Calling a function available in .oct file from .m file

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling a function available in .oct file from .m file

vivek
I have few .m files and .oct files where functions are mapped with file
names.I am trying to call a function available in .oct file from .m file and
getting "undefined" error.I have used "addpath", "autoload" and "setenv"
functions in .m file for including and loading .oct files but no
success.Could anyone help me in identifying the issue? I am new to octave.I
am using octave 5.1.0 on centos.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Calling a function available in .oct file from .m file

Mike Miller-4
On Tue, Apr 02, 2019 at 09:59:51 -0500, vivek wrote:
> I have few .m files and .oct files where functions are mapped with file
> names.I am trying to call a function available in .oct file from .m file and
> getting "undefined" error.I have used "addpath", "autoload" and "setenv"
> functions in .m file for including and loading .oct files but no
> success.Could anyone help me in identifying the issue? I am new to octave.I
> am using octave 5.1.0 on centos.

Can you please provide a complete example of what you have tried to do
so far so that we can help you?

What you describe is definitely possible and done in many places in
Octave using 'autoload'.

--
mike


Reply | Threaded
Open this post in threaded view
|

Re: Calling a function available in .oct file from .m file

vivek
This post was updated on .
Following are the files which i have in my case

genplots - Octave script file

genobsplot_all.m - ".m" file where genobsplot_all function is available

tmgetevents.oct is an oct file which has tmgetevents function defined in it. tmgetevents is called from genobsplot_all.m

Octave was able to locate genobsplot_all.m after adding the statement "addpath("/usr/local/vhosts/logfetch/:");" in genplots

Similar things were tried on trail and error basis for tmgetevents.oct but still i am facing undefined error for tmgetevents function.

**************************
/usr/local/vhosts/logfetch/genplots
**************************

#!/usr/local/bin/octave -qf
## takes filename, pulls all obs from that file
if (nargin != 1 && nargin != 4)
    usage("genplots filename [evid startobs endobs]");
endif

# set loadpath to just our local world and the system stuff
LOADPATH = ["/usr/local/vendor/bin:/usr/local/vhosts/logfetch/:"];

#addpath("/usr/local/vendor/bin:/usr/local/vhosts/logfetch:");

addpath("/usr/local/vhosts/logfetch/:");

setenv( "LOADPATH", "/usr/local/vendor/bin:/usr/local/vhosts/logfetch/:/usr/local/vhosts/logfetch/");

autoload('tmgetevents', '/usr/local/vendor/bin/tmgetevents.oct');

ignore_function_time_stamp = 'all';
if (nargin == 1)
    exit(genobsplot_all( argv ) );
else
    exit(genobsplot( argv(1,:), str2num(argv(2,:)), str2num(argv(3,:)), str2num(argv(4,:)) ) );
endif

********************************
/usr/local/vhosts/logfetch/genobsplot_all.m
********************************

function retval = genobsplot_all(aFilename)
  retval = 255;
  if (nargin != 1)
    usage("genobsplots(aFilename)");
  endif
  evs = tmgetevents(aFilename);
  retval = 0;
endfunction

******************************
Output of nm command for tmgetevents.oct
******************************
nm /usr/local/vendor/bin/tmgetevents.oct | grep tmgetevents
00000000000050e0 t Gtmgetevents
0000000000006230 t _Z12FtmgeteventsRK17octave_value_listi

Reply | Threaded
Open this post in threaded view
|

Re: Calling a function available in .oct file from .m file

Mike Miller-4
On Tue, Apr 02, 2019 at 13:36:32 -0500, vivek wrote:
> Following are the files which i have in my case
[…]
> nm /usr/local/vendor/bin/tmgetevents.oct | grep tmgetevents
> 00000000000050e0 t Gtmgetevents
> 0000000000006230 t _Z12FtmgeteventsRK17octave_value_listi

This all looks correct and I see no reason why this wouldn't be working.
So again, please provide a *complete* example, the still missing pieces
are the full source of tmgetevents.oct and exactly how it was compiled
for Octave. That is likely the reason for Octave not being able to load
the function.

--
mike


Reply | Threaded
Open this post in threaded view
|

Re: Calling a function available in .oct file from .m file

vivek
Following is the command used to compile tmgetevents.oct

g++ -z defs -L../tm/dist/lib -Wl,-rpath-link,../tm/dist/lib -lpthread -ldl
-lc -lnsl -lrt -liconv -o out/tmgetevents.oct -shared out/tmgetevents.o
-loctave -loctinterp -L/usr/local/lib/octave/5.1.0/ out/tmrecostore.o
out/tmobsnode.o out/tmobsdatacollect.o -Wl,-rpath=/usr/local/vendor/bin
-L/usr/local/lib -Wl,-rpath=/usr/local/lib
-Wl,-rpath=/usr/local/lib/octave/5.1.0/

*****************************
GCC version
*****************************

-bash-4.3$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/tools/stow/gcc-4_9_3-static.x86_64.linux.centos6/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.3/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /remediation/build/tjs/compile/gcc-4.9.3/configure
--prefix=/usr/local --enable-languages=c,c++,objc,obj-c++,fortran,go
--disable-shared --enable-static --with-pic=yes --with-gmp=/usr/local
--with-mpfr=/usr/local --disable-multilib
Thread model: posix
gcc version 4.9.3 (GCC)
-bash-4.3$

*****************************
tmgetevents.cpp
*****************************

#include <octave/oct.h>
#include <stdlib.h>
#include <string>

DEFUN_DLD (tmgetevents, aArgs, aNumArgs,
  "events = tmgetevents (source, ... attributes)\n\
  \n\
  Takes an obslog source (currently binary log file\n\
  and internal sources are supported) and loads the\n\
  obslog events within.  Attributes may be specified\n\
  to filter the events.\n\
  \n\
  source - a binary log filename (a string), or a\n\
     vector of event pointers.\n\
  \n\
  attributes - the following attributes are supported:\n\
    'timerange', [startime endtime]\n\
    'uuid', uuid string or char matrix\n\
    'startobs', obs name\n\
    'endobs', obs name\n\
    'eventid', event id\n\
    'crit',\n\
    'nocrit',\n\
    'rand', probability of including event\n\
    'maxnum', number of events to stop after getting\n\
    'timeout', ms after which to return with whatever\n\
               has been loaded thus far\n\
    'quiet'\n\
  ")

{
//Function body
}




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Calling a function available in .oct file from .m file

Mike Miller-4
On Tue, Apr 02, 2019 at 23:04:49 -0500, vivek wrote:
> Following is the command used to compile tmgetevents.oct
[…]

No problems, what you have shown looks reasonable, no reason why this
should not be working. The function is callable for me, so this example
doesn't show the problem that you are asking for help with.

Feel free to share another example that does demonstrate the problem.

Good luck,

--
mike


Reply | Threaded
Open this post in threaded view
|

Re: Calling a function available in .oct file from .m file

vivek
Thanks for the response. I have resolved this issue. Root cause was some of
the dependency libraries were not properly built.

I am facing a different issue now. When I manually execute "genobsplot_all(
argv )" from octave terminal, it perfectly works fine but i am getting below
error while executing "genplots " octave script from bash shell which in
turn calls "genobsplot_all( argv )".

error: octave_base_value::array_value(): wrong type argument 'cell'
error: called from
    genobsplot_all at line 21 column 7

Line 21 is "evs = tmgetevents(aFilename); " in genobsplot_all.m where
tmgetevents is an octave function from .oct file.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Calling a function available in .oct file from .m file

vivek
This post was updated on .
Adding few more information.

tmgetevents returns a Matrix which has list of pointers.

Content of tmgetevents  looks like this.

    PRInt32 numEvents = 0;

    if (TM_SUCCESS == err)
        numEvents = eventArray.length();

    Matrix eventPtrs(numEvents, numEvents == 0 ? 0 : 1);

    while (numEvents-- > 0) {
        eventPtrs(numEvents, 0) = (INT_PTR)eventArray.get(numEvents);
    }
    return octave_value(eventPtrs);


Output of tmgetevents while calling from Octave terminal.

octave:4>
tmgetevents("/var/log/obslog.bin")
tmgetevents: got 12 events from 07-Apr-2019 00:00:02 PDT to 07-Apr-2019
00:01:22 PDT
ans =

   44494112
   44463744
   41097376
   44245936
   44568048
   44580560
   44580160
   44600656
   44610016
   44623472
   44636432
   44636096







--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html