hawki_cal_zpoint.c

00001 /* $Id: hawki_cal_zpoint.c,v 1.20 2010/03/08 18:01:24 cgarcia Exp $
00002  *
00003  * This file is part of the HAWKI Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: cgarcia $
00023  * $Date: 2010/03/08 18:01:24 $
00024  * $Revision: 1.20 $
00025  * $Name: hawki-1_7_2 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <string.h>
00037 #include <math.h>
00038 #include <cpl.h>
00039 
00040 #include "irplib_utils.h"
00041 #include "irplib_calib.h"
00042 #include "irplib_strehl.h"
00043 #include "irplib_stdstar.h"
00044 #include "irplib_cat.h"
00045 #include "irplib_wcs.h"
00046 
00047 #include "hawki_image_stats.h"
00048 #include "hawki_utils.h"
00049 #include "hawki_calib.h"
00050 #include "hawki_load.h"
00051 #include "hawki_save.h"
00052 #include "hawki_pfits.h"
00053 #include "hawki_dfs.h"
00054 #include "hawki_alloc.h"
00055 
00056 /*-----------------------------------------------------------------------------
00057                             Functions prototypes
00058  -----------------------------------------------------------------------------*/
00059 
00060 static int hawki_cal_zpoint_create(cpl_plugin *) ;
00061 static int hawki_cal_zpoint_exec(cpl_plugin *) ;
00062 static int hawki_cal_zpoint_destroy(cpl_plugin *) ;
00063 static int hawki_cal_zpoint(cpl_parameterlist *, cpl_frameset *) ;
00064 
00065 static void hawki_cal_zpoint_output_init(void);
00066 static int hawki_cal_zpoint_retrieve_input_param
00067 (cpl_parameterlist  *  parlist);
00068 static cpl_table ** hawki_cal_zpoint_reduce
00069 (cpl_frameset    *   set,
00070  const char      *   stdstars,
00071  const char      *   bpm,
00072  const char      *   flat,
00073  cpl_table       **  raw_zpoint_stats,
00074  int             *   labels,
00075  cpl_imagelist   **  images);
00076 static int hawki_cal_zpoint_save
00077 (cpl_table           **  zpoint_tables,
00078  int                 *   labels,
00079  cpl_imagelist       *   images,
00080  cpl_table           **  raw_zpoint_stats,
00081  cpl_frameset        *   zpoint_frames,
00082  cpl_frameset        *   calib_frames,
00083  const cpl_frame     *   stars_frame,
00084  cpl_parameterlist   *   parlist,
00085  cpl_frameset        *   set);
00086 static cpl_table ** hawki_cal_zpoint_photom
00087 (cpl_imagelist       *   ilist,
00088  cpl_bivector        *   pos,
00089  int                 *   labels);
00090 static int hawki_cal_zpoint_get_mag(const char *, double, double, hawki_band) ;
00091 static int hawki_cal_zpoint_compute_keywords
00092 (cpl_frameset * set, 
00093  int          * labels);
00094 static cpl_error_code  hawki_cal_zpoint_get_expected_pos
00095 (cpl_frameset * set,
00096  int          * labels);
00097 int hawki_cal_zpoint_check_epoch_equinox(cpl_propertylist * plist);
00098 
00099 /*-----------------------------------------------------------------------------
00100                             Static variables
00101  -----------------------------------------------------------------------------*/
00102 
00103 static struct {
00104     /* Inputs */
00105     double      xcoord[HAWKI_NB_DETECTORS] ;
00106     double      ycoord[HAWKI_NB_DETECTORS] ;
00107     double      target_ra;
00108     double      target_dec;
00109     double      magnitude ;
00110     double      detect_sigma ;
00111     int         sx ;
00112     int         sy ;
00113     double      phot_star_radius ;
00114     double      phot_bg_r1 ;
00115     double      phot_bg_r2 ;
00116 } hawki_cal_zpoint_config;
00117 
00118 static struct {
00119     /* Outputs */
00120     double      dit;
00121     double      pixscale;
00122     char        filter[512];
00123     hawki_band  band;
00124     char        starname[512];
00125     char        sptype[512];
00126     char        catalog[512];
00127     double      humidity;
00128     double      airmass[HAWKI_NB_DETECTORS];
00129     double      zpoint[HAWKI_NB_DETECTORS];
00130     double      atx0[HAWKI_NB_DETECTORS];
00131     double      posx[HAWKI_NB_DETECTORS];
00132     double      posy[HAWKI_NB_DETECTORS];
00133     double      flux[HAWKI_NB_DETECTORS];
00134     double      peak[HAWKI_NB_DETECTORS];
00135     double      bgd[HAWKI_NB_DETECTORS];
00136     double      fwhmx[HAWKI_NB_DETECTORS];
00137     double      fwhmy[HAWKI_NB_DETECTORS];
00138     double      fwhm[HAWKI_NB_DETECTORS];
00139     double      fwhmx_as[HAWKI_NB_DETECTORS];
00140     double      fwhmy_as[HAWKI_NB_DETECTORS];
00141     double      fwhm_as[HAWKI_NB_DETECTORS];
00142     double      mean_zpoint;
00143     double      mean_atx0;
00144     double      mean_airmass;
00145     double      stdstar_ra;
00146     double      stdstar_dec;
00147 } hawki_cal_zpoint_outputs;
00148 
00149 static char hawki_cal_zpoint_description[] =
00150 "hawki_cal_zpoint -- Zero point recipe\n"
00151 "The input of the recipe files listed in the Set Of Frames (sof-file)\n"
00152 "must be tagged as:\n"
00153 "raw-file.fits "HAWKI_CAL_ZPOINT_RAW" or\n"
00154 "stdstars-file.fits "HAWKI_CALPRO_STDSTARS" or\n"
00155 "flat-file.fits "HAWKI_CALPRO_FLAT" or\n"
00156 "bpm-file.fits "HAWKI_CALPRO_BPM"\n"
00157 "The recipe creates as an output:\n"
00158 "hawki_cal_zpoint.fits ("HAWKI_CALPRO_ZPOINT_TAB"): Zero point solution table\n"
00159 "hawki_cal_zpoint_check.fits ("HAWKI_CALPRO_ZPOINT_IMA"): Standard star images corrected (for checking purposes)\n"
00160 "hawki_cal_zpoint_stats.fits ("HAWKI_CALPRO_ZPOINT_STATS"): Statistics of the raw standard star images\n"
00161 "Return code:\n"
00162 "esorex exits with an error code of 0 if the recipe completes successfully\n"
00163 "or 1 otherwise";
00164 
00165 /*-----------------------------------------------------------------------------
00166                                 Functions code
00167  -----------------------------------------------------------------------------*/
00168 
00169 /*----------------------------------------------------------------------------*/
00177 /*----------------------------------------------------------------------------*/
00178 int cpl_plugin_get_info(cpl_pluginlist * list)
00179 {
00180     cpl_recipe  *   recipe = cpl_calloc(1, sizeof(*recipe)) ;
00181     cpl_plugin  *   plugin = &recipe->interface ;
00182 
00183     cpl_plugin_init(plugin,
00184                     CPL_PLUGIN_API,
00185                     HAWKI_BINARY_VERSION,
00186                     CPL_PLUGIN_TYPE_RECIPE,
00187                     "hawki_cal_zpoint",
00188                     "Zero point computation recipe",
00189                     hawki_cal_zpoint_description,
00190                     "Cesar Enrique Garcia Dabo",
00191                     "cgarcia@eso.org",
00192                     hawki_get_license(),
00193                     hawki_cal_zpoint_create,
00194                     hawki_cal_zpoint_exec,
00195                     hawki_cal_zpoint_destroy) ;
00196 
00197     cpl_pluginlist_append(list, plugin) ;
00198 
00199     return 0;
00200 }
00201 
00202 /*----------------------------------------------------------------------------*/
00211 /*----------------------------------------------------------------------------*/
00212 static int hawki_cal_zpoint_create(cpl_plugin * plugin)
00213 {
00214     cpl_recipe      * recipe ;
00215     cpl_parameter   * p ;
00216 
00217     /* Get the recipe out of the plugin */
00218     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00219         recipe = (cpl_recipe *)plugin ;
00220     else return -1 ;
00221 
00222     /* Create the parameters list in the cpl_recipe object */
00223     recipe->parameters = cpl_parameterlist_new() ;
00224 
00225     /* Fill the parameters list */
00226     /* --detect_sigma */
00227     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.detect_sigma",
00228             CPL_TYPE_DOUBLE, "the sigma value for object detection",
00229             "hawki.hawki_cal_zpoint", 7.0);
00230     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "detect_sigma") ;
00231     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00232     cpl_parameterlist_append(recipe->parameters, p) ;
00233     /* --star_r */
00234     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.star_r",CPL_TYPE_DOUBLE,
00235             "the star radius", "hawki.hawki_cal_zpoint", -1.0) ;
00236     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "star_r") ;
00237     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00238     cpl_parameterlist_append(recipe->parameters, p) ;
00239     /* --bg_r1 */
00240     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.bg_r1", CPL_TYPE_DOUBLE,
00241             "the internal background radius", "hawki.hawki_cal_zpoint", -1.0) ;
00242     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "bg_r1") ;
00243     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00244     cpl_parameterlist_append(recipe->parameters, p) ;
00245     /* --bg_r2 */
00246     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.bg_r2", CPL_TYPE_DOUBLE,
00247             "the external background radius", "hawki.hawki_cal_zpoint", -1.0) ;
00248     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "bg_r2") ;
00249     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00250     cpl_parameterlist_append(recipe->parameters, p) ;
00251     /* --ra */
00252     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.ra", CPL_TYPE_DOUBLE,
00253             "RA in degrees", "hawki.hawki_cal_zpoint", 999.0) ;
00254     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ra") ;
00255     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00256     cpl_parameterlist_append(recipe->parameters, p) ;
00257     /* --dec */
00258     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.dec", CPL_TYPE_DOUBLE,
00259             "DEC in degrees", "hawki.hawki_cal_zpoint", 999.0) ;
00260     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dec") ;
00261     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00262     cpl_parameterlist_append(recipe->parameters, p) ;
00263     /* --mag */
00264     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.mag", CPL_TYPE_DOUBLE,
00265             "magnitude", "hawki.hawki_cal_zpoint", 99.0) ;
00266     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "mag") ;
00267     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00268     cpl_parameterlist_append(recipe->parameters, p) ;
00269     /* --sx */
00270     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.sx", CPL_TYPE_INT,
00271             "x size of the search window", "hawki.hawki_cal_zpoint", 100) ;
00272     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "sx") ;
00273     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00274     cpl_parameterlist_append(recipe->parameters, p) ;
00275     /* --sy */
00276     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.sy", CPL_TYPE_INT,
00277             "y size of the search window", "hawki.hawki_cal_zpoint", 100) ;
00278     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "sy") ;
00279     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00280     cpl_parameterlist_append(recipe->parameters, p) ;
00281     /* --xcoord */
00282     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.xcoord", CPL_TYPE_STRING,
00283             "Coordinates in X where the standard star is located. If -1 use WCS",
00284             "hawki.hawki_cal_zpoint", "-1., -1., -1., -1.");
00285     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "xcoord") ;
00286     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00287     cpl_parameterlist_append(recipe->parameters, p) ;
00288     /* --ycoord */
00289     p = cpl_parameter_new_value("hawki.hawki_cal_zpoint.ycoord", CPL_TYPE_STRING,
00290             "Coordinates in Y where the standard star is located. If -1 use WCS",
00291             "hawki.hawki_cal_zpoint", "-1., -1., -1., -1.") ;
00292     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ycoord") ;
00293     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00294     cpl_parameterlist_append(recipe->parameters, p) ;
00295 
00296     /* Return */
00297     return 0;
00298 }
00299 
00300 /*----------------------------------------------------------------------------*/
00306 /*----------------------------------------------------------------------------*/
00307 static int hawki_cal_zpoint_exec(cpl_plugin * plugin)
00308 {
00309     cpl_recipe  *   recipe ;
00310 
00311     /* Get the recipe out of the plugin */
00312     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00313         recipe = (cpl_recipe *)plugin ;
00314     else return -1 ;
00315 
00316     /* Issue a banner */
00317     hawki_print_banner();
00318 
00319     return hawki_cal_zpoint(recipe->parameters, recipe->frames) ;
00320 }
00321 
00322 /*----------------------------------------------------------------------------*/
00328 /*----------------------------------------------------------------------------*/
00329 static int hawki_cal_zpoint_destroy(cpl_plugin * plugin)
00330 {
00331     cpl_recipe  *   recipe ;
00332 
00333     /* Get the recipe out of the plugin */
00334     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00335         recipe = (cpl_recipe *)plugin ;
00336     else return -1 ;
00337 
00338     cpl_parameterlist_delete(recipe->parameters) ;
00339     return 0 ;
00340 }
00341 
00342 /*----------------------------------------------------------------------------*/
00349 /*----------------------------------------------------------------------------*/
00350 static int hawki_cal_zpoint(
00351         cpl_parameterlist   *   parlist,
00352         cpl_frameset        *   framelist)
00353 {
00354     cpl_parameter   *   par ;
00355     const char      *   flat ;
00356     const char      *   bpm ;
00357     const char      *   stdstars ;
00358     cpl_frameset    *   zpoint_frames ;
00359     cpl_frameset    *   calib_frames ;
00360     const cpl_frame *   stars_frame;
00361     cpl_table       **  raw_zpoint_stats;
00362     cpl_table       **  zpoint_tables;
00363     cpl_imagelist   *   std_star_images ;
00364     int             *   labels;
00365     int                 idet;
00366 
00367     /* Initialise Output */
00368     hawki_cal_zpoint_output_init();
00369     zpoint_frames = NULL ;
00370     par = NULL ;
00371 
00372     /* Retrieve input parameters */
00373     if(hawki_cal_zpoint_retrieve_input_param(parlist))
00374     {
00375         cpl_msg_error(__func__, "Wrong parameters");
00376         return -1;
00377     }
00378 
00379     /* Identify the RAW and CALIB frames in the input frameset */
00380     if (hawki_dfs_set_groups(framelist)) {
00381         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00382         return -1 ;
00383     }
00384 
00385     /* Retrieve calibration data */
00386     calib_frames = cpl_frameset_new();
00387     flat = hawki_extract_first_filename(framelist, HAWKI_CALPRO_FLAT) ;
00388     if(flat)
00389         cpl_frameset_insert(calib_frames, cpl_frame_duplicate(
00390                 cpl_frameset_find_const(framelist, HAWKI_CALPRO_FLAT)));
00391     bpm = hawki_extract_first_filename(framelist, HAWKI_CALPRO_BPM) ;
00392     if(bpm)
00393         cpl_frameset_insert(calib_frames, cpl_frame_duplicate(
00394                 cpl_frameset_find_const(framelist, HAWKI_CALPRO_BPM)));
00395 
00396     /* STD stars catalog requested */
00397     stars_frame = cpl_frameset_find_const(framelist, HAWKI_CALPRO_STDSTARS);
00398     if (stars_frame  == NULL) 
00399     {
00400         cpl_msg_error(__func__,"Cannot find the catalog in the input list (%s)",
00401                       HAWKI_CALPRO_STDSTARS);
00402         cpl_frameset_delete(calib_frames);
00403         return -1 ;
00404     }
00405     stdstars = cpl_frame_get_filename(stars_frame);
00406 
00407     /* Retrieve raw frames */
00408     if ((zpoint_frames = hawki_extract_frameset(framelist,
00409                     HAWKI_CAL_ZPOINT_RAW)) != NULL) {
00410     } else {
00411         cpl_msg_error(__func__, "Cannot find raw frames in the input list (%s)",
00412                       HAWKI_CAL_ZPOINT_RAW);
00413         return -1 ;
00414     }
00415 
00416     /* Exactly 4 images are expected */
00417     if (cpl_frameset_get_size(zpoint_frames) != 4) {
00418         cpl_msg_error(__func__, "4 input raw frames are expected, not %d",
00419                 cpl_frameset_get_size(zpoint_frames)) ;
00420         cpl_frameset_delete(zpoint_frames) ;
00421         return -1 ;
00422     }
00423 
00424     /* Create the statistics table */
00425     raw_zpoint_stats = cpl_malloc(HAWKI_NB_DETECTORS * sizeof(cpl_table *));
00426     for(idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
00427     {
00428         raw_zpoint_stats[idet] = cpl_table_new(
00429             cpl_frameset_get_size(zpoint_frames));
00430     }
00431     hawki_image_stats_initialize(raw_zpoint_stats);
00432 
00433     /* Compute the zpoint values */
00434     cpl_msg_info(__func__, "Reduce the data") ;
00435     cpl_msg_indent_more() ;
00436     labels = cpl_calloc(cpl_frameset_get_size(zpoint_frames), sizeof(int)) ;
00437     if ((zpoint_tables = hawki_cal_zpoint_reduce(zpoint_frames, stdstars, 
00438              bpm, flat, raw_zpoint_stats, labels, &std_star_images))==NULL)
00439     {
00440         cpl_msg_error(__func__, "Cannot reduce the data") ;
00441         cpl_frameset_delete(zpoint_frames) ;
00442         hawki_table_delete(raw_zpoint_stats);
00443         cpl_free(labels);
00444         cpl_msg_indent_less() ;
00445         return -1 ;
00446     }
00447     cpl_msg_indent_less() ;
00448 
00449     /* Save the products */
00450     cpl_msg_info(__func__, "Save the products") ;
00451     cpl_msg_indent_more() ;
00452     if (hawki_cal_zpoint_save
00453             (zpoint_tables, labels, std_star_images, raw_zpoint_stats, 
00454              zpoint_frames, calib_frames, stars_frame,
00455              parlist, framelist) == -1)
00456     {
00457         cpl_msg_warning(__func__, "Data could not be saved. "
00458                         "Check permisions or disk space") ;
00459         hawki_table_delete(zpoint_tables) ;
00460         cpl_imagelist_delete(std_star_images) ;
00461         hawki_table_delete(raw_zpoint_stats);
00462         cpl_free(labels);
00463         cpl_msg_indent_less() ;
00464         return -1 ;
00465     }
00466     cpl_msg_indent_less() ;
00467 
00468     /* Free and return */
00469     cpl_frameset_delete(zpoint_frames);
00470     cpl_frameset_delete(calib_frames);
00471     cpl_imagelist_delete(std_star_images);
00472     hawki_table_delete(zpoint_tables);
00473     hawki_table_delete(raw_zpoint_stats);
00474     cpl_free(labels);
00475 
00476     /* Return */
00477     if (cpl_error_get_code()) return -1 ;
00478     else return 0 ;
00479 }
00480 
00481 /*----------------------------------------------------------------------------*/
00491 /*----------------------------------------------------------------------------*/
00492 static cpl_table ** hawki_cal_zpoint_reduce
00493 (cpl_frameset    *   set,
00494  const char      *   stdstars,
00495  const char      *   bpm,
00496  const char      *   flat,
00497  cpl_table       **  raw_zpoint_stats,
00498  int             *   labels,
00499  cpl_imagelist   **  star_images)
00500 {
00501     cpl_frame           *   cur_frame ;
00502     cpl_propertylist    *   plist ;
00503     const char          *   sval ;
00504     cpl_imagelist       *   star_images_frame_order ;
00505     int                     nima ;
00506     cpl_bivector        *   positions ;
00507     cpl_image           *   filt_ima ;
00508     cpl_matrix          *   kernel ;
00509     int                     size_x, size_y ;
00510     double                  pos_x, pos_y, pos_x_cen, pos_y_cen, dist, min_dist ;
00511     double                  equinox, epoch;
00512     cpl_apertures       *   aperts ;
00513     cpl_table           **  zpoint_tables;
00514     cpl_image           *   tmp_ima ;
00515     int                     iaper;
00516     int                     idet;
00517     int                     iframe;
00518     int                     iframe_star = -1;
00519     int                     nframes;
00520     cpl_errorstate          error_prevstate;
00521 
00522     /* Check inputs */
00523     if (set == NULL) return NULL ;
00524     if (stdstars == NULL) return NULL ;
00525     if (star_images == NULL) return NULL ;
00526 
00527     /* Initialize */
00528     *star_images = cpl_imagelist_new();
00529 
00530     /* Get the filter name, DIT, RA and DEC  */
00531     error_prevstate = cpl_errorstate_get();
00532     cur_frame = cpl_frameset_get_frame(set, 0) ;
00533     plist=cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0) ;
00534     if ((sval = hawki_pfits_get_filter(plist)) == NULL) return NULL ;
00535     else sprintf(hawki_cal_zpoint_outputs.filter, sval) ;
00536     if (hawki_cal_zpoint_config.target_ra > 998.0)
00537     {
00538         hawki_cal_zpoint_config.target_ra = hawki_pfits_get_targ_alpha(plist);
00539         //hawki_cal_zpoint_config.target_ra = hawki_pfits_get_ra(plist) -
00540         //hawki_pfits_get_cumoffseta(plist) / 3600.;// Not valid before Nov 2008
00541         if(hawki_cal_zpoint_check_epoch_equinox(plist) == -1)
00542         {
00543             cpl_propertylist_delete(plist);
00544             return NULL;
00545         }
00546     }
00547     if (hawki_cal_zpoint_config.target_dec > 998.0)
00548     {
00549         hawki_cal_zpoint_config.target_dec = hawki_pfits_get_targ_delta(plist);
00550         //hawki_cal_zpoint_config.target_dec = hawki_pfits_get_dec(plist) -
00551         //hawki_pfits_get_cumoffsetd(plist) / 3600.;// Not valid before Nov 2008
00552         if(hawki_cal_zpoint_check_epoch_equinox(plist) == -1)
00553         {
00554             cpl_propertylist_delete(plist);
00555             return NULL;
00556         }
00557     }
00558     hawki_cal_zpoint_outputs.dit = hawki_pfits_get_dit(plist) ;
00559     hawki_cal_zpoint_outputs.pixscale = hawki_pfits_get_pixscale(plist) ;
00560     cpl_propertylist_delete(plist) ;
00561     if(!cpl_errorstate_is_equal(error_prevstate))
00562     {
00563         cpl_msg_error(__func__, "Cannot get some header informations") ;
00564         cpl_imagelist_delete(*star_images);
00565         return NULL ;
00566     }
00567     cpl_msg_info(__func__,"Searching catalog stars closest to target:");
00568     cpl_msg_indent_more();
00569     cpl_msg_info(__func__,"RA = %g ; DEC = %g",
00570                  hawki_cal_zpoint_config.target_ra,
00571                  hawki_cal_zpoint_config.target_dec);
00572     cpl_msg_info(__func__,"HAWK-I Filter: %s", hawki_cal_zpoint_outputs.filter);
00573     cpl_msg_indent_less();
00574 
00575     /* Get the band */
00576     if ((hawki_cal_zpoint_outputs.band =
00577                 hawki_get_band(hawki_cal_zpoint_outputs.filter)) ==
00578             HAWKI_BAND_UNKNOWN) {
00579         cpl_msg_error(__func__, "Cannot associate the filter %s to a band",
00580                 hawki_cal_zpoint_outputs.filter) ;
00581         cpl_imagelist_delete(*star_images);
00582         return NULL ;
00583     }
00584 
00585     /* Get the standard star information from database */
00586     if (hawki_cal_zpoint_config.magnitude > 98.0) {
00587         if (hawki_cal_zpoint_get_mag(stdstars, hawki_cal_zpoint_config.target_ra,
00588                                     hawki_cal_zpoint_config.target_dec,
00589                                     hawki_cal_zpoint_outputs.band) == -1)
00590         {
00591             cpl_msg_error(__func__,"Cannot get a suitable star from catalog");
00592             cpl_imagelist_delete(*star_images);
00593             return NULL ;
00594         }
00595     }
00596     cpl_msg_info(__func__, "Star magnitude in filter %s : %g",
00597             hawki_cal_zpoint_outputs.filter,
00598             hawki_cal_zpoint_config.magnitude) ;
00599     cpl_msg_info(__func__, "Star coordinates: RA = %g ; DEC = %g",
00600             hawki_cal_zpoint_outputs.stdstar_ra,
00601             hawki_cal_zpoint_outputs.stdstar_dec);
00602 
00603     /* Labelise frames */
00604     cpl_msg_info(__func__, "Guessing which frame the STD is in for each chip");
00605     hawki_detectors_locate_star
00606         (set, hawki_cal_zpoint_outputs.stdstar_ra,
00607          hawki_cal_zpoint_outputs.stdstar_dec, labels);
00608     if (labels == NULL)
00609     {
00610         cpl_msg_error(__func__, "Cannot determine which frame the STD is on") ;
00611         cpl_imagelist_delete(*star_images);
00612         return NULL ;
00613     }
00614 
00615     /* Compute the expected position of the star in pixels */
00616     /* This is stored in hawki_cal_zpoint_config.xcoord, ycoord */
00617     if(hawki_cal_zpoint_get_expected_pos(set, labels) != CPL_ERROR_NONE)
00618     {
00619         cpl_msg_error(__func__,"Could not determine where the star is located");
00620         cpl_imagelist_delete(*star_images);
00621         return NULL;
00622     }
00623     
00624     /* Fetch the airmass and humidity */
00625     hawki_cal_zpoint_compute_keywords(set, labels);
00626 
00627     /* Create the positions vector */
00628     nima = cpl_frameset_get_size(set) ;
00629     positions = cpl_bivector_new(nima) ;
00630 
00631     /* Loop on the detectors */
00632     nframes = cpl_frameset_get_size(set) ;
00633     cpl_msg_info(__func__,"Loop on the chips");
00634     cpl_msg_indent_more() ;
00635     for(idet = 0; idet < HAWKI_NB_DETECTORS; ++idet)
00636     {
00637         cpl_imagelist * sky_images;
00638         cpl_image     * star_ima = NULL;
00639         cpl_image     * sky;
00640         cpl_image     * flat_im;
00641         int             ext_nb;
00642 
00643         cpl_msg_info(__func__, "Loading the chip %d", idet+1);
00644         cpl_msg_indent_more() ;
00645 
00646         /* Allocate */
00647         sky_images = cpl_imagelist_new();
00648 
00649         cpl_msg_indent_more() ;
00650         for (iframe=0 ; iframe<nframes ; iframe++)
00651         {
00652             cpl_image * ima_cur;
00653 
00654             /* Load the image */
00655             ima_cur = hawki_load_image(set, iframe, idet+1, CPL_TYPE_FLOAT) ;
00656             if(ima_cur == NULL)
00657             {
00658                 cpl_bivector_delete(positions) ;
00659                 cpl_imagelist_delete(*star_images);
00660                 cpl_imagelist_delete(sky_images) ;
00661                 cpl_msg_error(__func__, "Error reading image");
00662                 return NULL;
00663             }
00664             /* Get image statistics */
00665             size_x = cpl_image_get_size_x(ima_cur) ;
00666             size_y = cpl_image_get_size_y(ima_cur) ;
00667             if(hawki_image_stats_fill_from_image
00668                 (raw_zpoint_stats,
00669                  ima_cur,
00670                  1,
00671                  1,
00672                  size_x,
00673                  size_y,
00674                  idet,
00675                  iframe) !=0 )
00676             {
00677                 cpl_msg_error(__func__,"Cannot compute stats on ima %d det %d",
00678                               iframe+1, idet+1);
00679                 cpl_bivector_delete(positions) ;
00680                 cpl_imagelist_delete(*star_images);
00681                 cpl_imagelist_delete(sky_images) ;
00682                 cpl_image_delete(ima_cur);
00683                 cpl_msg_indent_less() ;
00684                 return NULL ;
00685             }
00686 
00687             /* Add the image to either the sky images or the star image */
00688             if(labels[iframe] == idet + 1)
00689             {
00690                 star_ima = ima_cur;
00691                 iframe_star = iframe;
00692             }
00693             else
00694                 cpl_imagelist_set(sky_images, ima_cur,
00695                                   cpl_imagelist_get_size(sky_images));
00696         }
00697         cpl_msg_indent_less();
00698 
00699         /* Create the sky */
00700         cpl_msg_info(__func__, "Correct for the sky");
00701         sky = cpl_imagelist_collapse_median_create(sky_images);
00702         cpl_imagelist_delete(sky_images) ;
00703 
00704         /* Subtract the sky */
00705         cpl_image_subtract(star_ima, sky) ;
00706         cpl_image_delete(sky) ;
00707 
00708         /* Divide by the flatfield if one is provided */
00709         if (flat) {
00710             cpl_msg_info(__func__, "Correct for the flat") ;
00711 
00712             /* Get the extension with the current chip */
00713             if ((ext_nb = hawki_get_ext_from_detector(flat, idet + 1)) == -1)
00714             {
00715                 cpl_msg_error(__func__, "Cannot get the extension with chip %d",
00716                               idet + 1);
00717                 cpl_imagelist_delete(*star_images) ;
00718                 cpl_bivector_delete(positions) ;
00719                 return NULL ;
00720             }
00721             /* Load */
00722             flat_im = cpl_image_load(flat, CPL_TYPE_FLOAT, 0, ext_nb) ;
00723             cpl_image_divide(star_ima, flat_im) ;
00724             cpl_image_delete(flat_im) ;
00725         }
00726 
00727         /* Correct the bad pixels */
00728         if (bpm) {
00729             cpl_msg_info(__func__, "Correct for the bad pixels") ;
00730             if (hawki_bpm_calib(star_ima, bpm, idet + 1) == -1)
00731             {
00732                 cpl_msg_error(__func__, "Cannot correct the BPM for chip %d",
00733                               idet + 1);
00734                 cpl_imagelist_delete(*star_images) ;
00735                 cpl_bivector_delete(positions) ;
00736                 return NULL ;
00737             }
00738         }
00739 
00740         /* Put the result in the image list */
00741         cpl_imagelist_set(*star_images, star_ima,
00742                           cpl_imagelist_get_size(*star_images)) ;
00743 
00744         /* Object detection */
00745         cpl_msg_info(__func__,"For chip %d the STD is detected on frame %d",
00746                      idet + 1, iframe_star+1);
00747         pos_x_cen = pos_y_cen = -1.0 ;
00748         size_x = cpl_image_get_size_x(star_ima) ;
00749         size_y = cpl_image_get_size_y(star_ima) ;
00750 
00751         /* Filtering the image*/
00752         kernel = cpl_matrix_new(3, 3) ;
00753         cpl_matrix_fill(kernel, 1.0) ;
00754         filt_ima = cpl_image_filter_median(star_ima, kernel) ;
00755         cpl_matrix_delete(kernel) ;
00756 
00757         /* Looking for apertures */
00758         aperts = cpl_apertures_extract_sigma(filt_ima,
00759                 hawki_cal_zpoint_config.detect_sigma) ;
00760         cpl_image_delete(filt_ima) ;
00761         if (aperts == NULL)
00762         {
00763             cpl_msg_error(__func__, "Cannot find the central object") ;
00764             cpl_imagelist_delete(*star_images) ;
00765             cpl_bivector_delete(positions) ;
00766             return NULL ;
00767         }
00768         min_dist = size_x * size_x + size_y * size_y ;
00769         for (iaper=0 ; iaper<cpl_apertures_get_size(aperts) ; iaper++) {
00770             pos_x = cpl_apertures_get_centroid_x(aperts, iaper+1) ;
00771             pos_y = cpl_apertures_get_centroid_y(aperts, iaper+1) ;
00772             dist = (pos_x-hawki_cal_zpoint_config.xcoord[idet])*
00773                     (pos_x-hawki_cal_zpoint_config.xcoord[idet]) +
00774                    (pos_y-hawki_cal_zpoint_config.ycoord[idet])*
00775                     (pos_y-hawki_cal_zpoint_config.ycoord[idet]);
00776             if (dist<min_dist) {
00777                 min_dist = dist ;
00778                 pos_x_cen = pos_x ;
00779                 pos_y_cen = pos_y ;
00780             }
00781         }
00782         cpl_apertures_delete(aperts) ;
00783 
00784         cpl_vector_set(cpl_bivector_get_x(positions), iframe_star, pos_x_cen) ;
00785         cpl_vector_set(cpl_bivector_get_y(positions), iframe_star, pos_y_cen) ;
00786         cpl_msg_info(__func__, "Expected star position: %g %g",
00787                 hawki_cal_zpoint_config.xcoord[idet],
00788                 hawki_cal_zpoint_config.ycoord[idet]);
00789         cpl_msg_info(__func__, "Bright object position: %g %g",
00790                 pos_x_cen, pos_y_cen) ;
00791 
00792         /* Check that the star is within the search window */
00793         if(fabs(pos_x_cen - hawki_cal_zpoint_config.xcoord[idet]) >
00794                 hawki_cal_zpoint_config.sx                        ||
00795            fabs(pos_y_cen - hawki_cal_zpoint_config.ycoord[idet]) >
00796                 hawki_cal_zpoint_config.sy)
00797         {
00798             cpl_msg_error(__func__,"No star found within search window "
00799                           "[%d, %d] of expected position",
00800                           hawki_cal_zpoint_config.sx,
00801                           hawki_cal_zpoint_config.sy);
00802 
00803             cpl_imagelist_delete(*star_images) ;
00804             cpl_bivector_delete(positions) ;
00805             return NULL ;
00806         }
00807 
00808         /* Free */
00809         cpl_msg_indent_less() ;
00810     }
00811     cpl_msg_indent_less() ;
00812 
00813     /* Reorder the images (frame order) */
00814     star_images_frame_order = cpl_imagelist_new() ;
00815     for (iframe=0 ; iframe< nframes; iframe++)
00816     {
00817         tmp_ima = cpl_image_duplicate
00818             (cpl_imagelist_get(*star_images, labels[iframe] -1 ));
00819         cpl_imagelist_set(star_images_frame_order, tmp_ima, iframe);
00820     }
00821 
00822     /* Compute the photometry */
00823     cpl_msg_info(__func__, "Compute the photometry") ;
00824     cpl_msg_indent_more() ;
00825     if ((zpoint_tables = hawki_cal_zpoint_photom
00826             (star_images_frame_order, positions, labels))==NULL) {
00827         cpl_msg_error(__func__, "Cannot reduce") ;
00828         cpl_bivector_delete(positions) ;
00829         cpl_imagelist_delete(star_images_frame_order) ;
00830         cpl_msg_indent_less() ;
00831         return NULL ;
00832     }
00833 
00834 
00835     /* Free and exit */
00836     cpl_msg_indent_less() ;
00837     cpl_bivector_delete(positions) ;
00838     cpl_imagelist_delete(star_images_frame_order) ;
00839 
00840     return zpoint_tables;
00841 }
00842 
00843 /*----------------------------------------------------------------------------*/
00853 /*----------------------------------------------------------------------------*/
00854 static cpl_table ** hawki_cal_zpoint_photom(
00855         cpl_imagelist       *   ilist,
00856         cpl_bivector        *   pos,
00857         int                 *   labels)
00858 {
00859     cpl_table **        zpoint;
00860     int                 nframes;
00861     double              r, r1, r2, mag, dit, extinction, pixscale ;
00862     cpl_image       *   ima ;
00863     double          *   pos_x ;
00864     double          *   pos_y ;
00865     double              bgd, fl, zp, peak, fwhm_x, fwhm_y ;
00866     cpl_bivector    *   iqe_res ;
00867     int                 iframe;
00868     int                 idet;
00869 
00870     /* Test entries */
00871     if (ilist == NULL) return NULL ;
00872     if (pos == NULL) return NULL ;
00873 
00874     /* Initialise */
00875     nframes = cpl_imagelist_get_size(ilist) ;
00876     mag = hawki_cal_zpoint_config.magnitude ;
00877     dit = hawki_cal_zpoint_outputs.dit ;
00878     pixscale = hawki_cal_zpoint_outputs.pixscale ;
00879 
00880     /* Get extinction */
00881     switch (hawki_cal_zpoint_outputs.band) {
00882         case HAWKI_BAND_J:      extinction = 0.098 ; break ;
00883         case HAWKI_BAND_H:      extinction = 0.039 ; break ;
00884         case HAWKI_BAND_K:      extinction = 0.065 ; break ;
00885         case HAWKI_BAND_Y:      extinction = 0.00 ; break ;
00886         default:                extinction = 0.00 ; break ;
00887     }
00888     cpl_msg_info(__func__,"Using tabulated extinction for band %s: %f",
00889                  hawki_cal_zpoint_outputs.filter, extinction);
00890 
00891     /* Loop on the images */
00892     for (iframe=0 ; iframe<nframes ; iframe++) {
00893         /* Get the current image */
00894         ima = cpl_imagelist_get(ilist, iframe) ;
00895 
00896         /* Get the current position */
00897         pos_x = cpl_bivector_get_x_data(pos) ;
00898         pos_y = cpl_bivector_get_y_data(pos) ;
00899 
00900         /* FWHM_X / FWHM_Y */
00901         iqe_res = cpl_image_iqe
00902             (ima, (int)(pos_x[iframe]-10.0), (int)(pos_y[iframe]-10.0),
00903              (int)(pos_x[iframe]+10.0), (int)(pos_y[iframe]+10.0));
00904         if (iqe_res == NULL)
00905         {
00906             cpl_msg_debug(__func__,"Cannot compute FWHM for chip %d",
00907                           labels[iframe]);
00908             fwhm_x = fwhm_y = -1.0 ;
00909             cpl_error_reset() ;
00910         } else {
00911             fwhm_x = cpl_vector_get(cpl_bivector_get_x(iqe_res), 2) ;
00912             fwhm_y = cpl_vector_get(cpl_bivector_get_x(iqe_res), 3) ;
00913             cpl_bivector_delete(iqe_res) ;
00914         }
00915 
00916         /* Determine the radii */
00917         r = hawki_cal_zpoint_config.phot_star_radius ;
00918         if (r < 0) {
00919             if (fwhm_x>0 && fwhm_y>0)   r = 5*(fwhm_x+fwhm_y)/2.0 ;
00920             else                        r = HAWKI_PHOT_STAR_RADIUS ;
00921         }
00922         r1 = hawki_cal_zpoint_config.phot_bg_r1 ;
00923         r2 = hawki_cal_zpoint_config.phot_bg_r2 ;
00924         if (r1 < 0) r1 = r + 10.0 ;
00925         if (r2 < 0) r2 = r1 + 20.0 ;
00926         //cpl_msg_info(__func__, "Use radii for star: %g and background: %g, %g",
00927         //        r, r1, r2) ;
00928 
00929         /* Compute the photometry */
00930         /* Background */
00931         bgd = irplib_strehl_ring_background(ima, (int)(pos_x[iframe]),
00932                 (int)(pos_y[iframe]), (int)r1, (int)r2, IRPLIB_BG_METHOD_MEDIAN) ;
00933         /* Flux */
00934         fl = irplib_strehl_disk_flux(ima,
00935                 (int)(pos_x[iframe]), (int)(pos_y[iframe]), (int)r, bgd) ;
00936         /* Zero Point */
00937         if ((fl < 0) || (dit < 0))     zp = -1.0 ;
00938         else                    zp = mag + 2.5 * log10(fl) - 2.5 * log10(dit) ;
00939         //cpl_msg_info(__func__, "Zero point in chip %d:   %g", labels[iframe], zp) ;
00940         /* Peak */
00941         peak = cpl_image_get_max_window(ima,
00942                 (int)(pos_x[iframe]-5), (int)(pos_y[iframe]-5),
00943                 (int)(pos_x[iframe]+5), (int)(pos_y[iframe]+5)) ;
00944 
00945         hawki_cal_zpoint_outputs.zpoint[labels[iframe]-1] = zp ;
00946         hawki_cal_zpoint_outputs.atx0[labels[iframe]-1] = zp + 
00947             extinction * hawki_cal_zpoint_outputs.airmass[labels[iframe]-1];
00948         hawki_cal_zpoint_outputs.posx[labels[iframe]-1] = pos_x[iframe] ;
00949         hawki_cal_zpoint_outputs.posy[labels[iframe]-1] = pos_y[iframe] ;
00950         hawki_cal_zpoint_outputs.flux[labels[iframe]-1] = fl ;
00951         hawki_cal_zpoint_outputs.peak[labels[iframe]-1] = peak ;
00952         hawki_cal_zpoint_outputs.bgd[labels[iframe]-1] = bgd ;
00953         hawki_cal_zpoint_outputs.fwhmx[labels[iframe]-1] = fwhm_x ;
00954         hawki_cal_zpoint_outputs.fwhmy[labels[iframe]-1] = fwhm_y ;
00955         if (fwhm_x > 0 && fwhm_y > 0)
00956             hawki_cal_zpoint_outputs.fwhm[labels[iframe]-1] = sqrt(fwhm_x*fwhm_y) ;
00957         else
00958             hawki_cal_zpoint_outputs.fwhm[labels[iframe]-1] = -1.0 ;
00959         hawki_cal_zpoint_outputs.fwhmx_as[labels[iframe]-1] = fwhm_x * pixscale ;
00960         hawki_cal_zpoint_outputs.fwhmy_as[labels[iframe]-1] = fwhm_y * pixscale ;
00961         if (fwhm_x > 0 && fwhm_y > 0)
00962             hawki_cal_zpoint_outputs.fwhm_as[labels[iframe]-1] =
00963                 sqrt(fwhm_x*fwhm_y*pixscale*pixscale) ;
00964         else
00965             hawki_cal_zpoint_outputs.fwhm_as[labels[iframe]-1] = -1.0 ;
00966 
00967     }
00968 
00969     /* Create the table */
00970     zpoint = hawki_table_new(1);
00971     //tab = cpl_table_new(nframes) ;
00972     for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++) {
00973         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_CHIP, CPL_TYPE_INT) ;
00974         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_STARNAME, CPL_TYPE_STRING) ;
00975         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_POSX, CPL_TYPE_DOUBLE) ;
00976         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_POSY, CPL_TYPE_DOUBLE) ;
00977         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_ZPOINT, CPL_TYPE_DOUBLE) ;
00978         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_ATX0, CPL_TYPE_DOUBLE) ;
00979         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_AIRMASS, CPL_TYPE_DOUBLE) ;
00980         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_FLUX, CPL_TYPE_DOUBLE) ;
00981         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_FILTER, CPL_TYPE_STRING) ;
00982         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_PEAK, CPL_TYPE_DOUBLE) ;
00983         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_BGD, CPL_TYPE_DOUBLE) ;
00984         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_FWHMX, CPL_TYPE_DOUBLE) ;
00985         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_FWHMY, CPL_TYPE_DOUBLE) ;
00986         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_FWHM, CPL_TYPE_DOUBLE) ;
00987         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_FWHMX_AS, CPL_TYPE_DOUBLE) ;
00988         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_FWHMY_AS, CPL_TYPE_DOUBLE) ;
00989         cpl_table_new_column(zpoint[idet], HAWKI_COL_ZPOINT_FWHM_AS, CPL_TYPE_DOUBLE) ;
00990         
00991         cpl_table_set_int(zpoint[idet], HAWKI_COL_ZPOINT_CHIP, 0, idet+1) ;
00992         cpl_table_set_string(zpoint[idet], HAWKI_COL_ZPOINT_STARNAME, 0,
00993                 hawki_cal_zpoint_outputs.starname) ;
00994         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_POSX, 0,
00995                 hawki_cal_zpoint_outputs.posx[idet]) ;
00996         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_POSY, 0,
00997                 hawki_cal_zpoint_outputs.posy[idet]) ;
00998         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_ZPOINT, 0,
00999                 hawki_cal_zpoint_outputs.zpoint[idet]) ;
01000         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_ATX0, 0,
01001                 hawki_cal_zpoint_outputs.atx0[idet]) ;
01002         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_AIRMASS, 0,
01003                 hawki_cal_zpoint_outputs.airmass[idet]) ;
01004         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_FLUX, 0,
01005                 hawki_cal_zpoint_outputs.flux[idet]) ;
01006         cpl_table_set_string(zpoint[idet], HAWKI_COL_ZPOINT_FILTER, 0,
01007                 hawki_cal_zpoint_outputs.filter);
01008         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_PEAK, 0,
01009                 hawki_cal_zpoint_outputs.peak[idet]) ;
01010         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_BGD, 0,
01011                 hawki_cal_zpoint_outputs.bgd[idet]) ;
01012         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_FWHMX, 0,
01013                 hawki_cal_zpoint_outputs.fwhmx[idet]) ;
01014         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_FWHMY, 0,
01015                 hawki_cal_zpoint_outputs.fwhmy[idet]) ;
01016         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_FWHM, 0,
01017                 hawki_cal_zpoint_outputs.fwhm[idet]) ;
01018         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_FWHMX_AS, 0,
01019                 hawki_cal_zpoint_outputs.fwhmx_as[idet]) ;
01020         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_FWHMY_AS, 0,
01021                 hawki_cal_zpoint_outputs.fwhmy_as[idet]) ;
01022         cpl_table_set_double(zpoint[idet], HAWKI_COL_ZPOINT_FWHM_AS, 0,
01023                 hawki_cal_zpoint_outputs.fwhm_as[idet]) ;
01024     }
01025 
01026     /* Mean values */
01027     hawki_cal_zpoint_outputs.mean_zpoint = 0.0 ;
01028     hawki_cal_zpoint_outputs.mean_atx0 = 0.0 ;
01029     for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++) {
01030         hawki_cal_zpoint_outputs.mean_zpoint +=
01031             hawki_cal_zpoint_outputs.zpoint[idet] ;
01032         hawki_cal_zpoint_outputs.mean_atx0  +=
01033             hawki_cal_zpoint_outputs.atx0[idet] ;
01034     }
01035     hawki_cal_zpoint_outputs.mean_zpoint /= HAWKI_NB_DETECTORS ;
01036     hawki_cal_zpoint_outputs.mean_atx0 /= HAWKI_NB_DETECTORS ;
01037 
01038     /* Output results */
01039     for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
01040     {
01041         cpl_msg_info(__func__, "Zero point [at airmass=1] in chip %d:", idet + 1);
01042         cpl_msg_indent_more();
01043         cpl_msg_info(__func__,"   ZP: %g [%g]",
01044                      hawki_cal_zpoint_outputs.zpoint[idet],
01045                      hawki_cal_zpoint_outputs.atx0[idet]);
01046         cpl_msg_info(__func__,"   Flux of star: %f",
01047                      hawki_cal_zpoint_outputs.flux[idet]);
01048         cpl_msg_indent_less();
01049     }
01050 
01051     return zpoint;
01052 }
01053 
01054 /*----------------------------------------------------------------------------*/
01062 /*----------------------------------------------------------------------------*/
01063 static int hawki_cal_zpoint_get_mag(
01064         const char  *       stdstars,
01065         double              pointing_ra,
01066         double              pointing_dec,
01067         hawki_band          band)
01068 {
01069     double           star_mag ;
01070     char             star_name[512] ;
01071     char             cat_name[512] ;
01072     char             star_type[32] ;
01073     double           stdstar_ra;
01074     double           stdstar_dec;
01075     int              ret ;
01076     cpl_errorstate   error_prevstate = cpl_errorstate_get();
01077 
01078     /* Initialise */
01079     ret = -1 ;
01080 
01081     switch (band) {
01082         /* SW mode */
01083         case HAWKI_BAND_J:
01084         case HAWKI_BAND_H:
01085         case HAWKI_BAND_K:
01086         case HAWKI_BAND_Y:
01087             strcpy(cat_name, "all") ;
01088             irplib_stdstar_find_star
01089                 (stdstars, pointing_ra, pointing_dec,
01090                  hawki_std_band_name(band), "all", &star_mag,
01091                  star_name, star_type, &stdstar_ra, &stdstar_dec, 5.0);
01092             break ;
01093         default:
01094             cpl_msg_error(__func__, "cannot determine associated filter") ;
01095             return -1 ;
01096     }
01097 
01098     /* If the magnitude still is not know, abort */
01099     if(!cpl_errorstate_is_equal(error_prevstate))
01100     {
01101         cpl_msg_error(__func__, "%s", cpl_error_get_message());
01102         return -1 ;
01103     }
01104     cpl_msg_info(__func__, "Found catalog star %s", star_name) ;
01105 
01106     /* Store results */
01107     hawki_cal_zpoint_config.magnitude = star_mag ;
01108     strcpy(hawki_cal_zpoint_outputs.starname, star_name) ;
01109     strcpy(hawki_cal_zpoint_outputs.sptype, star_type) ;
01110     strcpy(hawki_cal_zpoint_outputs.catalog, cat_name) ;
01111     hawki_cal_zpoint_outputs.stdstar_ra = stdstar_ra;
01112     hawki_cal_zpoint_outputs.stdstar_dec = stdstar_dec;
01113 
01114     return 0 ;
01115 }
01116 
01117 /*----------------------------------------------------------------------------*/
01126 /*----------------------------------------------------------------------------*/
01127 static int hawki_cal_zpoint_save
01128 (cpl_table           **  zpoint_tables,
01129  int                 *   labels,
01130  cpl_imagelist       *   images,
01131  cpl_table           **  raw_zpoint_stats,
01132  cpl_frameset        *   zpoint_frames,
01133  cpl_frameset        *   calib_frames,
01134  const cpl_frame     *   stars_frame,
01135  cpl_parameterlist   *   parlist,
01136  cpl_frameset        *   set)
01137 {
01138     cpl_propertylist    **  qclists ;
01139     cpl_propertylist    *   wcslist;
01140     cpl_frameset        *   used_frames;
01141     const char          *   ref_filename;
01142     cpl_propertylist    *   inputlist ;
01143     int                     ext_nb, nframes ;
01144     const char          *   recipe_name = "hawki_cal_zpoint" ;
01145     int                     idet;
01146     int                     iframe;
01147     cpl_errorstate          error_prevstate = cpl_errorstate_get();
01148 
01149 
01150     /* Initialise */
01151     nframes = cpl_frameset_get_size(set) ;
01152 
01153     /* Get the reference frame */
01154     ref_filename = hawki_get_extref_file(set);
01155 
01156     /* Create the QC lists for the extensions */
01157     qclists = cpl_malloc(HAWKI_NB_DETECTORS * sizeof(cpl_propertylist*)) ;
01158     for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
01159     {
01160         int            this_iframe = -1;
01161 
01162         qclists[idet] = cpl_propertylist_new() ;
01163         /* These QC are common to all extensions */
01164         cpl_propertylist_append_string(qclists[idet], "ESO QC FILTER OBS",
01165                 hawki_cal_zpoint_outputs.filter) ;
01166         cpl_propertylist_append_string(qclists[idet], "ESO QC FILTER REF",
01167                 hawki_std_band_name(hawki_cal_zpoint_outputs.band)) ;
01168         cpl_propertylist_append_double(qclists[idet], "ESO QC AMBI RHUM AVG",
01169                 hawki_cal_zpoint_outputs.humidity);
01170         cpl_propertylist_append_double(qclists[idet], "ESO QC AIRMASS MEAN",
01171                 hawki_cal_zpoint_outputs.mean_airmass) ;
01172         cpl_propertylist_append_string(qclists[idet], "ESO QC STDNAME",
01173                 hawki_cal_zpoint_outputs.starname) ;
01174         cpl_propertylist_append_string(qclists[idet], "ESO QC SPECTYPE",
01175                 hawki_cal_zpoint_outputs.sptype) ;
01176         cpl_propertylist_append_double(qclists[idet], "ESO QC STARMAG",
01177                 hawki_cal_zpoint_config.magnitude) ;
01178         cpl_propertylist_append_string(qclists[idet], "ESO QC CATNAME",
01179                 hawki_cal_zpoint_outputs.catalog) ;
01180         cpl_propertylist_append_double(qclists[idet], "ESO QC DATANCOM",
01181                 nframes) ;
01182         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT MEAN",
01183                                        hawki_cal_zpoint_outputs.mean_zpoint) ;
01184         cpl_propertylist_append_double(qclists[idet], "ESO QC ATX0 MEAN",
01185                                        hawki_cal_zpoint_outputs.mean_atx0) ;
01186         /* These QC are specific of the extension */
01187         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT",
01188                 hawki_cal_zpoint_outputs.zpoint[idet]) ;
01189         cpl_propertylist_append_double(qclists[idet], "ESO QC ATX0",
01190                 hawki_cal_zpoint_outputs.atx0[idet]) ;
01191         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT POSX",
01192                 hawki_cal_zpoint_outputs.posx[idet]) ;
01193         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT POSY",
01194                 hawki_cal_zpoint_outputs.posy[idet]) ;
01195         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT FLUX",
01196                 hawki_cal_zpoint_outputs.flux[idet]) ;
01197         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT PEAK",
01198                 hawki_cal_zpoint_outputs.peak[idet]) ;
01199         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT BGD",
01200                 hawki_cal_zpoint_outputs.bgd[idet]) ;
01201         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT FWHMX",
01202                 hawki_cal_zpoint_outputs.fwhmx[idet]) ;
01203         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT FWHMY",
01204                 hawki_cal_zpoint_outputs.fwhmy[idet]) ;
01205         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT FWHM",
01206                 hawki_cal_zpoint_outputs.fwhm[idet]) ;
01207         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT FWHMX_AS",
01208                 hawki_cal_zpoint_outputs.fwhmx_as[idet]) ;
01209         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT FWHMY_AS",
01210                 hawki_cal_zpoint_outputs.fwhmy_as[idet]) ;
01211         cpl_propertylist_append_double(qclists[idet], "ESO QC ZPOINT FWHM_AS",
01212                 hawki_cal_zpoint_outputs.fwhm_as[idet]) ;
01213 
01214         /* Propagate some keywords from input raw frame extensions */
01215         ext_nb=hawki_get_ext_from_detector(ref_filename, idet+1);
01216         inputlist = cpl_propertylist_load_regexp(ref_filename, ext_nb,
01217                 HAWKI_HEADER_EXT_FORWARD, 0) ;
01218         cpl_propertylist_append(qclists[idet], inputlist) ;
01219         cpl_propertylist_delete(inputlist) ;
01220 
01221         /* Propagate WCS keywords */
01222         for(iframe=0; iframe<cpl_frameset_get_size(zpoint_frames); iframe++)
01223             if(labels[iframe] == idet + 1)
01224                 this_iframe = iframe;
01225         wcslist = cpl_propertylist_load_regexp
01226             (cpl_frame_get_filename(cpl_frameset_get_frame(zpoint_frames, this_iframe)),
01227                                     ext_nb, HAWKI_HEADER_WCS, 0);
01228         cpl_propertylist_copy_property_regexp
01229             (qclists[idet], wcslist, HAWKI_HEADER_WCS, 0);
01230         cpl_propertylist_delete(wcslist) ;
01231     }
01232     
01233     /* Write the zpoint table  */
01234     used_frames = cpl_frameset_duplicate(zpoint_frames);
01235     for(iframe = 0; iframe< cpl_frameset_get_size(calib_frames); ++iframe)
01236         cpl_frameset_insert(used_frames, cpl_frame_duplicate(
01237                 cpl_frameset_get_frame(calib_frames, iframe)));
01238     cpl_frameset_insert(used_frames, cpl_frame_duplicate(stars_frame));
01239     hawki_tables_save(set,
01240                       parlist,
01241                       used_frames,
01242                       (const cpl_table **)zpoint_tables,
01243                       recipe_name,
01244                       HAWKI_CALPRO_ZPOINT_TAB,
01245                       HAWKI_PROTYPE_ZPOINT_TAB,
01246                       NULL,
01247                       (const cpl_propertylist **)qclists,
01248                       "hawki_cal_zpoint.fits");
01249     cpl_frameset_delete(used_frames);
01250     
01251     /* Statistics of the raw images in the QC */
01252     hawki_image_stats_stats(raw_zpoint_stats, qclists);
01253 
01254     /* Write the table with the raw zpoint objects statistics */
01255     used_frames = cpl_frameset_duplicate(zpoint_frames);
01256     hawki_tables_save(set,
01257                       parlist,
01258                       used_frames,
01259                       (const cpl_table **)raw_zpoint_stats,
01260                       recipe_name,
01261                       HAWKI_CALPRO_ZPOINT_STATS,
01262                       HAWKI_PROTYPE_ZPOINT_STATS,
01263                       NULL,
01264                       (const cpl_propertylist **)qclists,
01265                       "hawki_cal_zpoint_stats.fits");
01266 
01267     /* Write the images  */
01268     for(iframe = 0; iframe< cpl_frameset_get_size(calib_frames); ++iframe)
01269         cpl_frameset_insert(used_frames, cpl_frame_duplicate(
01270                 cpl_frameset_get_frame(calib_frames, iframe)));
01271     hawki_imagelist_save(set,
01272                          parlist,
01273                          used_frames,
01274                          images,
01275                          recipe_name,
01276                          HAWKI_CALPRO_ZPOINT_IMA,
01277                          HAWKI_PROTYPE_ZPOINT_IMA,
01278                          NULL,
01279                          (const cpl_propertylist**)qclists,
01280                          "hawki_cal_zpoint_check.fits") ;
01281     cpl_frameset_delete(used_frames);
01282 
01283     /* Remove the keywords for the FITS extensions */
01284     for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++) {
01285         cpl_propertylist_erase_regexp(qclists[idet], HAWKI_HEADER_EXT_FORWARD, 0) ;
01286     }
01287 
01288     /* Free */
01289     for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++) {
01290         cpl_propertylist_delete(qclists[idet]) ;
01291     }
01292     cpl_free(qclists) ;
01293 
01294     /* Free */
01295     if(!cpl_errorstate_is_equal(error_prevstate))
01296     {
01297         cpl_errorstate_set(CPL_ERROR_NONE);
01298         return -1;
01299     }
01300     return  0;
01301 }
01302 
01303 /*----------------------------------------------------------------------------*/
01309 /*----------------------------------------------------------------------------*/
01310 static int hawki_cal_zpoint_compute_keywords(
01311         cpl_frameset    *   set,
01312         int             *   labels)
01313 {
01314     int                     nframes ;
01315     cpl_vector          *   hum_vec ;
01316     cpl_frame           *   cur_frame ;
01317     cpl_propertylist    *   plist ;
01318     int                     iframe;
01319 
01320     /* Test inputs  */
01321     if (set == NULL) return -1 ;
01322 
01323     /* Initialize */
01324     nframes = cpl_frameset_get_size(set) ;
01325     hawki_cal_zpoint_outputs.mean_airmass   = 0.0 ;
01326 
01327     hum_vec = cpl_vector_new(nframes) ;
01328 
01329     for (iframe=0 ; iframe<nframes ; iframe++) {
01330         if (cpl_error_get_code()) {
01331             cpl_vector_delete(hum_vec) ;
01332             return -1 ;
01333         }
01334         cur_frame = cpl_frameset_get_frame(set, iframe) ;
01335         plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0) ;
01336         if (iframe==0) 
01337             hawki_cal_zpoint_outputs.mean_airmass += 
01338                 hawki_pfits_get_airmass_start(plist) ; 
01339         if (iframe==nframes-1) 
01340             hawki_cal_zpoint_outputs.mean_airmass += 
01341                 hawki_pfits_get_airmass_end(plist);
01342         hawki_cal_zpoint_outputs.airmass[labels[iframe] - 1] = 
01343             (hawki_pfits_get_airmass_start(plist) + 
01344              hawki_pfits_get_airmass_end(plist)) / 2.;
01345         cpl_vector_set(hum_vec,  iframe, hawki_pfits_get_humidity_level(plist));
01346         cpl_propertylist_delete(plist) ;
01347         if (cpl_error_get_code()) {
01348             cpl_vector_delete(hum_vec) ;
01349             cpl_error_reset() ;
01350             return -1 ;
01351         }
01352     }
01353     hawki_cal_zpoint_outputs.humidity  = cpl_vector_get_mean(hum_vec) ;
01354     hawki_cal_zpoint_outputs.mean_airmass /= 2 ;
01355 
01356     /* Free and return */
01357     cpl_vector_delete(hum_vec) ;
01358     if (cpl_error_get_code()) return -1 ;
01359     return 0 ;
01360 }
01361 
01362 static cpl_error_code hawki_cal_zpoint_get_expected_pos
01363 (cpl_frameset * set,
01364  int          * labels)
01365 {
01366     const char *  filename;
01367     int           iframe;
01368 
01369     for(iframe=0 ; iframe<HAWKI_NB_DETECTORS ; iframe++)
01370     {
01371         cpl_propertylist * wcs_plist;
01372         cpl_wcs          * wcs;
01373         int                idet;
01374 
01375         idet = labels[iframe];
01376         if(hawki_cal_zpoint_config.xcoord[idet - 1] == -1 ||
01377                 hawki_cal_zpoint_config.ycoord[idet - 1] == -1)
01378         {
01379             filename = cpl_frame_get_filename
01380                 (cpl_frameset_get_frame_const(set, iframe));
01381             wcs_plist = cpl_propertylist_load
01382                 (filename, hawki_get_ext_from_detector(filename, idet));
01383             wcs = cpl_wcs_new_from_propertylist(wcs_plist);
01384             cpl_propertylist_delete(wcs_plist);
01385             if(wcs == NULL)
01386             {
01387                 cpl_msg_error(__func__, "Could not get WCS info");
01388                 cpl_wcs_delete(wcs);
01389                 return CPL_ERROR_ILLEGAL_INPUT;
01390             }
01391             if(irplib_wcs_radectoxy(wcs,
01392                                     hawki_cal_zpoint_outputs.stdstar_ra,
01393                                     hawki_cal_zpoint_outputs.stdstar_dec,
01394                                     &(hawki_cal_zpoint_config.xcoord[idet - 1]),
01395                                     &(hawki_cal_zpoint_config.ycoord[idet - 1]))
01396                     != CPL_ERROR_NONE)
01397             {
01398                 cpl_msg_error(__func__,"Could not get the expected position of star");
01399                 cpl_wcs_delete(wcs);
01400                 return CPL_ERROR_UNSPECIFIED;
01401             }
01402 
01403             /* Free */
01404             cpl_wcs_delete(wcs);
01405         }
01406     }
01407 
01408     return 0;
01409 }
01410 
01411 
01412 static void hawki_cal_zpoint_output_init(void)
01413 {
01414     int idet;
01415 
01416     hawki_cal_zpoint_outputs.starname[0] = (char)0 ;
01417     hawki_cal_zpoint_outputs.sptype[0] = (char)0 ;
01418     hawki_cal_zpoint_outputs.filter[0] = (char)0 ;
01419     hawki_cal_zpoint_outputs.catalog[0] = (char)0 ;
01420     hawki_cal_zpoint_outputs.pixscale = -1.0 ;
01421     hawki_cal_zpoint_outputs.dit = -1.0 ;
01422     hawki_cal_zpoint_outputs.humidity = -1.0 ;
01423     hawki_cal_zpoint_outputs.mean_airmass = -1.0 ;
01424     for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
01425     {
01426         hawki_cal_zpoint_outputs.airmass[idet] = -1.0 ;
01427         hawki_cal_zpoint_outputs.zpoint[idet] = -1.0 ;
01428         hawki_cal_zpoint_outputs.atx0[idet] = -1.0 ;
01429         hawki_cal_zpoint_outputs.posx[idet] = -1.0 ;
01430         hawki_cal_zpoint_outputs.posy[idet] = -1.0 ;
01431         hawki_cal_zpoint_outputs.flux[idet] = -1.0 ;
01432         hawki_cal_zpoint_outputs.peak[idet] = -1.0 ;
01433         hawki_cal_zpoint_outputs.bgd[idet] = -1.0 ;
01434         hawki_cal_zpoint_outputs.fwhmx[idet] = -1.0 ;
01435         hawki_cal_zpoint_outputs.fwhmy[idet] = -1.0 ;
01436         hawki_cal_zpoint_outputs.fwhm[idet] = -1.0 ;
01437         hawki_cal_zpoint_outputs.fwhmx_as[idet] = -1.0 ;
01438         hawki_cal_zpoint_outputs.fwhmy_as[idet] = -1.0 ;
01439         hawki_cal_zpoint_outputs .fwhm_as[idet] = -1.0 ;
01440     }
01441 }
01442 
01443 int hawki_cal_zpoint_retrieve_input_param
01444 (cpl_parameterlist  *  parlist)
01445 {
01446     cpl_parameter   *   par ;
01447     const char      *   sval ;
01448 
01449     par = NULL ;
01450 
01451     /* --ra */
01452     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.ra") ;
01453     hawki_cal_zpoint_config.target_ra = cpl_parameter_get_double(par) ;
01454     /* --dec */
01455     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.dec") ;
01456     hawki_cal_zpoint_config.target_dec = cpl_parameter_get_double(par) ;
01457     /* --mag */
01458     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.mag") ;
01459     hawki_cal_zpoint_config.magnitude = cpl_parameter_get_double(par) ;
01460     /* --detect_sigma */
01461     par = cpl_parameterlist_find(parlist,"hawki.hawki_cal_zpoint.detect_sigma");
01462     hawki_cal_zpoint_config.detect_sigma = cpl_parameter_get_double(par) ;
01463     /* --sx */
01464     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.sx") ;
01465     hawki_cal_zpoint_config.sx = cpl_parameter_get_int(par) ;
01466     /* --sy */
01467     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.sy") ;
01468     hawki_cal_zpoint_config.sy = cpl_parameter_get_int(par) ;
01469     /* --star_r */
01470     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.star_r") ;
01471     hawki_cal_zpoint_config.phot_star_radius = cpl_parameter_get_double(par) ;
01472     /* --bg_r1 */
01473     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.bg_r1") ;
01474     hawki_cal_zpoint_config.phot_bg_r1 = cpl_parameter_get_double(par) ;
01475     /* --bg_r2 */
01476     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.bg_r2") ;
01477     hawki_cal_zpoint_config.phot_bg_r2 = cpl_parameter_get_double(par) ;
01478     /* --xcoord */
01479     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.xcoord");
01480     sval = cpl_parameter_get_string(par);
01481     if (sscanf(sval, "%lf,%lf,%lf,%lf",
01482                hawki_cal_zpoint_config.xcoord,
01483                hawki_cal_zpoint_config.xcoord+1,
01484                hawki_cal_zpoint_config.xcoord+2,
01485                hawki_cal_zpoint_config.xcoord+3)!=4)
01486     {
01487         return -1;
01488     }
01489     /* --ycoord */
01490     par = cpl_parameterlist_find(parlist, "hawki.hawki_cal_zpoint.ycoord");
01491     sval = cpl_parameter_get_string(par);
01492     if (sscanf(sval, "%lf,%lf,%lf,%lf",
01493                hawki_cal_zpoint_config.ycoord,
01494                hawki_cal_zpoint_config.ycoord+1,
01495                hawki_cal_zpoint_config.ycoord+2,
01496                hawki_cal_zpoint_config.ycoord+3)!=4)
01497     {
01498         return -1;
01499     }
01500 
01501     return 0;
01502 }
01503 
01504 int hawki_cal_zpoint_check_epoch_equinox(cpl_propertylist * plist)
01505 {
01506     if(hawki_pfits_get_targ_epoch(plist) != 2000. ||
01507        hawki_pfits_get_targ_equinox(plist) != 2000.)
01508     {
01509         cpl_msg_error(__func__,"Epoch and equinox must be 2000.");
01510         return -1;
01511     }
01512     else
01513         return 0;
01514 }

Generated on 10 Jun 2010 for HAWKI Pipeline Reference Manual by  doxygen 1.6.1