Program Examples:Octave interface
Language: | English • 中文(简体) |
---|
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'); % open file and save its id to fid
n = fread(fid,1,'int32'); % n-> raw number of columns
n = mod(n,16); % n -> fix the number of columns
m = fread(fid,1,'int32'); % m -> number of rows
gap = fread(fid,1,'int32');
vlen= fread(fid,1,'int32');
vars = fgets(fid,vlen); % vars -> string stating the recorded variables
rec = zeros(m,n);
for i = 1:m
for j = 1:n
rec(i,j) = fread(fid,1,'double');
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));