Code

fix handling of PREV(x) command
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 7 May 2005 10:34:48 +0000 (10:34 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 7 May 2005 10:34:48 +0000 (10:34 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@497 a5681a0c-68f1-0310-ab6d-d61299d08faa

src/rrd_graph.c
src/rrd_rpncalc.c

index cbf947dc1ac631182171adeebb09d37d5538e763..b01bd3a365c2d35547cd0fb731fa174371696634 100644 (file)
@@ -886,26 +886,29 @@ data_calc( image_desc_t *im){
                 *   and the resulting number is the step size for the
                 *   resulting data source.
                 */
-               for(rpi=0;im->gdes[gdi].rpnp[rpi].op != OP_END;rpi++){
-               if(im->gdes[gdi].rpnp[rpi].op == OP_VARIABLE ||
-                  im->gdes[gdi].rpnp[rpi].op == OP_PREV_OTHER){
-                       long ptr = im->gdes[gdi].rpnp[rpi].ptr;
-                       if (im->gdes[ptr].ds_cnt == 0) {
+               for(rpi=0;im->gdes[gdi].rpnp[rpi].op != OP_END;rpi++){
+                   if(im->gdes[gdi].rpnp[rpi].op == OP_VARIABLE  ||
+                       im->gdes[gdi].rpnp[rpi].op == OP_PREV_OTHER){
+                       long ptr = im->gdes[gdi].rpnp[rpi].ptr;
+                       if (im->gdes[ptr].ds_cnt == 0) { /* this is a VDEF data source */
 #if 0
-                       printf("DEBUG: inside CDEF '%s' processing VDEF '%s'\n",
-       im->gdes[gdi].vname,
-       im->gdes[ptr].vname);
-                       printf("DEBUG: value from vdef is %f\n",im->gdes[ptr].vf.val);
+                           printf("DEBUG: inside CDEF '%s' processing VDEF '%s'\n",
+                              im->gdes[gdi].vname,
+                              im->gdes[ptr].vname);
+                           printf("DEBUG: value from vdef is %f\n",im->gdes[ptr].vf.val);
 #endif
                            im->gdes[gdi].rpnp[rpi].val = im->gdes[ptr].vf.val;
                            im->gdes[gdi].rpnp[rpi].op  = OP_NUMBER;
-                       } else {
-                       if ((steparray =
+                       } else { /* normal variables and PREF(variables) */
+
+                           /* add one entry to the array that keeps track of the step sizes of the
+                            * data sources going into the CDEF. */
+                           if ((steparray =
                                 rrd_realloc(steparray,
                                                         (++stepcnt+1)*sizeof(*steparray)))==NULL){
-                               rrd_set_error("realloc steparray");
-                               rpnstack_free(&rpnstack);
-                               return -1;
+                                rrd_set_error("realloc steparray");
+                                rpnstack_free(&rpnstack);
+                                return -1;
                            };
 
                            steparray[stepcnt-1] = im->gdes[ptr].step;
@@ -915,6 +918,7 @@ data_calc( image_desc_t *im){
                             * to the earliest endpoint of any of the
                             * rras involved (ptr)
                             */
+
                            if(im->gdes[gdi].start < im->gdes[ptr].start)
                                im->gdes[gdi].start = im->gdes[ptr].start;
 
@@ -927,8 +931,8 @@ data_calc( image_desc_t *im){
                             * further save step size and data source
                             * count of this rra
                             */ 
-                            im->gdes[gdi].rpnp[rpi].data  im->gdes[ptr].data + im->gdes[ptr].ds;
-                           im->gdes[gdi].rpnp[rpi].step = im->gdes[ptr].step;
+                            im->gdes[gdi].rpnp[rpi].data   = im->gdes[ptr].data + im->gdes[ptr].ds;
+                           im->gdes[gdi].rpnp[rpi].step   = im->gdes[ptr].step;
                            im->gdes[gdi].rpnp[rpi].ds_cnt = im->gdes[ptr].ds_cnt;
 
                            /* backoff the *.data ptr; this is done so
@@ -941,9 +945,9 @@ data_calc( image_desc_t *im){
 
                 /* move the data pointers to the correct period */
                 for(rpi=0;im->gdes[gdi].rpnp[rpi].op != OP_END;rpi++){
-               if(im->gdes[gdi].rpnp[rpi].op == OP_VARIABLE ||
-                  im->gdes[gdi].rpnp[rpi].op == OP_PREV_OTHER){
-                        long ptr = im->gdes[gdi].rpnp[rpi].ptr;
+                   if(im->gdes[gdi].rpnp[rpi].op == OP_VARIABLE ||
+                       im->gdes[gdi].rpnp[rpi].op == OP_PREV_OTHER){
+                       long ptr  = im->gdes[gdi].rpnp[rpi].ptr;
                        long diff = im->gdes[gdi].start - im->gdes[ptr].start;
 
                         if(diff > 0)
index 8639d398d805f937682ff571ccc99f7b03625114..e3784da335c73a09807d40c245a162c551bd0f91 100644 (file)
@@ -428,7 +428,8 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx,
                rpnstack -> s[++stptr] = rpnp[rpi].val;
                break;
            case OP_VARIABLE:
-               /* Sanity check: VDEFs shouldn't make it here */
+            case OP_PREV_OTHER:
+           /* Sanity check: VDEFs shouldn't make it here */
                if (rpnp[rpi].ds_cnt == 0) {
                    rrd_set_error("VDEF made it into rpn_calc... aborting");
                    return -1;
@@ -439,7 +440,16 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx,
                     * row in the rra (skip over non-relevant
                     * data sources)
                     */
-                   rpnstack -> s[++stptr] =  *(rpnp[rpi].data);
+                   if (rpnp[rpi].op == OP_VARIABLE) {
+                       rpnstack -> s[++stptr] =  *(rpnp[rpi].data);
+                   } else {
+                       if ((output_idx) <= 0) {
+                           rpnstack -> s[++stptr] = DNAN;
+                       } else {                            
+                           rpnstack -> s[++stptr] =  *(rpnp[rpi].data-rpnp[rpi].ds_cnt);
+                       }
+                      
+                   }              
                    if (data_idx % rpnp[rpi].step == 0){
                        rpnp[rpi].data += rpnp[rpi].ds_cnt;
                    }
@@ -454,15 +464,8 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx,
                } else {
                    rpnstack -> s[++stptr] = output[output_idx-1];
                }
-               break;
-       case OP_PREV_OTHER:
-         if ((output_idx) <= 0) {
-               rpnstack -> s[++stptr] = DNAN;
-         } else {
-               rpnstack -> s[++stptr] = rpnp[rpnp[rpi].ptr].data[output_idx-1];
-         }
-         break;
-           case OP_UNKN:
+               break;
+        case OP_UNKN:
                rpnstack -> s[++stptr] = DNAN; 
                break;
            case OP_INF: