Controlling Multiple Instances of FEMM from Matlab/Octave
User of the OctaveFEMM are often interested in knowing how to control multiple instances of FEMM from within on Matlab program. For example, using Matlab's parfor command, it would be possible to do parallel computing in a Matlab program that operates on multiple instances of FEMM.
Internal to the OctaveFEMM toolbox, there is a global variable called HandleToFEMM that is handle to the FEMM ActiveX server. To run multiple instances of FEMM, you need to expose this variable and keep track of the handles to each instance of FEMM so that your OctaveFEMM commands end up being executed on the "right" instance of FEMM. Here's a code snippet that shows how you'd go about opening, manipulating, and closing two separate instances of FEMM in Matlab:
global HandleToFEMM
openfemm;
hand1=HandleToFEMM;
openfemm;
hand2=HandleToFEMM;
% To do work on the first instance, set HandleToFEMM equal to hand1
HandleToFEMM=hand1;
newdocument(0);
%... the rest of your script acting on Instance 1
% To do work on the second instance, set HandleToFEMM equal to hand2
HandleToFEMM=hand2;
newdocument(0);
%... the rest of your script acting on Instance 2
% carefully close down all instances
HandleToFEMM=hand1;
closefemm;
HandleToFEMM=hand2;
closefemm;
openfemm;
hand1=HandleToFEMM;
openfemm;
hand2=HandleToFEMM;
% To do work on the first instance, set HandleToFEMM equal to hand1
HandleToFEMM=hand1;
newdocument(0);
%... the rest of your script acting on Instance 1
% To do work on the second instance, set HandleToFEMM equal to hand2
HandleToFEMM=hand2;
newdocument(0);
%... the rest of your script acting on Instance 2
% carefully close down all instances
HandleToFEMM=hand1;
closefemm;
HandleToFEMM=hand2;
closefemm;
Note that you don't have to precede every command by a definition of HandleToFEMM--you just need to change HandleToFEMM when you want to change what instance Matlab is pointing at.