[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master bc57ade 021/125: Minimum and maximum value ope
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master bc57ade 021/125: Minimum and maximum value operators implemented |
Date: |
Sun, 23 Apr 2017 22:36:28 -0400 (EDT) |
branch: master
commit bc57ade2c842914915f0ff8868215597bb56a0be
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Minimum and maximum value operators implemented
The minimum and maximum value operators are now available to the
`gal_data_arithmetic' library function and thus to Arithmetic. As part of
implementing these functions, the old `data_arithmetic_unary_function_f'
was removed and is now generally usable for any type. Depending on the
operator, control will either be taken to functions to work on each element
(for example taking the log of every pixel), or to work on the full array
(like minimum or maximum values).
Other smaller work that is done with this commit:
- When the output of Arithmetic is a single element data structure, it is
printed as a number, not saved as a FITS file (like before this branch
started).
- The unused `operator' argument to `data_arithmetic_bitwise_not' was
removed.
- The two new `gal_data_type_min' and `gal_data_type_max' functions now
return the maximum value of the given type in a `void *' pointer.
---
bin/arithmetic/arithmetic.c | 32 ++++---
lib/data-arithmetic-onlyint.c | 18 ++--
lib/data-arithmetic-onlyint.h | 5 +-
lib/data-arithmetic-other.c | 191 ++++++++++++++++++++++++++++++++++++------
lib/data-arithmetic-other.h | 6 +-
lib/data.c | 133 +++++++++++++++++++++--------
lib/fits.c | 4 -
lib/gnuastro/data.h | 22 +++--
8 files changed, 321 insertions(+), 90 deletions(-)
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index 604b3f4..4389893 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -118,9 +118,9 @@ reversepolish(struct imgarithparams *p)
{ op=GAL_DATA_OPERATOR_LOG10; nop=1; }
/* Statistical operators. */
- else if (!strcmp(token->v, "minval"))
+ else if (!strcmp(token->v, "minvalue"))
{ op=GAL_DATA_OPERATOR_MINVAL; nop=1; }
- else if (!strcmp(token->v, "maxval"))
+ else if (!strcmp(token->v, "maxvalue"))
{ op=GAL_DATA_OPERATOR_MAXVAL; nop=1; }
else if (!strcmp(token->v, "min"))
{ op=GAL_DATA_OPERATOR_MIN; nop=-1; }
@@ -246,16 +246,28 @@ reversepolish(struct imgarithparams *p)
d1=p->operands->data;
- /* Put a copy of the WCS structure from the reference image, it will be
- freed while freeing d1. */
- d1->wcs=p->refdata.wcs;
-
-
- /* Write the data structure to a FITS image. */
- gal_fits_write_img(d1, p->cp.output, "Arithmetic", NULL, SPACK_STRING);
+ /* If the final data structure has more than one element, write it as a
+ FITS file. Otherwise, print it in the standard output. */
+ if(d1->size==1)
+ {
+ /* To simplify the printing process, we will first change it to
+ double, then use printf's `%g' to print it, so integers will be
+ printed as an integer. */
+ d2=gal_data_copy_to_new_type(d1, GAL_DATA_TYPE_DOUBLE);
+ printf("%g\n", *(double *)d2->array);
+ gal_data_free(d2);
+ }
+ else
+ {
+ /* Put a copy of the WCS structure from the reference image, it
+ will be freed while freeing d1. */
+ d1->wcs=p->refdata.wcs;
+ gal_fits_write_img(d1, p->cp.output, "Arithmetic", NULL, SPACK_STRING);
+ }
- /* Clean up: */
+ /* Clean up, note that above, we copied the pointer to `refdata->wcs'
+ into `d1', so it is freed when freeing d1. */
gal_data_free(d1);
free(p->refdata.dsize);
diff --git a/lib/data-arithmetic-onlyint.c b/lib/data-arithmetic-onlyint.c
index 63ab16e..5bf729a 100644
--- a/lib/data-arithmetic-onlyint.c
+++ b/lib/data-arithmetic-onlyint.c
@@ -667,8 +667,7 @@ data_arithmetic_onlyint_binary(int operator, unsigned char
flags,
gal_data_t *
-data_arithmetic_bitwise_not(int operator, unsigned char flags,
- gal_data_t *in)
+data_arithmetic_bitwise_not(unsigned char flags, gal_data_t *in)
{
gal_data_t *o;
unsigned char *iuc=in->array, *iucf=in->array+in->size, *ouc;
@@ -681,6 +680,15 @@ data_arithmetic_bitwise_not(int operator, unsigned char
flags,
long *il=in->array, *ilf=in->array+in->size, *ol;
LONGLONG *iL=in->array, *iLf=in->array+in->size, *oL;
+ /* Check the type */
+ switch(in->type)
+ {
+ case GAL_DATA_TYPE_FLOAT:
+ case GAL_DATA_TYPE_DOUBLE:
+ error(EXIT_FAILURE, 0, "the bitwise not (one's complement) "
+ "operator can only work on integer types");
+ }
+
/* If we want inplace output, set the output pointer to the input
pointer, for every pixel, the operation will be independent. */
if(flags & GAL_DATA_ARITH_INPLACE)
@@ -689,7 +697,7 @@ data_arithmetic_bitwise_not(int operator, unsigned char
flags,
o = gal_data_alloc(NULL, in->type, in->ndim, in->dsize, in->wcs,
0, in->minmapsize);
- /* Start setting the operator and operands. */
+ /* Start setting the types. */
switch(in->type)
{
case GAL_DATA_TYPE_UCHAR:
@@ -711,8 +719,8 @@ data_arithmetic_bitwise_not(int operator, unsigned char
flags,
case GAL_DATA_TYPE_LONGLONG:
oL=o->array; do *oL++ = ~(*iL++); while(iL<iLf);
default:
- error(EXIT_FAILURE, 0, "Operator code %d not recognized in "
- "data_arithmetic_binary_function", operator);
+ error(EXIT_FAILURE, 0, "type code %d not recognized in "
+ "data_arithmetic_bitwise_not", in->type);
}
diff --git a/lib/data-arithmetic-onlyint.h b/lib/data-arithmetic-onlyint.h
index e1b6c24..f9d8153 100644
--- a/lib/data-arithmetic-onlyint.h
+++ b/lib/data-arithmetic-onlyint.h
@@ -29,6 +29,7 @@ data_arithmetic_onlyint_binary(int operator, unsigned char
flags,
gal_data_t *lo, gal_data_t *ro);
gal_data_t *
-data_arithmetic_bitwise_not(int operator, unsigned char flags,
- gal_data_t *in);
+data_arithmetic_bitwise_not(unsigned char flags, gal_data_t *in);
+
+
#endif
diff --git a/lib/data-arithmetic-other.c b/lib/data-arithmetic-other.c
index 2b4e6fc..6b392b9 100644
--- a/lib/data-arithmetic-other.c
+++ b/lib/data-arithmetic-other.c
@@ -249,6 +249,10 @@ data_arithmetic_abs(unsigned char flags, gal_data_t *in)
+
+
+
+
/***********************************************************************/
/*************** Checking functions **************/
/***********************************************************************/
@@ -302,28 +306,137 @@ check_float_input(gal_data_t *in, int operator, char
*numstr)
/*************** Unary functions **************/
/***********************************************************************/
+#define UNIFUNC_MINVALUE(ISINT) { \
+ int hasblank= (ISINT && gal_data_has_blank(in)) ? 1 : 0; \
+ if(hasblank) \
+ do if(*ia!=*b) *oa = *ia < *oa ? *ia : *oa; while(++ia<iaf); \
+ else \
+ do *oa = *ia < *oa ? *ia : *oa; while(++ia<iaf); \
+ }
-#define UNIFUNC_RUN_FUNCTION(IT, OP){ \
- IT *ia=in->array, *oa=o->array, *of=oa + o->size; \
- do *oa++ = OP(*ia++); while(oa<of); \
+#define UNIFUNC_MAXVALUE(ISINT) { \
+ int hasblank= (ISINT && gal_data_has_blank(in)) ? 1 : 0; \
+ if(hasblank) \
+ do if(*ia!=*b) *oa = *ia > *oa ? *ia : *oa; while(++ia<iaf); \
+ else \
+ do *oa = *ia > *oa ? *ia : *oa; while(++ia<iaf); \
}
-#define UNIFUNC_F_OPERATOR_DONE(OP) \
+#define UNIFUNC_RUN_FUNCTION_ON_ELEMENT(IT, OP){ \
+ IT *ia=in->array, *oa=o->array, *iaf=ia + in->size; \
+ do *oa++ = OP(*ia++); while(ia<iaf); \
+ }
+
+#define UNIFUNC_RUN_FUNCTION_ON_ARRAY(IT, ISINT){ \
+ IT *ia=in->array, *oa=o->array, *iaf=ia + in->size; \
+ IT *b = ISINT ? gal_data_alloc_blank(in->type) : NULL; \
+ switch(operator) \
+ { \
+ case GAL_DATA_OPERATOR_MINVAL: \
+ UNIFUNC_MINVALUE(ISINT); \
+ break; \
+ case GAL_DATA_OPERATOR_MAXVAL: \
+ UNIFUNC_MAXVALUE(ISINT); \
+ break; \
+ default: \
+ error(EXIT_FAILURE, 0, "the operator code %d is not " \
+ "recognized in UNIFUNC_RUN_FUNCTION_ON_ARRAY", operator); \
+ } \
+ if(ISINT) free(b); \
+ }
+
+
+
+
+
+#define UNIARY_FUNCTION_ON_ELEMENT(OP) \
switch(in->type) \
{ \
+ case GAL_DATA_TYPE_UCHAR: \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(unsigned char, OP) \
+ break; \
+ case GAL_DATA_TYPE_CHAR: \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(char, OP) \
+ break; \
+ case GAL_DATA_TYPE_USHORT: \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(unsigned short, OP) \
+ break; \
+ case GAL_DATA_TYPE_SHORT: \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(short, OP) \
+ break; \
+ case GAL_DATA_TYPE_UINT: \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(unsigned int, OP) \
+ break; \
+ case GAL_DATA_TYPE_INT: \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(int, OP) \
+ break; \
+ case GAL_DATA_TYPE_ULONG: \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(unsigned long, OP) \
+ break; \
+ case GAL_DATA_TYPE_LONG: \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(long, OP) \
+ break; \
+ case GAL_DATA_TYPE_LONGLONG: \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(LONGLONG, OP) \
+ break; \
case GAL_DATA_TYPE_FLOAT: \
- UNIFUNC_RUN_FUNCTION(float, OP); \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(float, OP) \
break; \
case GAL_DATA_TYPE_DOUBLE: \
- UNIFUNC_RUN_FUNCTION(double, OP); \
+ UNIFUNC_RUN_FUNCTION_ON_ELEMENT(double, OP) \
break; \
default: \
- error(EXIT_FAILURE, 0, "type %d not recognized in " \
- "for l->type in UNIFUNC_F_OPERATOR_DONE", in->type); \
+ error(EXIT_FAILURE, 0, "type code %d not recognized in " \
+ "`UNIFUNC_PER_ELEMENT'", in->type); \
+ }
+
+
+
+
+
+#define UNIARY_FUNCTION_ON_ARRAY \
+ switch(in->type) \
+ { \
+ case GAL_DATA_TYPE_UCHAR: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(unsigned char, 1) \
+ break; \
+ case GAL_DATA_TYPE_CHAR: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(char, 1) \
+ break; \
+ case GAL_DATA_TYPE_USHORT: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(unsigned short, 1) \
+ break; \
+ case GAL_DATA_TYPE_SHORT: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(short, 1) \
+ break; \
+ case GAL_DATA_TYPE_UINT: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(unsigned int, 1) \
+ break; \
+ case GAL_DATA_TYPE_INT: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(int, 1) \
+ break; \
+ case GAL_DATA_TYPE_ULONG: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(unsigned long, 1) \
+ break; \
+ case GAL_DATA_TYPE_LONG: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(long, 1) \
+ break; \
+ case GAL_DATA_TYPE_LONGLONG: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(LONGLONG, 1) \
+ break; \
+ case GAL_DATA_TYPE_FLOAT: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(float, 0) \
+ break; \
+ case GAL_DATA_TYPE_DOUBLE: \
+ UNIFUNC_RUN_FUNCTION_ON_ARRAY(double, 0) \
+ break; \
+ default: \
+ error(EXIT_FAILURE, 0, "type code %d not recognized in " \
+ "`UNIFUNC_PER_ELEMENT'", in->type); \
}
@@ -331,31 +444,59 @@ check_float_input(gal_data_t *in, int operator, char
*numstr)
gal_data_t *
-data_arithmetic_unary_function_f(int operator, unsigned char flags,
- gal_data_t *in)
+data_arithmetic_unary_function(int operator, unsigned char flags,
+ gal_data_t *in)
{
+ long dsize=1;
gal_data_t *o;
- /* Check the input type. */
- check_float_input(in, operator, "first");
-
/* If we want inplace output, set the output pointer to the input
pointer, for every pixel, the operation will be independent. */
- if(flags & GAL_DATA_ARITH_INPLACE)
- o = in;
- else
- o = gal_data_alloc(NULL, in->type, in->ndim, in->dsize, in->wcs,
- 0, in->minmapsize);
+ switch(operator)
+ {
+
+ /* Operators with only one value as output. */
+ case GAL_DATA_OPERATOR_MINVAL:
+ o = gal_data_alloc(NULL, in->type, 1, &dsize, NULL, 0, -1);
+ gal_data_type_max(o->type, o->array);
+ break;
+ case GAL_DATA_OPERATOR_MAXVAL:
+ o = gal_data_alloc(NULL, in->type, 1, &dsize, NULL, 0, -1);
+ gal_data_type_min(o->type, o->array);
+ break;
+
+ /* The other operators */
+ default:
+ if(flags & GAL_DATA_ARITH_INPLACE)
+ o = in;
+ else
+ o = gal_data_alloc(NULL, in->type, in->ndim, in->dsize, in->wcs,
+ 0, in->minmapsize);
+ }
/* Start setting the operator and operands. */
switch(operator)
{
- case GAL_DATA_OPERATOR_SQRT: UNIFUNC_F_OPERATOR_DONE( sqrt ); break;
- case GAL_DATA_OPERATOR_LOG: UNIFUNC_F_OPERATOR_DONE( log ); break;
- case GAL_DATA_OPERATOR_LOG10: UNIFUNC_F_OPERATOR_DONE( log10 ); break;
+ case GAL_DATA_OPERATOR_SQRT:
+ UNIARY_FUNCTION_ON_ELEMENT( sqrt );
+ break;
+
+ case GAL_DATA_OPERATOR_LOG:
+ UNIARY_FUNCTION_ON_ELEMENT( log );
+ break;
+
+ case GAL_DATA_OPERATOR_LOG10:
+ UNIARY_FUNCTION_ON_ELEMENT( log10 );
+ break;
+
+ case GAL_DATA_OPERATOR_MINVAL:
+ case GAL_DATA_OPERATOR_MAXVAL:
+ UNIARY_FUNCTION_ON_ARRAY;
+ break;
+
default:
- error(EXIT_FAILURE, 0, "Operator code %d not recognized in "
- "data_arithmetic_binary_function", operator);
+ error(EXIT_FAILURE, 0, "operator code %d not recognized in "
+ "data_arithmetic_unary_function", operator);
}
@@ -467,8 +608,8 @@ data_arithmetic_unary_function_f(int operator, unsigned
char flags,
gal_data_t *
-data_arithmetic_binary_function_f(int operator, unsigned char flags,
- gal_data_t *l, gal_data_t *r)
+data_arithmetic_binary_function_flt(int operator, unsigned char flags,
+ gal_data_t *l, gal_data_t *r)
{
int final_otype;
gal_data_t *o=NULL;
diff --git a/lib/data-arithmetic-other.h b/lib/data-arithmetic-other.h
index 5e1d984..f233d43 100644
--- a/lib/data-arithmetic-other.h
+++ b/lib/data-arithmetic-other.h
@@ -34,11 +34,11 @@ gal_data_t *
data_arithmetic_abs(unsigned char flags, gal_data_t *in);
gal_data_t *
-data_arithmetic_unary_function_f(int operator, unsigned char flags,
- gal_data_t *in);
+data_arithmetic_unary_function(int operator, unsigned char flags,
+ gal_data_t *in);
gal_data_t *
-data_arithmetic_binary_function_f(int operator, unsigned char flags,
+data_arithmetic_binary_function_flt(int operator, unsigned char flags,
gal_data_t *l, gal_data_t *r);
void
diff --git a/lib/data.c b/lib/data.c
index ebdc333..77af0b4 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -218,7 +218,6 @@ gal_data_calloc_array(int type, size_t size)
void *
gal_data_alloc_number(int type, void *number)
{
- /* Define the pointers. */
void *allocated;
/* Allocate the space for the blank value: */
@@ -381,9 +380,7 @@ gal_data_alloc(void *array, int type, size_t ndim, long
*dsize,
sizeof *out);
- /* Set the basic information we know so far. Note that we need a blank
- WCS structure allocated outside of WCSLIB, then WCSLIB will copy the
- contents. */
+ /* Set the basic information we know so far. */
out->next=NULL;
out->ndim=ndim;
out->type=type;
@@ -885,22 +882,20 @@ gal_data_has_blank(gal_data_t *data)
/* 'value' will only be read from one of these based on the
datatype. Which the caller assigned. If there is any problem, it is
their responsability, not this function's.*/
- void *A=data->array;
- size_t S=data->size;
- unsigned char *uc = A, *ucf = A+S;
- char *c = A, *cf = A+S;
- char **str = A, **strf = A+S;
- unsigned short *us = A, *usf = A+S;
- short *s = A, *sf = A+S;
- unsigned int *ui = A, *uif = A+S;
- int *in = A, *inf = A+S;
- unsigned long *ul = A, *ulf = A+S;
- long *l = A, *lf = A+S;
- LONGLONG *L = A, *Lf = A+S;
- float *f = A, *ff = A+S;
- double *d = A, *df = A+S;
- gsl_complex_float *cx = A, *cxf = A+S;
- gsl_complex *dcx = A, *dcxf = A+S;
+ unsigned char *uc = data->array, *ucf = data->array + data->size;
+ char *c = data->array, *cf = data->array + data->size;
+ char **str = data->array, **strf = data->array + data->size;
+ unsigned short *us = data->array, *usf = data->array + data->size;
+ short *s = data->array, *sf = data->array + data->size;
+ unsigned int *ui = data->array, *uif = data->array + data->size;
+ int *in = data->array, *inf = data->array + data->size;
+ unsigned long *ul = data->array, *ulf = data->array + data->size;
+ long *l = data->array, *lf = data->array + data->size;
+ LONGLONG *L = data->array, *Lf = data->array + data->size;
+ float *f = data->array, *ff = data->array + data->size;
+ double *d = data->array, *df = data->array + data->size;
+ gsl_complex_float *cx = data->array, *cxf = data->array + data->size;
+ gsl_complex *dcx = data->array, *dcxf = data->array + data->size;
/* Go over the pixels and check: */
@@ -1451,6 +1446,75 @@ gal_data_string_to_number(char *string)
+/*************************************************************
+ ************** Type minimum and maximums ***************
+ *************************************************************/
+void
+gal_data_type_min(int type, void *in)
+{
+ switch(type)
+ {
+ case GAL_DATA_TYPE_UCHAR: *(unsigned char *)in = 0; break;
+ case GAL_DATA_TYPE_CHAR: *(char *)in = CHAR_MIN; break;
+ case GAL_DATA_TYPE_USHORT: *(unsigned short *)in = 0; break;
+ case GAL_DATA_TYPE_SHORT: *(short *)in = SHRT_MIN; break;
+ case GAL_DATA_TYPE_UINT: *(unsigned int *)in = 0; break;
+ case GAL_DATA_TYPE_INT: *(int *)in = INT_MIN; break;
+ case GAL_DATA_TYPE_ULONG: *(unsigned long *)in = 0; break;
+ case GAL_DATA_TYPE_LONG: *(long *)in = LONG_MIN; break;
+ case GAL_DATA_TYPE_LONGLONG: *(LONGLONG *)in = LONGLONG_MIN; break;
+ case GAL_DATA_TYPE_FLOAT: *(float *)in = -FLT_MAX; break;
+ case GAL_DATA_TYPE_DOUBLE: *(double *)in = -DBL_MAX; break;
+ default:
+ error(EXIT_FAILURE, 0, "type code %d not recognized in "
+ "`gal_data_type_min'", type);
+ }
+}
+
+
+
+
+
+void
+gal_data_type_max(int type, void *in)
+{
+ switch(type)
+ {
+ case GAL_DATA_TYPE_UCHAR: *(unsigned char *)in = UCHAR_MAX; break;
+ case GAL_DATA_TYPE_CHAR: *(char *)in = CHAR_MAX; break;
+ case GAL_DATA_TYPE_USHORT: *(unsigned short *)in = USHRT_MAX; break;
+ case GAL_DATA_TYPE_SHORT: *(short *)in = SHRT_MAX; break;
+ case GAL_DATA_TYPE_UINT: *(unsigned int *)in = UINT_MAX; break;
+ case GAL_DATA_TYPE_INT: *(int *)in = INT_MAX; break;
+ case GAL_DATA_TYPE_ULONG: *(unsigned long *)in = ULONG_MAX; break;
+ case GAL_DATA_TYPE_LONG: *(long *)in = LONG_MAX; break;
+ case GAL_DATA_TYPE_LONGLONG: *(LONGLONG *)in = LONGLONG_MAX; break;
+ case GAL_DATA_TYPE_FLOAT: *(float *)in = FLT_MAX; break;
+ case GAL_DATA_TYPE_DOUBLE: *(double *)in = DBL_MAX; break;
+ default:
+ error(EXIT_FAILURE, 0, "type code %d not recognized in "
+ "`gal_data_type_min'", type);
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*************************************************************
************** Arithmetic operations ***************
@@ -1491,8 +1555,8 @@ gal_data_operator_string(int operator)
case GAL_DATA_OPERATOR_LOG: return "log";
case GAL_DATA_OPERATOR_LOG10: return "log10";
- case GAL_DATA_OPERATOR_MINVAL: return "minval";
- case GAL_DATA_OPERATOR_MAXVAL: return "maxval";
+ case GAL_DATA_OPERATOR_MINVAL: return "minvalue";
+ case GAL_DATA_OPERATOR_MAXVAL: return "maxvalue";
case GAL_DATA_OPERATOR_MIN: return "min";
case GAL_DATA_OPERATOR_MAX: return "max";
case GAL_DATA_OPERATOR_AVERAGE: return "average";
@@ -1537,6 +1601,7 @@ gal_data_arithmetic(int operator, unsigned char flags,
...)
/* Depending on the operator do the job: */
switch(operator)
{
+
/* Binary operators with any data type. */
case GAL_DATA_OPERATOR_PLUS:
case GAL_DATA_OPERATOR_MINUS:
@@ -1574,12 +1639,15 @@ gal_data_arithmetic(int operator, unsigned char flags,
...)
out=d1;
break;
+
/* Unary function operators. */
case GAL_DATA_OPERATOR_SQRT:
case GAL_DATA_OPERATOR_LOG:
case GAL_DATA_OPERATOR_LOG10:
+ case GAL_DATA_OPERATOR_MINVAL:
+ case GAL_DATA_OPERATOR_MAXVAL:
d1 = va_arg(va, gal_data_t *);
- out=data_arithmetic_unary_function_f(operator, flags, d1);
+ out=data_arithmetic_unary_function(operator, flags, d1);
break;
case GAL_DATA_OPERATOR_ABS:
@@ -1587,13 +1655,15 @@ gal_data_arithmetic(int operator, unsigned char flags,
...)
out=data_arithmetic_abs(flags, d1);
break;
+
/* Binary function operators. */
case GAL_DATA_OPERATOR_POW:
d1 = va_arg(va, gal_data_t *);
d2 = va_arg(va, gal_data_t *);
- out=data_arithmetic_binary_function_f(operator, flags, d1, d2);
+ out=data_arithmetic_binary_function_flt(operator, flags, d1, d2);
break;
+
/* Binary operators that only work on integer types. */
case GAL_DATA_OPERATOR_BITAND:
case GAL_DATA_OPERATOR_BITOR:
@@ -1606,6 +1676,11 @@ gal_data_arithmetic(int operator, unsigned char flags,
...)
out=data_arithmetic_onlyint_binary(operator, flags, d1, d2);
break;
+ case GAL_DATA_OPERATOR_BITNOT:
+ d1 = va_arg(va, gal_data_t *);
+ out=data_arithmetic_bitwise_not(flags, d1);
+ break;
+
/* Conversion operators. */
case GAL_DATA_OPERATOR_TO_UCHAR:
@@ -1624,15 +1699,7 @@ gal_data_arithmetic(int operator, unsigned char flags,
...)
break;
-#if 0
- else if(!strcmp(operator, "minvalue")) findmin(p);
- else if(!strcmp(operator, "maxvalue")) findmax(p);
- else if(!strcmp(operator, "min")
- || !strcmp(operator, "max")
- || !strcmp(operator, "average")
- || !strcmp(operator, "median")) alloppixs(p, operator);
-#endif
-
+ /* When operator is not recognized. */
default:
error(EXIT_FAILURE, 0, "the argument \"%d\" could not be "
"interpretted as an operator", operator);
diff --git a/lib/fits.c b/lib/fits.c
index 4fa4c23..b25e09b 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -1243,10 +1243,6 @@ gal_fits_read_img_hdu(char *filename, char *hdu, char
*maskname,
free(dsize);
- /* See if there is any blank pixels in the image (necessary for CFITSIO). */
- anyblank=gal_data_has_blank(img);
-
-
/* Read the image into the allocated array: */
fits_read_pix(fptr, gal_fits_type_to_datatype(type), fpixel,
img->size, blank, img->array, &anyblank, &status);
diff --git a/lib/gnuastro/data.h b/lib/gnuastro/data.h
index 699c219..74e5939 100644
--- a/lib/gnuastro/data.h
+++ b/lib/gnuastro/data.h
@@ -129,14 +129,7 @@ enum gal_data_alltypes
-/* Operators not yet implemented in `gal_data_arithmetic':
- GAL_DATA_OPERATOR_MINVAL
- GAL_DATA_OPERATOR_MAXVAL
- GAL_DATA_OPERATOR_MIN
- GAL_DATA_OPERATOR_MAX
- GAL_DATA_OPERATOR_AVERAGE
- GAL_DATA_OPERATOR_MEDIAN
-*/
+
enum gal_data_operators
{
GAL_DATA_OPERATOR_PLUS, /* + */
@@ -317,6 +310,19 @@ gal_data_string_to_number(char *string);
/*************************************************************
+ ************** Type minimum and maximums ***************
+ *************************************************************/
+void
+gal_data_type_min(int type, void *in);
+
+void
+gal_data_type_max(int type, void *in);
+
+
+
+
+
+/*************************************************************
************** Arithmetic ***************
*************************************************************/
char *
- [gnuastro-commits] master 531c263 008/125: Operators treated as macros, not string, (continued)
- [gnuastro-commits] master 531c263 008/125: Operators treated as macros, not string, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ff9258a 006/125: Arithmetic with internal type conversion, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 5336d5c 024/125: Small but important corrections, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c2fcb3e 020/125: Absolute value operator in gal_data_arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master fdb6183 019/125: Where operator implemented in gal_data_arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 493bc6f 001/125: Defined new gnuastro/data.h header, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c6462d1 016/125: Type conversion operators in Arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c10c4be 002/125: Moved type code and alloc functions into data.h, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master a4c5b9d 012/125: Binary operator arithmetic works on uncompiled types, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ad2810d 029/125: Work started on getting text table information, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master bc57ade 021/125: Minimum and maximum value operators implemented,
Mohammad Akhlaghi <=
- [gnuastro-commits] master 2dea9a7 011/125: All binary operator types set at configure time, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ff0b76d 018/125: New Data types section in book, bitwise not added, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c62b01e 031/125: Corrected incrementation issue with and and or operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0a32a82 027/125: Any number of searched columns from FITS are read, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master d0aa78e 005/125: Arithmetic operation on data structures in library, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0ad0906 014/125: Bitwise operators available in arithmetic operations, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 3ad83a4 010/125: data-arithmetic and data-copy separated from data.c, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 6c6382a 013/125: Use of function instead of macros for binary operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ce73959 030/125: Reading FITS keywords into linked list not array, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master e0e8679 017/125: Removed `anyblank' from datastructure, several new operators, Mohammad Akhlaghi, 2017/04/23