Difference between revisions of "AnyWave:Plugin Batch"

From WikiMEG
Jump to: navigation, search
Line 16: Line 16:
 
flags = CanRunFromCommandLine:NoDataRequired<br/>
 
flags = CanRunFromCommandLine:NoDataRequired<br/>
 
This indicates that the plugin can be called from the command line but also indicates that no data file is required. (The plugin will not run on a data file.)<br/>
 
This indicates that the plugin can be called from the command line but also indicates that no data file is required. (The plugin will not run on a data file.)<br/>
 +
===edit MATLAB code===
 +
Modify the main.m file:<br/>
 +
<syntaxhighlight lang="matlab">
 +
function main(varargin)
 +
global args;  %% IMPORTANT: this variable will hold the arguments set by the user on the command line.
 +
if isdeployed  % this is the code to use if you plan to Compile your plugin to distribute it.
 +
% STANDALONE AnyWave Plugin code
 +
  global host; 
 +
  global port;
 +
  global pid;
 +
 +
  if (nargin < 3) % basic argument checking
 +
      error('missing arguments.');
 +
  end
 +
  host = varargin{1};
 +
  port = str2num(varargin{2});
 +
  pid = str2num(varargin{3});
 +
  if (nargin > 3)
 +
    args = varargin{4};
 +
  end
 +
 
 +
  assignin('base', 'host',  host);
 +
  assignin('base', 'port', port);
 +
  assignin('base', 'pid', pid);
 +
  assignin('base', 'args', args);
 +
% end of STANDALONE AnyWave Plugin code
 +
end
 +
 +
% we assume here that the code will always run in batch mode.
 +
% To check if the plugin was called in batch mode, just check if args variable is empty or not.
 +
if isempty(args)
 +
  error('this plugin will only run in batch mode');
 +
end
 +
 +
% code your stuff here
 +
% use args to get the arguments:
 +
% args is a structure containing fields named upon the arguments set by the command line.
 +
%
 +
% one of the common argument set by AnyWave is input_file which contains the path to the data file to process.
 +
% so to get the file use :  file = args.input_file;
 +
 +
</syntaxhighlight>
 
==C++==
 
==C++==

Revision as of 15:39, 21 April 2020

Introduction

One of the features of AnyWave is to run some processing from the command line.
This is called batch processing, allowing to process many files in different locations using a script file run by the OS.

Make my plugin runnable in command line

If you want AnyWave to handle your plugin using the command line, you must do as follow:

MATLAB/Python

edit the desc.txt:

name = MyPlugin
description = do something in MATLAB
category = Process:Test:MyPlugin
flags = CanRunFromCommandLine

Note: we've added a line with the flags keyword. This keyword will inform AnyWave of the capabilities of your plugin.
You may combine flags using the : (the colon character). Example:
flags = CanRunFromCommandLine:NoDataRequired
This indicates that the plugin can be called from the command line but also indicates that no data file is required. (The plugin will not run on a data file.)

edit MATLAB code

Modify the main.m file:

function main(varargin)
global args;  %% IMPORTANT: this variable will hold the arguments set by the user on the command line. 
if isdeployed  % this is the code to use if you plan to Compile your plugin to distribute it.
% STANDALONE AnyWave Plugin code
   global host;   
   global port;
   global pid;
 
   if (nargin < 3) % basic argument checking
       error('missing arguments.');
  end
  host = varargin{1};
  port = str2num(varargin{2});
  pid = str2num(varargin{3});
  if (nargin > 3)
    args = varargin{4};
  end
 
  assignin('base', 'host',  host);
  assignin('base', 'port', port);
  assignin('base', 'pid', pid);
  assignin('base', 'args', args);
% end of STANDALONE AnyWave Plugin code
end
 
% we assume here that the code will always run in batch mode.
% To check if the plugin was called in batch mode, just check if args variable is empty or not.
if isempty(args)
   error('this plugin will only run in batch mode');
end
 
% code your stuff here
% use args to get the arguments:
% args is a structure containing fields named upon the arguments set by the command line.
%
% one of the common argument set by AnyWave is input_file which contains the path to the data file to process.
% so to get the file use :  file = args.input_file;

C++