;; Matlab-interface ;; Copyright (c) 2002 Sebastian Seidel ;; This library is free software; you can redistribute it and/or ;; modify it under the terms of the GNU Lesser General Public ;; License as published by the Free Software Foundation; either ;; version 2.1 of the License, or (at your option) any later version. ;; This library is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; Lesser General Public License for more details. ;; You should have received a copy of the GNU Lesser General Public ;; License along with this library; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;; Contact me by mail: Sebastian.H.Seidel@med.uni-giessen.de ;; ---------------------------------------------------------------------- ;; This file - highlevel.ss - provides the high-level procedures of ;; matlab-interface. ;; Use matlab-interface to control matlab (www.mathworks.com) via ;; interprocess-communication from within the fantastic open-source ;; scheme-interpreters/compilers mzscheme and drscheme that are ;; distributed by plt (www.plt-scheme.org). ;; ---------------------------------------------------------------------- ;; First-edition: 2002-03-20 SSeidel ;; Latest-revision: 2002-06-03 SSeidel ;; Works with PLT-Scheme version: ;; 200 - available from http://download.plt-scheme.org ;; Usage-example: ;; (require (lib "primitive.ss" "matlab-interface")) ;; (require (lib "highlevel.ss" "matlab-interface")) ;; (engine-open) ;; (array->matrix (engine-apply "magic" (list (object->array 4)))) ;; (engine-close) ;; Procedures ;; ---------- ;; (engine-apply ... (list ...)) -> ;; Ideas ;; ----- ;; (engine-let (name-argument*) +) ;; (engine-lambda (name-argument*) +) ;; name-argument: ( ) ;; ---------------------------------------------------------------------- (module highlevel mzscheme (require (prefix pr: (lib "primitive.ss" "matlab-interface"))) (provide engine-apply) (define engine-apply (lambda (fun . args) ;; * -> (pr:engine-eval (string-append "clear " fun)) (letrec ((executor (lambda (x) (pr:engine-eval (string-append "scheme_return = feval ('" fun "'" (apply string-append x) ")")) (pr:engine-eval (string-append "clear " fun)) (pr:engine-eval "clear scheme_tmp_*") (let ((return-value (pr:engine-get "scheme_return"))) (pr:engine-eval "clear scheme_return") return-value))) (exporter (lambda (arr num exe) (let ((name (string-append "scheme_tmp_" (number->string num)))) (pr:array-name arr name) (pr:engine-put arr) (lambda (x) (exe (cons (string-append "," name) x)))))) (walker-a (lambda (ls num exe) (if (pair? ls) (if (list? (car ls)) (if (null? (cdr ls)) (walker-b (car ls) num exe) (error 'last-arg-must-be-list)) (walker-a (cdr ls) (+ num 1) (exporter (car ls) num exe))) (error 'last-arg-must-be-list)))) (walker-b (lambda (ls num exe) (if (pair? ls) (walker-b (cdr ls) (+ num 1) (exporter (car ls) num exe)) (exe '() ))))) (walker-a args 0 executor)))) )