Program Examples:Octave interface

From SoftMC-Wiki
Revision as of 13:40, 8 March 2017 by Ron (talk | contribs) (Example of an Octave function that reads a softMC record file)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Example of an Octave function that reads a softMC record file. (Octave is an open source software with a similar syntax to Matlab)

function [rec, vars] = MCplot(filepath)
     fid = fopen(filepath,'r');
     n   = fread(fid,1,'int32');
     m   = fread(fid,1,'int32');
     gap = fread(fid,1,'int32');
     vlen= fread(fid,1,'int32');
     vars = fgets(fid,vlen);
     n = mod(n,16);
     rec = zeros(m,n);
 
     for i = 1:m
       for j = 1:n
     	  tmp = fread(fid,1,'double');
     	  rec(i,j) = tmp;
     	end
     end
     fclose(fid);
end

The returned parameters are 'rec' and 'vars', were 'vars' is a string stating the recorded variables and 'rec' is the data of these variables ordered in a matrix such that var_1 -> rec(:,1), var_2 -> rec(:,2) ... var_n -> rec(:,n).

Example for plotting 2D data:

[rec, vars] = MCplot('C:\SoftMC\Projects\test.rec')
plot(rec(:,1),rec(:,2));

Example for plotting 3D data as a curve:

[rec, vars] = MCplot('C:\SoftMC\Projects\test.rec')
plot3(rec(:,1),rec(:,2),rec(:,3));