From: oetiker Date: Tue, 4 May 2004 21:01:29 +0000 (+0000) Subject: Added the ATAN function. This is being used to convert a DS for each vector component... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2412c8211fbd8e6cb077a0785ab335416a7090fa;p=rrdtool.git Added the ATAN function. This is being used to convert a DS for each vector component of wind direction into a single direction for graphing. CDEF:avdir=yavg,xavg,/,ATAN,57.296,*,xavg,0,LT,180,0,IF,+,DUP,0,LT,360,0,IF,+ -- Daniel Shiels git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@247 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/doc/rrdgraph_rpn.src b/doc/rrdgraph_rpn.src index f9ac7fe..65f0917 100644 --- a/doc/rrdgraph_rpn.src +++ b/doc/rrdgraph_rpn.src @@ -98,6 +98,10 @@ B Sine, cosine (input in radians), log, exp (natural logarithm) +B + +Arctangent. Output in radians. + B Round down,up to the nearest integer diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index 65748cc..52d7a11 100644 --- a/src/rrd_rpncalc.c +++ b/src/rrd_rpncalc.c @@ -153,6 +153,7 @@ void rpn_compact2str(rpn_cdefds_t *rpnc,ds_def_t *ds_def,char **str) add_op(OP_NOW,NOW) add_op(OP_LTIME,LTIME) add_op(OP_TIME,TIME) + add_op(OP_ATAN,ATAN) #undef add_op } @@ -321,6 +322,7 @@ rpn_parse(void *key_hash,char *expr,long (*lookup)(void *,char*)){ match_op(OP_NOW,NOW) match_op(OP_LTIME,LTIME) match_op(OP_TIME,TIME) + match_op(OP_ATAN,ATAN) #undef match_op @@ -501,6 +503,10 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx, stackunderflow(0); rpnstack -> s[stptr] = sin(rpnstack -> s[stptr]); break; + case OP_ATAN: + stackunderflow(0); + rpnstack -> s[stptr] = atan(rpnstack -> s[stptr]); + break; case OP_COS: stackunderflow(0); rpnstack -> s[stptr] = cos(rpnstack -> s[stptr]); diff --git a/src/rrd_rpncalc.h b/src/rrd_rpncalc.h index 2aa6dfb..fe456f2 100644 --- a/src/rrd_rpncalc.h +++ b/src/rrd_rpncalc.h @@ -6,7 +6,7 @@ #ifndef _RRD_RPNCALC_H #define _RRD_RPNCALC_H -/* WARNING: if new operators are added, they MUST be added after OP_END. +/* WARNING: if new operators are added, they MUST be added at the very end of the list. * This is because COMPUTE (CDEF) DS store OP nodes by number (name is not * an option due to limited par array size). OP nodes must have the same * numeric values, otherwise the stored numbers will mean something different. */ @@ -15,7 +15,7 @@ enum op_en {OP_NUMBER=0,OP_VARIABLE,OP_INF,OP_PREV,OP_NEGINF, OP_DIV,OP_SIN, OP_DUP, OP_EXC, OP_POP, OP_COS,OP_LOG,OP_EXP,OP_LT,OP_LE,OP_GT,OP_GE,OP_EQ,OP_IF, OP_MIN,OP_MAX,OP_LIMIT, OP_FLOOR, OP_CEIL, - OP_UN,OP_END,OP_LTIME,OP_NE,OP_ISINF,OP_PREV_OTHER,OP_COUNT}; + OP_UN,OP_END,OP_LTIME,OP_NE,OP_ISINF,OP_PREV_OTHER,OP_COUNT,OP_ATAN}; typedef struct rpnp_t { enum op_en op;