/* $Id: cpl_tools.h,v 1.70 2008/02/13 13:12:51 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: 2008/02/13 13:12:51 $ * $Revision: 1.70 $ * $Name: $ */ #ifndef CPL_TOOLS_H #define CPL_TOOLS_H /*----------------------------------------------------------------------------- Includes -----------------------------------------------------------------------------*/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include "cpl_propertylist.h" #include "cpl_error.h" #include "cpl_errorstate.h" #include "cpl_vector.h" #include "cpl_msg.h" #include "cpl_test.h" /*----------------------------------------------------------------------------- Define -----------------------------------------------------------------------------*/ /** @ingroup cpl_tools @internal @brief Generate and return a double in the range 0 to 1. @return A pseudo-random number in the range 0 to 1 @see rand() */ #define cpl_drand() ((double)rand()/(double)RAND_MAX) #define CPL_XSTRINGIFY(TOSTRING) #TOSTRING #define CPL_STRINGIFY(TOSTRING) CPL_XSTRINGIFY(TOSTRING) #define CPL_FITS_BADKEYS "SIMPLE|BSCALE|BZERO|EXTEND" \ "|XTENSION|BITPIX|NAXIS[0-9]*|PCOUNT|GCOUNT|DATE" "" \ "|TFIELDS|TFORM[0-9]*|TTYPE[0-9]*|TUNIT[0-9]*|TZERO[0-9]*" \ "|TSCAL[0-9]*|TDIM[0-9]*|TNULL[0-9]*" #define CPL_FITS_BADKEYS_PRIM "^(" CPL_FITS_BADKEYS \ "|BLOCKED|EXTNAME|EXTVER|EXTLEVEL" ")$" #define CPL_FITS_BADKEYS_EXT "^(" CPL_FITS_BADKEYS \ "|ORIGIN[0-9]*)$" #define CPL_FITS_COMPRKEYS "^(" "ZIMAGE|ZCMPTYPE|ZNAXIS" \ "|ZTENSION|ZPCOUNT|ZGCOUNT|ZNAME[0-9]|ZVAL[0-9]|" \ "ZTILE[0-9]|ZBITPIX|ZNAXIS[0-9]|ZSCALE|ZZERO|ZBLANK" ")$" typedef unsigned long long int cpl_flops; enum _cpl_clock_ { CPL_CLOCK_RESET, CPL_CLOCK_START, CPL_CLOCK_STOP, CPL_CLOCK_TIME }; typedef enum _cpl_clock_ cpl_clock; #if defined HAVE_LONG_DOUBLE && HAVE_LONG_DOUBLE == 1 typedef long double cpl_long_double; #define CPL_LDBL_EPSILON LDBL_EPSILON #define CPL_LDBL_EPSILON_STR "LDBL_EPSILON" #else typedef double cpl_long_double; #define CPL_LDBL_EPSILON DBL_EPSILON #define CPL_LDBL_EPSILON_STR "DBL_EPSILON" #endif /*----------------------------------------------------------------------------- Function prototypes -----------------------------------------------------------------------------*/ /* Operations on arrays */ double cpl_tools_get_kth_double(double *, int, int) ; float cpl_tools_get_kth_float(float *, int, int) ; int cpl_tools_get_kth_int(int *, int, int) ; double cpl_tools_get_variance_double(const double *, int, double); double cpl_tools_get_median_double(double *, int) ; float cpl_tools_get_median_float(float *, int) ; int cpl_tools_get_median_int(int *, int) ; cpl_error_code cpl_tools_copy_window(void *, const void *, size_t, int, int, int, int, int, int); /* Sorting */ cpl_error_code cpl_tools_sort_stable_pattern_int(const int *, int, int, int, int *); cpl_error_code cpl_tools_sort_stable_pattern_float(const float *, int, int, int, int *); cpl_error_code cpl_tools_sort_stable_pattern_double(const double *, int, int, int, int *); cpl_error_code cpl_tools_sort_stable_pattern_string(char * const *, int, int, int, int *); cpl_error_code cpl_tools_sort_double(double *, int) ; cpl_error_code cpl_tools_sort_int(int *, int) ; void cpl_polynomial_shift_double(double *, int, double); cpl_vector * cpl_vector_transform_mean(const cpl_vector *, double *); /* Benchmarking functionality */ double cpl_tools_get_cputime(cpl_clock); void cpl_tools_reset_flops(void); void cpl_tools_add_flops(cpl_flops); cpl_flops cpl_tools_get_flops(void); /* Others */ int cpl_tools_is_power_of_2(int) ; double cpl_tools_ipow(double, int); double * cpl_tools_fill_kernel_profile(cpl_kernel, int *) ; cpl_error_code cpl_fits_add_properties(fitsfile *, const cpl_propertylist *, const char *) ; const char * cpl_tools_get_cfitsio_msg(int); cpl_error_code cpl_vector_ensure_distinct(const cpl_vector *, int); #endif