[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Loading files from within c++ (feval)
From: |
Douglas Eck |
Subject: |
Re: Loading files from within c++ (feval) |
Date: |
Fri, 15 Feb 2002 11:16:37 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20011221 |
Paul Kienzle wrote:
Not having looked at the relevant code, I'm guessing that load is
attempting to create a variable in the current symbol table but
failing because you haven't initialized the current symbol table.
Maybe something like:
octave_value a;
curr_sym_tab = new symbol_table(10);
... your feval stuff ...
symbol_record *sr = curr_sym_tab->lookup("a");
if (sr && sr->is_defined ()) a = sr->def ();
Thanks Paul. That helped. Now all I need to do is populate
the symbol table with the functions I need... namely
"load" and, when that works, "save". I tried to figure out how
install_builtin_function(...) works. I think that's what I need to use.
But for the life of me I can't figure out how to call the constructor.
John uses clever macro stuff
[ builtins.cc: XDEFUN_INTERNAL ( load , args , nargout , true
...]
that Doug doesn't understand.
Any help?
Attached is complete code with Makefile.
Thanks!
Doug
##Primitive but effective
##This Makefile is a very-crippled version of something
##I cribbed from Paul Kienzle's matcompat work (before it
##turned into octave-forge.
##
##Douglas Eck address@hidden
##If you don't want debugging and proflining
##OPTIMIZATION = -O2
##If you want debugging and profiling
##You will have to set the version by hand.
OCTAVE_VERSION=2.1.35
OPTIMIZATION = -pg -g
MKOCTFILE = mkoctfile -v
CC=g++
CCFLAGS=-fno-implicit-templates -Wall
CCINCLUDES=-I/usr/include/octave-$(OCTAVE_VERSION)
-I/usr/include/octave-$(OCTAVE_VERSION)/octave
LD_LIBS=-lblas -loctave -loctinterp -ldl -lcruft -lg2c -ltermcap -lhdf5
-lreadline -lkpathsea -lfftw
LD_PATHS=-L/usr/lib/octave-$(OCTAVE_VERSION)
-L/usr/src/octave-$(OCTAVE_VERSION)/kpathsea
PROJ=tstFile
OBJS=tstFile.o
OCTS=tstFile.oct
all: $(OBJS) $(OCTS) $(PROJ)
$(PROJ): $(PROJ).o
$(CC) $(OPTIMIZATION) $(OBJS) -o $(PROJ) $(LD_PATHS) $(LD_LIBS)
.cc.o:
$(CC) $(CCFLAGS) $(CCINCLUDES) $(OPTIMIZATION) -c $<
%.oct: %.cc; $(MKOCTFILE) $<
clean:
rm $(OBJS) $(OCTS) $(APPS)
/*
Filename: tstFile.cc
Overview: test
Required args:
none
Optional args:
none
Return values:
none
Details: none
Author: Douglas Eck (address@hidden) http://www.idsia.ch/~doug
Project: LSTM Long Short-Term Learning
Time-stamp: <2002-02-15 11:00:41 doug>
Copyright (C) 2001 Douglas Eck
This program is free software and may be used for any purpose.
Douglas Eck is not is not responsible for the consequences of
using this software.
*/
#include <octave/oct.h>
#include <octave/ov-struct.h>
#include <octave/parse.h>
#include <octave/oct-map.h>
#include <octave/variables.h>
void dotest() {
octave_value_list func;
func(0)="load";
curr_sym_tab = new symbol_table(10);
install_builtin_function(func,"load","foo",0);
Matrix a;
char * fn = "/home/doug/src/tstFile/tst.mat";
char * var = "a";
octave_value_list args;
args(0)=fn;
args(1)=var;
cout << "Loading file " << fn << " ... ";
feval("load", args, 0); // no arguments returned
cout << "success" << endl;
cout << "Fetching variable (" << var << ") from symbol table... ";
symbol_record *sr = curr_sym_tab->lookup(var);
if (sr == NULL || sr->def().is_undefined ()) {
cerr << "Variable (" << var << ") not found in symbol table " << fn << endl;
exit(0);
} else {
a = sr->def().matrix_value();
}
cout << "success" << endl;
cout << "Displaying matrix "<< endl << a << endl;
}
DEFUN_DLD (tstFile, args, , "testing") {
octave_value_list retval;
dotest();
return retval;
}
int main(int argc, char * argv[]) {
global_sym_tab=new symbol_table(2048);
dotest();
}