From 847ebfa49980b02f02d4ebdb6a10614073a7f77a Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (l)" <j.wuttke@fz-juelich.de>
Date: Sat, 4 Jan 2014 14:33:53 +0100
Subject: [PATCH] new command ofs

---
 pub/CHANGELOG        |  2 +-
 pub/src/commands.cpp |  1 +
 pub/src/opr.cpp      | 12 ++++++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/pub/CHANGELOG b/pub/CHANGELOG
index 094e89b5..739b6e8d 100644
--- a/pub/CHANGELOG
+++ b/pub/CHANGELOG
@@ -1,6 +1,6 @@
 Release 2.1.8f of
 
-- new commands ftvd (to read x-y-dy lines), oixyd
+- new commands ftvd (to read x-y-dy lines), oixyd, ofs
 - improved error message from convolution
 
 Release 2.1.8e of 19nov13, to be used with frida2libs-131120:
diff --git a/pub/src/commands.cpp b/pub/src/commands.cpp
index 8fa6d1a8..ea3b003f 100644
--- a/pub/src/commands.cpp
+++ b/pub/src/commands.cpp
@@ -503,6 +503,7 @@ bool fridaCommand( string cmd )
             "  opa      take absolute value\n"
             "  opc      copy from another curve\n"
             "  ofi      functional integrate\n"
+            "  ofs      summation up to current index\n"
             "  ofd      functional derivate\n"
             "  ofac     functional autocorrelate\n"
             "  oi       rank-reducing (""integral"") operations\n"
diff --git a/pub/src/opr.cpp b/pub/src/opr.cpp
index 8d467ce5..2158eb4b 100644
--- a/pub/src/opr.cpp
+++ b/pub/src/opr.cpp
@@ -675,6 +675,9 @@ void NOperate::Functional( const string& subcmd )
         if        ( subcmd=="i" ) { // integrate
             fout->yco.name = "Int d" + fin->xco.name + " " + fin->yco.name;
             fout->yco.unit = fin->xco.unit + " * " + fin->yco.unit;
+        } else if ( subcmd=="s" ) { // sum
+            fout->yco.name = "Sum_0^i " + fin->yco.name;
+            fout->yco.unit = fin->yco.unit;
         } else if ( subcmd=="d" ) { // derive
             fout->yco.name = "d" + fin->yco.name + " / d" + fin->xco.name;
             fout->yco.unit = fin->yco.unit + " / " + fin->xco.unit;
@@ -695,11 +698,16 @@ void NOperate::Functional( const string& subcmd )
                 sout->x = sin->x;
                 sout->y.resize( n );
                 sout->y[0] = 0;
-                for ( int i=1; i<n; ++i ) {
+                for ( int i=1; i<n; ++i )
                     sout->y[i] = sout->y[i-1] + 
                         (sin->x[i] - sin->x[i-1]) * 
                         (sin->y[i] + sin->y[i-1]) / 2;
-                }
+            } else if ( subcmd=="s" ) { // sum
+                sout->x = sin->x;
+                sout->y.resize( n );
+                sout->y[0] = sin->y[0];
+                for ( int i=1; i<n; ++i )
+                    sout->y[i] = sout->y[i-1] + sin->y[i];
             } else if ( subcmd=="d" ) { // derive
                 for( int i=0; i<n-1; ++i ){
                     double dx = sin->x[i+1] - sin->x[i];
-- 
GitLab