rbmatlab 0.10.01
general/remote_function.m
00001 function [varargout] = remote_function(functionname,varargin);
00002 %function res = remote_function(functionname,varargin);
00003 %
00004 % function starting a remote matlab session, performing a function
00005 % call and returning the results 
00006 
00007 % Bernard Haasdonk 22.4.2010
00008 
00009 % path to windows-directory with linux commands (ssh, scp:)
00010 path_bash = 'C:\Programme\Git\bin';
00011 path_remote = '~/matlab/';
00012 fn_res = 'tmpres.mat'; % local and remote
00013 fn_arg = 'tmparg.mat'; % local and remote
00014 fn_cmd = 'tmpcmd.m'; % remote command file
00015 fn_arg_local = fullfile(rbmatlabtemp,fn_arg);
00016 fn_ares_local = fullfile(rbmatlabtemp,fn_res);
00017 fn_arg_remote = fullfile(path_remote,fn_arg);
00018 fn_cmd_remote = fullfile(path_remote,fn_cmd);
00019 fn_res_remote = fullfile(path_remote,fn_res);
00020 
00021 if nargout==0
00022   error('remote function call only works for functions with return values!');
00023 end;
00024 
00025 saveargs = varargin;
00026 for i=1:length(saveargs)
00027   if isobject(varargin{i})
00028     warning('off', 'MATLAB:structOnObject');
00029     saveargs{i} = struct(varargin{i});
00030     warning('on', 'MATLAB:structOnObject');
00031   end
00032 end
00033 save(fn_arg_local,'saveargs');
00034 
00035 % copy file to remote host
00036 %cmd = [fullfile(bashpath,'cat'),' ',fn_arg_local];
00037 cmd = [fullfile(path_bash,'ssh.exe'),...
00038        ' haasdonk@am100.mathematik.uni-stuttgart.de ls'];
00039 %cmd = [fullfile(bashpath,'ssh.exe'),' ',fn_arg_local,...
00040 %       ' haasdonk@am100.uni-stuttgart.de:', ...
00041 %       fn_arg_remote];
00042 disp(['executing:']);
00043 disp(cmd);
00044 
00045 keyboard;
00046 
00047 [s,w] = unix(cmd);
00048 
00049 
00050 % on remote host generate command file:
00051 % matlab -nodesktop -nosplash, 
00052 %   load 'remote_fn_arg'
00053 %   [varargout{1:nargout}] = feval('functionname',saveargs{:});
00054 %   tmpfn_res = '~/tmpres.mat';
00055 %   save(tmpres.mat,'varargout');
00056 
00057 % on remote host: delete command, argument and result file
00058 
00059 % copy file to local host
00060 
00061 tmpfn_res = fullfile(rbmatlabtemp,fnres);
00062 loaded = load(tmpfn_res);
00063 varargout = loaded.varargout;
 All Classes Namespaces Files Functions Variables