help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

iterator problem in oct-file


From: matthias . bergmeister
Subject: iterator problem in oct-file
Date: Tue, 20 Jun 2006 13:58:29 +0200


Hello,
I have a strange problem accessing structure elements in an oct-file. Please have a look at the example below which runs perfectly with Octave 2.1.73 under cygwin but not with Octave under 2.1.73 under Linux. Please let me know, if you are willing to help but need further information.

First,  I create a structure, which I use as test data, in a script file:
*******************************************************************************************************************
structure1.a =4.23;
structure1.b =4;
structure1.c ="testString 1";


structure2.a =2.76;
structure2.b =5;
structure2.c ="testString 2";

structure3.a =3.88;
structure3.b =6;
structure3.c ="testString 3";

testArray(1)=structure1;
testArray(2)=structure2;
testArray(3)=structure3;

Then I call the following oct-file:
//***************************************************************************************************************************
#include <string>
#include <octave/oct.h>
#include <octave/ov-struct.h>

DEFUN_DLD (conversionExample, prhs, nlhs ,  "Reproduces an Error which does not occur when cygwin is used")
{
 
   double a;
   int b;
   std::string c;
   octave_value tmp;
   Octave_map::iterator p1;

      if ( !prhs(0).is_map() )          {error("First input argument must be of type struct."); return octave_value(0);}
 
   p1 = prhs(0).map_value().seek("a");
   tmp =  prhs(0).map_value().contents(p1)(1);
   a = tmp.double_value();
   octave_stdout << "a is " << a << std::endl;
 
   p1 = prhs(0).map_value().seek("b");
   tmp =  prhs(0).map_value().contents(p1)(2);
   b = tmp.int_value();
   octave_stdout << "b is " << b << std::endl;

   p1 = prhs(0).map_value().seek("c");
   tmp =  prhs(0).map_value().contents(p1)(2);
   c = tmp.string_value().data();
   octave_stdout << "c is " << c << std::endl;
   return octave_value(0);

}
Letting this oct-file run with testArray as an argument, octave correctly returns the following under cygwin:
octave:2>conversionExample(testArray)
a is 2.76
b is 6
c is testString3
ans = 0

under linux I get different results. All of them indicate the "seek"-command does not return iterators which point to the correct field. e.g.:
octave:3> conversionExample(testArray)
a is 5
error: invalid conversion from string to real scalar
error: octave_base_value::int_value (): wrong type argument 'string'
b is 0
warning: implicit conversion fom scalar to string
c is

Regards
Matthias








reply via email to

[Prev in Thread] Current Thread [Next in Thread]