New special value COUNT which allows calculations based on the position of a
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Fri, 11 Apr 2003 19:43:44 +0000 (19:43 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Fri, 11 Apr 2003 19:43:44 +0000 (19:43 +0000)
value within a data set. Bug fix in rrd_rpncalc.c. PREV returned erroneus
value for the second value. Bug fix in rrd_restore.c. Bug causing seek error
when accesing an RRD restored from an xml that holds an RRD version <3.
--  Ruben Justo <ruben@ainek.com>

git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@199 a5681a0c-68f1-0310-ab6d-d61299d08faa

doc/rrdcreate.pod
doc/rrdgraph-old.pod
doc/rrdgraph_rpn.src
src/rrd_open.c
src/rrd_restore.c
src/rrd_rpncalc.c
src/rrd_rpncalc.h
src/rrd_tool.c

index 7a327f8..d516ab4 100644 (file)
@@ -154,7 +154,7 @@ I<rpn-expression> defines the formula used to compute the PDPs of a COMPUTE
 data source from other data sources in the same <RRD>. It is similar to defining
 a B<CDEF> argument for the graph command. Please refer to that manual page
 for a list and description of RPN operations supported. For
-COMPUTE data sources, the following RPN operations are not supported: PREV,
+COMPUTE data sources, the following RPN operations are not supported: COUNT, PREV,
 TIME, and LTIME. In addition, in defining the RPN expression, the COMPUTE
 data source may only refer to the names of data source listed previously
 in the create command. This is similar to the restriction that B<CDEF>s must
index 6d34782..ef730c4 100644 (file)
@@ -360,6 +360,13 @@ Push I<*UNKNOWN*> if its at the first value of a data set or otherwise
 the value of this CDEF at the previous time step. This allows you to
 perform calculations across the data.
 
+=item COUNT
+
+Pushes the number 1 if it is at the first value of the data set, the 
+number 2 if it is at the second, and so on. This special value, allows 
+you to make calculations based on the position of the value within 
+the data set.
+
 =item INF, NEGINF
 
 Push a positive or negative infinite (oo) value onto the stack. When
index a8c4b11..f9ac7fe 100644 (file)
@@ -130,6 +130,13 @@ set or otherwise the result of vname variable at the previous time
 step. This allows you to do calculations across the data.  This
 function cannot be used in B<VDEF> instructions.
 
+B<COUNT>
+
+Pushes the number 1 if this is the first value of the data set, the 
+number 2 if it is the second, and so on. This special value, allows 
+you to make calculations based on the position of the value within 
+the data set. This function cannot be used in B<VDEF> instructions.
+
 Z<>
 
 =item Time
index f345e28..9ce17a3 100644 (file)
@@ -5,6 +5,13 @@
  *****************************************************************************
  * $Id$
  * $Log$
+ * Revision 1.8  2003/04/11 19:43:44  oetiker
+ * New special value COUNT which allows calculations based on the position of a
+ * value within a data set. Bug fix in rrd_rpncalc.c. PREV returned erroneus
+ * value for the second value. Bug fix in rrd_restore.c. Bug causing seek error
+ * when accesing an RRD restored from an xml that holds an RRD version <3.
+ * --  Ruben Justo <ruben@ainek.com>
+ *
  * Revision 1.7  2003/03/31 21:22:12  oetiker
  * enables RRDtool updates with microsecond or in case of windows millisecond
  * precision. This is needed to reduce time measurement error when archive step
@@ -129,7 +136,8 @@ rrd_open(char *file_name, FILE **in_file, rrd_t *rrd, int rdwr)
                fclose(*in_file); 
                return (-1);
            }
-            fread(&rrd->live_head->last_up, sizeof(long), 1, *in_file); 
+               fread(&rrd->live_head->last_up, sizeof(long), 1, *in_file); 
+               rrd->live_head->last_up_usec = 0;
     }
     else {
            MYFREAD(rrd->live_head, live_head_t, 1)
index a0ef635..150f1ee 100644 (file)
@@ -423,8 +423,12 @@ rrd_write(char *file_name, rrd_t *rrd)
 
     fwrite(rrd->rra_def,
           sizeof(rra_def_t), rrd->stat_head->rra_cnt, rrd_file);
-    
-    fwrite(rrd->live_head, sizeof(live_head_t),1, rrd_file);
+
+        /* maybe the xml hold an old formatted rrd */
+    if (atoi(rrd->stat_head->version) < 3)
+      fwrite(&(rrd->live_head->last_up), sizeof(long),1, rrd_file);
+    else
+      fwrite(rrd->live_head, sizeof(live_head_t),1, rrd_file);
 
     fwrite( rrd->pdp_prep, sizeof(pdp_prep_t),rrd->stat_head->ds_cnt,rrd_file);
     
index 9bb35d2..65748cc 100644 (file)
@@ -196,10 +196,10 @@ void parseCDEF_DS(char *def,rrd_t *rrd, int ds_idx)
      * occur too often. */
     for (i = 0; rpnp[i].op != OP_END; i++) {
         if (rpnp[i].op == OP_TIME || rpnp[i].op == OP_LTIME || 
-            rpnp[i].op == OP_PREV)
+            rpnp[i].op == OP_PREV || rpnp[i].op == OP_COUNT)
         {
             rrd_set_error(
-                "operators time, ltime and prev not supported with DS COMPUTE");
+                "operators time, ltime, prev and count not supported with DS COMPUTE");
             free(rpnp);
             return;
         }
@@ -313,6 +313,7 @@ rpn_parse(void *key_hash,char *expr,long (*lookup)(void *,char*)){
        match_op(OP_UN,UN)
        match_op(OP_NEGINF,NEGINF)
        match_op(OP_NE,NE)
+       match_op(OP_COUNT,COUNT)
          match_op_param(OP_PREV_OTHER,PREV)
        match_op(OP_PREV,PREV)
        match_op(OP_INF,INF)
@@ -428,15 +429,18 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx,
                    }
                }
                break;
+           case OP_COUNT:
+               rpnstack -> s[++stptr] = (output_idx+1); /* Note: Counter starts at 1 */
+               break;
            case OP_PREV:
-               if ((output_idx-1) <= 0) {
+               if ((output_idx) <= 0) {
                    rpnstack -> s[++stptr] = DNAN;
                } else {
                    rpnstack -> s[++stptr] = output[output_idx-1];
                }
                break;
        case OP_PREV_OTHER:
-         if ((output_idx-1) <= 0) {
+         if ((output_idx) <= 0) {
                rpnstack -> s[++stptr] = DNAN;
          } else {
                rpnstack -> s[++stptr] = rpnp[rpnp[rpi].ptr].data[output_idx-1];
index a4e7c65..796aa7d 100644 (file)
@@ -10,7 +10,7 @@
  * 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. */
-enum op_en {OP_NUMBER=0,OP_VARIABLE,OP_INF,OP_PREV,OP_NEGINF,
+enum op_en {OP_NUMBER=0,OP_VARIABLE,OP_INF,OP_PREV,OP_COUNT,OP_NEGINF,
            OP_UNKN,OP_NOW,OP_TIME,OP_ADD,OP_MOD,OP_SUB,OP_MUL,
            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,
index 0378940..2cb4494 100644 (file)
@@ -23,7 +23,11 @@ void PrintUsage(char *cmd)
 
     char help_main[] =
           "RRDtool 1.1.x  Copyright 1997-2003 by Tobias Oetiker <tobi@oetiker.ch>\n"
+#ifndef WIN32
            "               Compiled " MAKE_TIMESTAMP "\n\n"
+#else
+           "               Compiled " __DATE__ " " __TIME__ "\n\n"
+#endif          
           "Usage: rrdtool [options] command command_options\n\n";
 
     char help_list[] =