Code

Added the ATAN function. This is being used to convert a DS for each vector component...
[rrdtool-all.git] / program / doc / rrdgraph_rpn.src
1 =include name
3 =head1 SYNOPSYS
5 I<E<lt>RPN expressionE<gt>> := 
6 I<E<lt>vnameE<gt>>|I<E<lt>operatorE<gt>>|I<E<lt>valueE<gt>>
7 [ , I<E<lt>RPN expressionE<gt>>]
9 =head1 DESCRIPTION
11 If you have ever used a traditional HP calculator you already know
12 B<RPN>. The idea behind B<RPN> is that you have a stack and push
13 your data onto this stack. Whenever you execute an operation, it
14 takes as many elements from the stack as needed. Pushing is done
15 implicit so whenever you specify a number or a variable, it gets
16 pushed automatically.
18 At the end of the calculation there should be one and exactly one
19 value left on the stack.  This is the outcome of the function and
20 this is what is put into the I<vname>.  For B<CDEF> instructions,
21 the stack is processed for each data point on the graph. B<VDEF>
22 instructions work on an entire data set in one run.
24 Example: C<CDEF:mydatabits=mydata,8,*>
26 This means:  push variable I<mydata>, push the number 8, execute
27 the operator I<+>. The operator needs two elements and uses those
28 to return one value.  This value is then stored in I<mydatabits>.
29 As you may have guessed, this instruction means nothing more than
30 I<mydatabits = mydata * 8>.  The real power of B<RPN> lies in the
31 fact that it is always clear in which order to process the input.
32 For expressions like C<a = b + 3 * 5> you need to multiply 3 with
33 5 first before you add I<b> to get I<a>. However, with parentheses
34 you could change this order: C<a = (b + 3) * 5>. In B<RPN>, you
35 would do C<a = b, 3, +, 5, *> and need no parentheses.
37 =head1 OPERATORS
39 =over 4
41 =item Boolean operators
43 B<LT, LE, GT, GE, EQ, NE>
45 Pop two elements from the stack, compare them for the selected condition
46 and return 1 for true or 0 for false. Comparing an I<unknown> or an
47 I<infinite> value will always result in 0 (false).
49 B<UN, ISINF>
51 Pop one element from the stack, compare this to I<unknown> respectively
52 to I<positive or negative infinity>. Returns 1 for true or 0 for false.
54 B<IF>
56 Pops three elements from the stack.  If the last element is 0 (false),
57 the first value is pushed back onto the stack, otherwise the second
58 popped value is pushed back. This does, indeed, mean that any value
59 other than 0 is considered true.
60 I<Note: Should this change? It should IMHO as all the other functions
61 would return unknown if A,B or C were unknown>
63 Example: C<A,B,C,IF> should be read as C<if (A) then (B) else (C)>
65 Z<>
67 =item Comparing values
69 B<MIN, MAX> 
71 Pops two elements from the stack and returns the lesser or larger.
72 The two numbers shouldn't be I<infinite> or I<unknown>, if they are
73 that value is pushed back onto the stack as the result.
75 B<LIMIT>
77 Pops two elements from the stack and uses them to define a range.
78 Then it pops another element and if it falls inside the range, it
79 is pushed back. If not, an I<unknown> is pushed.
81 The range defined includes the two boundaries (so: a number equal
82 to one of the boundaries will be pushed back). If any of the three
83 numbers involved is either I<unknown> or I<infinite> this function
84 will always return an I<unknown>
86 Example: C<CDEF:a=alpha,0,100,LIMIT> will return I<unknown> if
87 alpha is lower than 0 or if it is higher than 100.
89 Z<>
91 =item Arithmetics
93 B<+, -, *, /, %>
95 Add, subtract, multiply, divide, modulo
97 B<SIN, COS, LOG, EXP>
99 Sine, cosine (input in radians), log, exp (natural logarithm)
101 B<ATAN>
103 Arctangent. Output in radians.
105 B<FLOOR, CEIL>
107 Round down,up to the nearest integer
109 Z<>
111 =item Special values
113 B<UNKN>
115 Pushes an unknown value on the stack
117 B<INF, NEGINF>
119 Pushes a positive or negative infinite value on the stack. When
120 such a value is graphed, it appears at the top or bottom of the
121 graph, no matter what the actual value on the y-axis is.
123 B<PREV>
125 Pushes an I<unknown> value if this is the first value of a data
126 set or otherwise the result of this B<CDEF> at the previous time
127 step. This allows you to do calculations across the data.  This
128 function cannot be used in B<VDEF> instructions.
130 B<PREV(vname)>
132 Pushes an I<unknown> value if this is the first value of a data
133 set or otherwise the result of vname variable at the previous time
134 step. This allows you to do calculations across the data.  This
135 function cannot be used in B<VDEF> instructions.
137 B<COUNT>
139 Pushes the number 1 if this is the first value of the data set, the 
140 number 2 if it is the second, and so on. This special value, allows 
141 you to make calculations based on the position of the value within 
142 the data set. This function cannot be used in B<VDEF> instructions.
144 Z<>
146 =item Time
148 Time inside RRDtool is measured in seconds since the epoch. This
149 epoch is defined to be S<C<Thu Jan  1 00:00:00 UTC 1970>>.
151 Z<>
153 =over 4
155 =item NOW
157 Pushes the current time on the stack.
159 Z<>
161 =item TIME
163 Pushes the time the currently processed value was taken onto the stack.
165 Z<>
167 =item LTIME
169 Takes the time as defined by B<TIME>, applies the time zone offset
170 valid at that time including daylight saving time if your OS supports
171 it, and pushes the result on the stack.  There is an elaborate example
172 in the examples section on how to use this.
174 =back
176 For B<VDEF> operations, B<TIME> and B<LTIME> have a different meaning
177 I<not yet implemented>.  As the B<VDEF> statement does not work per
178 value but rather on a complete time series, there is no such thing as
179 the currently processed value.  However, if you have used an operator
180 that returned a time component and would like to have this available
181 in the value component in stead (so you can use it as a number), you
182 can use B<TIME> or B<LTIME> for that.
184 Z<>
186 =item Processing the stack directly
188 B<DUP, POP, EXC>
190 Duplicate the top element, remove the top element, exchange the two
191 top elements.
193 Z<>
195 =item Selecting characteristics
197 These operators work only on B<VDEF> statements.
198 I<We can make most of them work at DEF and CDEF statements. If we do
199 so, we have a moving (not rolling!) average, max,min etcetera>
201 Z<>
203 =over 4
205 =item MAXIMUM, MINIMUM, AVERAGE
207 Return the corresponding value, MAXIMUM and MINIMUM also return
208 the first occurance of that value in the time component.
210 Example: C<VDEF:avg=mydata,AVERAGE>
212 Z<>
214 =item LAST, FIRST
216 Return the last,first value including its time.  The time for
217 FIRST is actually the start of the corresponding interval, where
218 LASTs time component returns the end of the corresponding interval.
220 Example: C<VDEF:first=mydata,FIRST>
222 Z<>
224 =item TOTAL
226 Returns the rate from each defined timeslot multiplied with the
227 step size.  This can for instance return total bytes transfered
228 when you have logged bytes per second. The time component returns
229 the amount of seconds 
231 Example: C<VDEF:total=mydata,TOTAL>
233 Z<>
235 =item PERCENT
237 Should follow a B<DEF> or B<CDEF> I<vname>. This I<vname> is popped,
238 another number is popped which is a certain percentage (0..100). The
239 data set is then sorted and the value returned is chosen such that
240 I<percentage> percent of the values is lower or equal than the result.
241 I<Unknown> values are considered lower than any finite number for this
242 purpose so if this operator returns an I<unknown> you have quite a lot
243 of them in your data.  B<Inf>inite numbers are lesser, or more, than the
244 finite numbers and are always more than the I<Unknown> numbers.
246 Example: C<VDEF:perc95=mydata,95,PERCENT>
248 =back
250 =back
252 =include see_also