From fc8956b08ce1ab1f1aee63dfcb63b57f181309fc Mon Sep 17 00:00:00 2001 From: pnenzi Date: Fri, 23 Nov 2001 18:01:38 +0000 Subject: [PATCH] Added min, max and d(iff) to vectors from code submitted by Routoure. --- src/frontend/parse.c | 3 + src/include/fteext.h | 5 ++ src/maths/cmaths/cmath2.c | 132 +++++++++++++++++++++++++++++++++++++- src/maths/cmaths/cmath2.h | 6 ++ 4 files changed, 144 insertions(+), 2 deletions(-) diff --git a/src/frontend/parse.c b/src/frontend/parse.c index d9c9f7e4a..d6eeccd4b 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -598,6 +598,9 @@ struct func ft_funcs[] = { { "vector", cx_vector } , { "unitvec", cx_unitvec } , { "length", cx_length } , + { "min", cx_min } , + { "max", cx_max } , + { "d", cx_d } , #if 0 /* These functions have been temporarily been disabled. See their definitions for the reason. */ diff --git a/src/include/fteext.h b/src/include/fteext.h index a2f12760d..64d0864bb 100644 --- a/src/include/fteext.h +++ b/src/include/fteext.h @@ -103,6 +103,11 @@ extern void *cx_mean(void *, short int , int , int *, short int *); extern void *cx_length(void *, short int , int , int *, short int *); extern void *cx_vector(void *, short int , int , int *, short int *); extern void *cx_unitvec(void *, short int , int , int *, short int *); + +/* Routoure JM : somme useful functions */ +extern void *cx_min(void *, short int , int , int *, short int *); +extern void *cx_max(void *, short int , int , int *, short int *); +extern void *cx_d(void *, short int , int , int *, short int *); extern void *cx_plus(void *, void *, short int , short int , int ); extern void *cx_minus(void *, void *, short int , short int , int ); diff --git a/src/maths/cmaths/cmath2.c b/src/maths/cmaths/cmath2.c index 18a3c7824..26c7c982d 100644 --- a/src/maths/cmaths/cmath2.c +++ b/src/maths/cmaths/cmath2.c @@ -106,7 +106,7 @@ cx_atan(void *data, short int type, int length, int *newlength, short int *newty double -cx_max(void *data, short int type, int length) +cx_max_local(void *data, short int type, int length) { double largest = 0.0; @@ -135,7 +135,7 @@ cx_norm(void *data, short int type, int length, int *newlength, short int *newty { double largest = 0.0; - largest = cx_max(data, type, length); + largest = cx_max_local(data, type, length); if (largest == 0.0) { fprintf(cp_err, "Error: can't normalize a 0 vector\n"); return (NULL); @@ -521,3 +521,131 @@ cx_mod(void *data1, void *data2, short int datatype1, short int datatype2, int l } } + +/* Routoure JM : Compute the max of a vector. */ + +void * +cx_max(void *data, short int type, int length, int *newlength, short int *newtype) +{ + *newlength = 1; + /* test if length >0 et affiche un message d'erreur */ + rcheck(length > 0, "mean"); + if (type == VF_REAL) { + double largest=0.0; + double *d; + double *dd = (double *) data; + int i; + + d = alloc_d(1); + *newtype = VF_REAL; + largest=dd[0]; + for (i = 1; i < length; i++) + if (dd[i]>largest) largest=dd[i]; + *d=largest; + return ((void *) d); + } else { + double largest_real=0.0; + double largest_complex=0.0; + complex *c; + complex *cc = (complex *) data; + int i; + + c = alloc_c(1); + *newtype = VF_COMPLEX; + largest_real=realpart(cc); + largest_complex=imagpart(cc); + for (i = 0; i < length; i++) { + if (realpart(cc + i)>largest_real) largest_real=realpart(cc + i); + if (imagpart(cc + i)>largest_complex) largest_complex=imagpart(cc + i); + } + realpart(c) = largest_real; + imagpart(c) = largest_complex; + return ((void *) c); + } +} +/* Routoure JM : Compute the min of a vector. */ + +void * +cx_min(void *data, short int type, int length, int *newlength, short int *newtype) +{ + *newlength = 1; + /* test if length >0 et affiche un message d'erreur */ + rcheck(length > 0, "mean"); + if (type == VF_REAL) { + double smallest; + double *d; + double *dd = (double *) data; + int i; + + d = alloc_d(1); + *newtype = VF_REAL; + smallest=dd[0]; + for (i = 1; i < length; i++) + if (dd[i]0 et affiche un message d'erreur */ + rcheck(length > 0, "deriv"); + if (type == VF_REAL) { + double *d; + double *dd = (double *) data; + int i; + + d = alloc_d(length); + *newtype = VF_REAL; + d[0]=dd[1]-dd[0]; + d[length-1]=dd[length-1]-dd[length-2]; + for (i = 1; i < length-1; i++) + d[i]=dd[i+1]-dd[i-1]; + + return ((void *) d); + } else { + + complex *c; + complex *cc = (complex *) data; + int i; + + c = alloc_c(length); + *newtype = VF_COMPLEX; + realpart(c)=realpart(cc+1)-realpart(cc); + imagpart(c)=imagpart(cc+1)-imagpart(cc); + realpart(c+length-1)=realpart(cc+length-1)-realpart(cc+length-2); + imagpart(c+length-1)=imagpart(cc+length-1)-imagpart(cc+length-2); + + + for (i = 1; i < (length-1); i++) { + realpart(c+i)=realpart(cc+i+1)-realpart(cc+i-1); + imagpart(c+i)=imagpart(cc+i+1)-imagpart(cc+i-1); + + } + return ((void *) c); + } +} diff --git a/src/maths/cmaths/cmath2.h b/src/maths/cmaths/cmath2.h index 1be23e970..16cdf668f 100644 --- a/src/maths/cmaths/cmath2.h +++ b/src/maths/cmaths/cmath2.h @@ -20,6 +20,12 @@ void * cx_plus(void *data1, void *data2, short int datatype1, short int datatype void * cx_minus(void *data1, void *data2, short int datatype1, short int datatype2, int length); void * cx_times(void *data1, void *data2, short int datatype1, short int datatype2, int length); void * cx_mod(void *data1, void *data2, short int datatype1, short int datatype2, int length); +void * cx_max(void *data, short int type, int length, int *newlength, short int *newtype); +void * cx_min(void *data, short int type, int length, int *newlength, short int *newtype); +void * cx_d(void *data, short int type, int length, int *newlength, short int *newtype); #endif + + +