1 /********************************************************************* 2 Arithmetic -- Preform arithmetic operations on datasets. 3 This is part of GNU Astronomy Utilities (Gnuastro) package. 4 5 Original author: 6 Mohammad Akhlaghi <mohammad@akhlaghi.org> 7 Contributing author(s): 8 Copyright (C) 2017-2021, Free Software Foundation, Inc. 9 10 Gnuastro is free software: you can redistribute it and/or modify it 11 under the terms of the GNU General Public License as published by the 12 Free Software Foundation, either version 3 of the License, or (at your 13 option) any later version. 14 15 Gnuastro is distributed in the hope that it will be useful, but 16 WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>. 22 **********************************************************************/ 23 #ifndef __GAL_ARITHMETIC_H__ 24 #define __GAL_ARITHMETIC_H__ 25 26 /* Include other headers if necessary here. Note that other header files 27 must be included before the C++ preparations below */ 28 #include <gnuastro/data.h> 29 30 31 /* When we are within Gnuastro's building process, 'IN_GNUASTRO_BUILD' is 32 defined. In the build process, installation information (in particular 33 'GAL_CONFIG_ARITH_CHAR' and the rest of the types that we needed in the 34 arithmetic function) is kept in 'config.h'. When building a user's 35 programs, this information is kept in 'gnuastro/config.h'. Note that all 36 '.c' files must start with the inclusion of 'config.h' and that 37 'gnuastro/config.h' is only created at installation time (not present 38 during the building of Gnuastro).*/ 39 #ifndef IN_GNUASTRO_BUILD 40 #include <gnuastro/config.h> 41 #endif 42 43 44 /* C++ Preparations */ 45 #undef __BEGIN_C_DECLS 46 #undef __END_C_DECLS 47 #ifdef __cplusplus 48 # define __BEGIN_C_DECLS extern "C" { 49 # define __END_C_DECLS } 50 #else 51 # define __BEGIN_C_DECLS /* empty */ 52 # define __END_C_DECLS /* empty */ 53 #endif 54 /* End of C++ preparations */ 55 56 57 58 /* Actual header contants (the above were for the Pre-processor). */ 59 __BEGIN_C_DECLS /* From C++ preparations */ 60 61 62 63 /* Arithmetic on-off bit flags (have to be powers of 2). */ 64 #define GAL_ARITHMETIC_FLAG_INPLACE 1 65 #define GAL_ARITHMETIC_FLAG_FREE 2 66 #define GAL_ARITHMETIC_FLAG_NUMOK 4 67 #define GAL_ARITHMETIC_FLAG_ENVSEED 8 68 #define GAL_ARITHMETIC_FLAG_QUIET 16 69 70 #define GAL_ARITHMETIC_FLAGS_BASIC ( GAL_ARITHMETIC_FLAG_INPLACE \ 71 | GAL_ARITHMETIC_FLAG_FREE \ 72 | GAL_ARITHMETIC_FLAG_NUMOK ) 73 74 75 /* Identifiers for each operator. */ 76 enum gal_arithmetic_operators 77 { 78 GAL_ARITHMETIC_OP_INVALID, /* Invalid (=0 by C standard). */ 79 80 GAL_ARITHMETIC_OP_PLUS, /* + */ 81 GAL_ARITHMETIC_OP_MINUS, /* - */ 82 GAL_ARITHMETIC_OP_MULTIPLY, /* x */ 83 GAL_ARITHMETIC_OP_DIVIDE, /* / */ 84 GAL_ARITHMETIC_OP_MODULO, /* % */ 85 86 GAL_ARITHMETIC_OP_LT, /* < */ 87 GAL_ARITHMETIC_OP_LE, /* <= */ 88 GAL_ARITHMETIC_OP_GT, /* > */ 89 GAL_ARITHMETIC_OP_GE, /* >= */ 90 GAL_ARITHMETIC_OP_EQ, /* == */ 91 GAL_ARITHMETIC_OP_NE, /* != */ 92 GAL_ARITHMETIC_OP_AND, /* && */ 93 GAL_ARITHMETIC_OP_OR, /* || */ 94 GAL_ARITHMETIC_OP_NOT, /* ! */ 95 GAL_ARITHMETIC_OP_ISBLANK, /* Similar to isnan() for floats. */ 96 GAL_ARITHMETIC_OP_WHERE, /* ?: */ 97 98 GAL_ARITHMETIC_OP_BITAND, /* & */ 99 GAL_ARITHMETIC_OP_BITOR, /* | */ 100 GAL_ARITHMETIC_OP_BITXOR, /* ^ */ 101 GAL_ARITHMETIC_OP_BITLSH, /* << */ 102 GAL_ARITHMETIC_OP_BITRSH, /* >> */ 103 GAL_ARITHMETIC_OP_BITNOT, /* ~ */ 104 105 GAL_ARITHMETIC_OP_ABS, /* abs() */ 106 GAL_ARITHMETIC_OP_POW, /* pow() */ 107 GAL_ARITHMETIC_OP_SQRT, /* sqrt() */ 108 GAL_ARITHMETIC_OP_LOG, /* log() */ 109 GAL_ARITHMETIC_OP_LOG10, /* log10() */ 110 111 GAL_ARITHMETIC_OP_SIN, /* sine (input in deg). */ 112 GAL_ARITHMETIC_OP_COS, /* cosine (input in deg). */ 113 GAL_ARITHMETIC_OP_TAN, /* tangent (input in deg). */ 114 GAL_ARITHMETIC_OP_ASIN, /* Inverse sine (output in deg). */ 115 GAL_ARITHMETIC_OP_ACOS, /* Inverse cosine (output in deg). */ 116 GAL_ARITHMETIC_OP_ATAN, /* Inverse tangent (output in deg). */ 117 GAL_ARITHMETIC_OP_ATAN2, /* Inv. atan (preserves quad, out in deg). */ 118 GAL_ARITHMETIC_OP_SINH, /* Hyperbolic sine. */ 119 GAL_ARITHMETIC_OP_COSH, /* Hyperbolic cosine. */ 120 GAL_ARITHMETIC_OP_TANH, /* Hyperbolic tangent. */ 121 GAL_ARITHMETIC_OP_ASINH, /* Inverse hyperbolic sine. */ 122 GAL_ARITHMETIC_OP_ACOSH, /* Inverse hyperbolic cosine. */ 123 GAL_ARITHMETIC_OP_ATANH, /* Inverse hyperbolic tangent. */ 124 125 GAL_ARITHMETIC_OP_RA_TO_DEGREE, /* right ascension to decimal. */ 126 GAL_ARITHMETIC_OP_DEC_TO_DEGREE,/* declination to decimal. */ 127 GAL_ARITHMETIC_OP_DEGREE_TO_RA, /* right ascension to decimal. */ 128 GAL_ARITHMETIC_OP_DEGREE_TO_DEC,/* declination to decimal. */ 129 GAL_ARITHMETIC_OP_COUNTS_TO_MAG,/* Counts to magnitude. */ 130 GAL_ARITHMETIC_OP_MAG_TO_COUNTS,/* Magnitude to counts. */ 131 GAL_ARITHMETIC_OP_COUNTS_TO_JY, /* Counts to Janskys with AB-mag zeropoint. */ 132 GAL_ARITHMETIC_OP_AU_TO_PC, /* Astronomical units (AU) to Parsecs (PC). */ 133 GAL_ARITHMETIC_OP_PC_TO_AU, /* Parsecs (PC) to Astronomical units (AU). */ 134 GAL_ARITHMETIC_OP_LY_TO_PC, /* Astronomical units (AU) to Parsecs (PC). */ 135 GAL_ARITHMETIC_OP_PC_TO_LY, /* Parsecs (PC) to Astronomical units (AU). */ 136 GAL_ARITHMETIC_OP_LY_TO_AU, /* Light-years to Astronomical units (AU). */ 137 GAL_ARITHMETIC_OP_AU_TO_LY, /* Astronomical units (AU) to Light-years. */ 138 139 GAL_ARITHMETIC_OP_MINVAL, /* Minimum value of array. */ 140 GAL_ARITHMETIC_OP_MAXVAL, /* Maximum value of array. */ 141 GAL_ARITHMETIC_OP_NUMBERVAL, /* Number of (non-blank) elements. */ 142 GAL_ARITHMETIC_OP_SUMVAL, /* Sum of (non-blank) elements. */ 143 GAL_ARITHMETIC_OP_MEANVAL, /* Mean value of array. */ 144 GAL_ARITHMETIC_OP_STDVAL, /* Standard deviation value of array. */ 145 GAL_ARITHMETIC_OP_MEDIANVAL, /* Median value of array. */ 146 147 GAL_ARITHMETIC_OP_MIN, /* Minimum per pixel of multiple arrays. */ 148 GAL_ARITHMETIC_OP_MAX, /* Maximum per pixel of multiple arrays. */ 149 GAL_ARITHMETIC_OP_NUMBER, /* Non-blank number of pixels in arrays. */ 150 GAL_ARITHMETIC_OP_SUM, /* Sum per pixel of multiple arrays. */ 151 GAL_ARITHMETIC_OP_MEAN, /* Mean per pixel of multiple arrays. */ 152 GAL_ARITHMETIC_OP_STD, /* STD per pixel of multiple arrays. */ 153 GAL_ARITHMETIC_OP_MEDIAN, /* Median per pixel of multiple arrays. */ 154 GAL_ARITHMETIC_OP_QUANTILE, /* Quantile per pixel of multiple arrays.*/ 155 GAL_ARITHMETIC_OP_SIGCLIP_NUMBER,/* Sigma-clipped number of mult. arrays.*/ 156 GAL_ARITHMETIC_OP_SIGCLIP_MEAN, /* Sigma-clipped mean of multiple arrays.*/ 157 GAL_ARITHMETIC_OP_SIGCLIP_MEDIAN,/* Sigma-clipped median of mult. arrays.*/ 158 GAL_ARITHMETIC_OP_SIGCLIP_STD, /* Sigma-clipped STD of multiple arrays. */ 159 160 GAL_ARITHMETIC_OP_MKNOISE_SIGMA,/* Fixed-sigma noise to every element. */ 161 GAL_ARITHMETIC_OP_MKNOISE_POISSON,/* Poission noise on every element. */ 162 GAL_ARITHMETIC_OP_MKNOISE_UNIFORM,/* Uniform noise on every element. */ 163 164 GAL_ARITHMETIC_OP_SIZE, /* Size of the dataset along an axis */ 165 166 GAL_ARITHMETIC_OP_TO_UINT8, /* Convert to uint8_t. */ 167 GAL_ARITHMETIC_OP_TO_INT8, /* Convert to int8_t. */ 168 GAL_ARITHMETIC_OP_TO_UINT16, /* Convert to uint16_t. */ 169 GAL_ARITHMETIC_OP_TO_INT16, /* Convert to int16_t. */ 170 GAL_ARITHMETIC_OP_TO_UINT32, /* Convert to uint32_t. */ 171 GAL_ARITHMETIC_OP_TO_INT32, /* Convert to int32_t. */ 172 GAL_ARITHMETIC_OP_TO_UINT64, /* Convert to uint64_t. */ 173 GAL_ARITHMETIC_OP_TO_INT64, /* Convert to int64_t. */ 174 GAL_ARITHMETIC_OP_TO_FLOAT32, /* Convert to float32. */ 175 GAL_ARITHMETIC_OP_TO_FLOAT64, /* Convert to float64. */ 176 177 GAL_ARITHMETIC_OP_BOX_AROUND_ELLIPSE, /* Width/Height of box over ellipse*/ 178 179 GAL_ARITHMETIC_OP_MAKENEW, /* Build a new dataset, containing zeros.*/ 180 181 GAL_ARITHMETIC_OP_LAST_CODE, /* Last code of the library operands. */ 182 }; 183 184 char * 185 gal_arithmetic_operator_string(int operator); 186 187 int 188 gal_arithmetic_set_operator(char *string, size_t *num_operands); 189 190 gal_data_t * 191 gal_arithmetic(int operator, size_t numthreads, int flags, ...); 192 193 194 195 __END_C_DECLS /* From C++ preparations */ 196 197 #endif /* __GAL_ARITHMETIC_H__ */ 198