From 68dc241fed3bdf9565d73c230c2cd2ba5207128a Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Fri, 6 Nov 2015 17:39:21 +0100
Subject: [PATCH] another correction and another test for 'i' in position J or
 K

---
 pub/ftest/trace.f2t | 27 ++++++++++++++++++++++++---
 pub/lib/expr.cpp    |  8 ++++----
 pub/lib/expr.hpp    |  1 +
 pub/lib/node.cpp    | 14 ++++++++++++--
 pub/lib/node.hpp    |  4 ++++
 5 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/pub/ftest/trace.f2t b/pub/ftest/trace.f2t
index 36715423..43408499 100755
--- a/pub/ftest/trace.f2t
+++ b/pub/ftest/trace.f2t
@@ -2,9 +2,30 @@
 fm 3 3 h
 fc
 fc
-0:2 ox! k+j+i
-oy! x^2
+0:2 ox! i/10
+oy! 100*k+10*j+i
+0 oy y[,i,0]
 0 oy y[,i,i]
+0 oy y[i,0,0]
+0 oy y[i,i,0]
+0 oy y[i,0,i]
 0 oy y[i,i,i]
-0 oi sum[i,i]
+0 oy y[,j,0]
+0 oy y[,j,j]
+0 oy y[j,0,0]
+0 oy y[j,j,0]
+0 oy y[j,0,j]
+0 oy y[j,j,j]
+exit_unless(y[3,2,2]==20,"y[,i,0]")
+exit_unless(y[4,2,2]==22,"y[,i,i]")
+exit_unless(y[5,2,2]==200,"y[i,0,0]")
+exit_unless(y[6,2,2]==220,"y[i,i,0]")
+exit_unless(y[7,2,2]==202,"y[i,0,i]")
+exit_unless(y[8,2,2]==222,"y[i,i,i]")
+exit_unless(y[9,2,2]==20,"y[,j,0]")
+exit_unless(y[10,2,2]==22,"y[,j,j]")
+exit_unless(y[11,2,2]==200,"y[j,0,0]")
+exit_unless(y[12,2,2]==220,"y[j,j,0]")
+exit_unless(y[13,2,2]==202,"y[j,0,j]")
+exit_unless(y[14,2,2]==222,"y[j,j,j]")
 exit(0)
diff --git a/pub/lib/expr.cpp b/pub/lib/expr.cpp
index fe32f87d..96d3578c 100644
--- a/pub/lib/expr.cpp
+++ b/pub/lib/expr.cpp
@@ -149,10 +149,10 @@ int CRef2::get_j( const CContext& ctx, int nj ) const
     int j;
     if ( tj ) {
         RObj tmp = tj->tree_val( ctx );
-        RObjInt pj = PCAST<const CObjInt>(tmp);
-        if ( !pj )
+        RObjInt pi = PCAST<const CObjInt>(tmp);
+        if ( !pi )
             throw "index J=" + tj->tree_info() + "->" + tmp->to_s() + " is not integer";
-        j = pj->val;
+        j = pi->val;
     } else {
         j = ctx.j;
     }
@@ -188,7 +188,7 @@ string CRef3::ref_info() const
 {
     return "[" +
         ( tk ? tk->tree_info() : "K" ) + "," +
-        ( tj ? tj->tree_info() : "J" ) + ",";
+        ( tj ? tj->tree_info() : "J" ) + "," +
         ( ti ? ti->tree_info() : "I" ) + "]";
 }
 
diff --git a/pub/lib/expr.hpp b/pub/lib/expr.hpp
index 3c19f9ee..3be2e973 100644
--- a/pub/lib/expr.hpp
+++ b/pub/lib/expr.hpp
@@ -72,6 +72,7 @@ class CNode {
 
     virtual int npar() const { return 0; }
     virtual bool k_dependent() const { return false; }
+    virtual bool j_dependent() const { return false; }
     virtual bool i_dependent() const { return false; }
 
     virtual bool has_dummy() const { return false; } //!< does node depend on t ?
diff --git a/pub/lib/node.cpp b/pub/lib/node.cpp
index aacea8f8..18c5e071 100644
--- a/pub/lib/node.cpp
+++ b/pub/lib/node.cpp
@@ -55,6 +55,11 @@ bool CNodeWithArgs::k_dependent() const
     return std::any_of( arg.begin(), arg.end(), [](RNode a){ return a && a->k_dependent(); } );
 }
 
+bool CNodeWithArgs::j_dependent() const
+{
+    return std::any_of( arg.begin(), arg.end(), [](RNode a){ return a && a->j_dependent(); } );
+}
+
 bool CNodeWithArgs::i_dependent() const
 {
     return std::any_of( arg.begin(), arg.end(), [](RNode a){ return a && a->i_dependent(); } );
@@ -763,7 +768,7 @@ CCoord CNodeFile::node_coord( int _k ) const
     try {
         int k;
         if (ref->tk) {
-            if ( ref->tk->i_dependent() )
+            if ( ref->tk->i_dependent() || ref->tk->j_dependent() )
                 return CCoord( name()+ref->ref_info(), "" );
             CContext ctx( _k );
             k = ref->tk->tree_val_idx( ctx, "k" );
@@ -871,8 +876,13 @@ RObj CNodePoint::tree_val( const CContext& ctx ) const
             if ( ctx.nv<0 )
                 throw S("BUG: i-dependent K or J incompatible with unspecified return array length");
             PObjVecObj tmp( new CObjVecObj() );
+            CContext myctx(ctx);
+            myctx.dim = CContext::_1;
             for ( int i=0; i<ctx.nv; ++i ) {
-                tmp->v.push_back( tree_val_point( ctx, i ) );
+                myctx.i = i;
+                tmp->v.push_back
+                    ( tree_val_point
+                      ( myctx, PCAST<const CRef3>(ref)->ti->tree_val_idx( myctx, "i" ) ) );
             }
             return tmp->to_vecnum();
         } else if ( !(PCAST<const CRef3>(ref)->ti) || PCAST<const CRef3>(ref)->ti->i_dependent() ) {
diff --git a/pub/lib/node.hpp b/pub/lib/node.hpp
index 98cbbcfe..225d81fb 100644
--- a/pub/lib/node.hpp
+++ b/pub/lib/node.hpp
@@ -20,6 +20,7 @@ class CNodeWithArgs: public CNode {
     CNodeWithArgs( int _narg ) : narg(_narg) { arg.resize(narg); }
     int npar() const;
     bool k_dependent() const;
+    bool j_dependent() const;
     bool i_dependent() const;
     bool has_dummy() const;
     bool has_conv() const;
@@ -172,6 +173,7 @@ class CNodeIdxJ: public CNodeIdx {
     RObj tree_val( const CContext& ctx ) const;
     CCoord node_coord( int k ) const { return CCoord("j", ""); }
     string tree_info() const { return "j"; }
+    bool j_dependent() const { return true; }
 };
 
 
@@ -425,6 +427,7 @@ class CNodeMixin: public CNode {
     CNodeMixin( const RNode& _shift ) : shift(_shift) {}
     int npar() const { return shift->npar(); }
     bool k_dependent() const { return shift->k_dependent(); }
+    bool j_dependent() const { return shift->j_dependent(); }
     bool i_dependent() const { return shift->i_dependent(); }
     RObj tree_val( const CContext& ctx ) const;
     virtual RObj copy_theory( const CContext& ctx, double theshift ) const =0;
@@ -443,6 +446,7 @@ class CNodeConvBase: public CNodeMixin {
         : CNodeMixin( _shift ), theory(_theory) {}
     int npar() const { return std::max(shift->npar(), theory->npar()); }
     bool k_dependent() const { return theory->k_dependent() || shift->k_dependent(); }
+    bool j_dependent() const { return theory->j_dependent() || shift->j_dependent(); }
     bool i_dependent() const { return theory->i_dependent() || shift->i_dependent(); }
     bool has_dummy() const { return theory->has_dummy(); }
     CCoord node_coord( int k ) const { return theory->node_coord( k ); }
-- 
GitLab