Mercurial > hg > plml
changeset 27:555b29024dab
Switched to use_foreign_library/1 and replaced plm_state with simpler current_engine/1
author | samer |
---|---|
date | Fri, 24 Feb 2012 18:11:23 +0000 |
parents | de95213cdcc2 |
children | fa51ed121a52 |
files | prolog/plml.pl |
diffstat | 1 files changed, 9 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/prolog/plml.pl Wed Feb 22 21:36:34 2012 +0000 +++ b/prolog/plml.pl Fri Feb 24 18:11:23 2012 +0000 @@ -235,29 +235,13 @@ :- op(400,xfy,\). % matrix reverse division :- op(100,yfx,#). % field indexing (note left-associativity) -:- dynamic plml_flag/2. +:- dynamic current_engine/1. -load_plml :- - catch( load_foreign_library(foreign(plml)), - Ex, ( - writeln('\n** Failed to load plml dynamic library. Possible causes:'), - writeln(' (1) plml.dylib or plml.so is not on foreign(_) search path (see file_search_path/2).'), - writeln(' (2) Matlab libraries not on dyld library path (need to set DYLD_FALLBACK_LIBRARY_PATH).'), - writeln(' Check error message below for more information.\n'), - throw(Ex) - )). - -set_flag(Flag,Value) :- - ground(Flag), - retractall(plml_flag(Flag,_)), - assert(plml_flag(Flag,Value)). - +:- use_foreign_library(foreign(plml)). +:- initialization(at_halt(ml_closeall)). ml_closeall :- - forall(plml_flag(ml(Id),open), ml_close(Id)). - -:- load_plml. -:- at_halt(ml_closeall). + forall(current_engine(Id), ml_close(Id)). %% matlab_init( -Key, -Cmd:ml_expr) is nondet. @@ -302,6 +286,7 @@ ml_open(Id) :- ml_open(Id,localhost,[]). ml_open(Id,Host) :- ml_open(Id,Host,[]). ml_open(Id,Host,Options) :- + ground(Id), options_flags(Options,Flags), ( (Host=localhost;hostname(Host)) -> Exec='exec matlab' % using exec fixes Ctrl-C bug @@ -319,7 +304,7 @@ debug(plml,'About to start Matlab with: ~w',[Cmd]), mlOPEN(Cmd,Id), addpath(db), - set_flag(ml(Id),open), + assert(current_engine(Id)), ( member(noinit,Options) -> true ; forall( matlab_path(_,Dir), maplist(nofail(addpath),Dir)), forall( matlab_init(_,Cmd), nofail(Cmd)) @@ -330,7 +315,7 @@ %% ml_close(+Id:ml_eng) is det. % Close Matlab session associated with Id. -ml_close(Id) :- mlCLOSE(Id), set_flag(ml(Id),closed). +ml_close(Id) :- ground(Id), mlCLOSE(Id), retract(current_engine(Id)). nofail(P) :- catch(ignore(call(P)), E, print_message(warning,E)). nofail(P,X) :- catch(ignore(call(P,X)), E, print_message(warning,E)). @@ -652,10 +637,10 @@ convert_mx(loc, X, mat(Y,W)) :- !, mlMX2ATOM(X,Z), term_to_atom(Y|W,Z). convert_mx(mat, X, Y) :- !, % !!! use first engine to save to its matbase - plml_flag(ml(I),open), + current_engine(I,open), bt_call( db_save(I,mx(X),Y), db_drop(I,Y)). convert_mx(tmp, X, Y) :- !, % !!! use first engine to save to its matbase - plml_flag(ml(I),open), + current_engine(I,open), bt_call( db_tmp(I,mx(X),Y), db_drop(I,Y)). convert_mx(list(float), X, Y) :- !, mlGETREALS(X,Y).