function [Label,Data]=MBDynLoad(FileName)

% MBDynLoad loads MBDyn output files such as MOV, FRC, and JNT files into workspace variables.
%    [LABEL,DATA]=MBDynLoad(FILENAME) reads and stores node or element labels in the row
%    vector LABEL and all data in the three dimensional array DATA.
%    DATA(i,j,k) will contain the j-th component value of the k-th node or element at the i-th time.
%    See MBDyn Manual for information about data contained in each output file.
%
%    For example, suppose 'sample.mov' is a MOV file output by an MBDyn analysis, then by
%
%       [LABEL,DATA]=MBDynLoad('sample.mov')
%
%    DATA(:,2,LABEL==5) gives the time sequence of X position of the node 5.
%
% NOTES:
% * Developed for MATLAB Version 6.0.0.88 Release 12. Modifications may be required for older or newer versions.
% * For information about MBDyn, please visit its official homepage at https://www.mbdyn.org/.
% (c) 2010-2011 Sky Engineering Laboratry Inc. (https://www.sky-engin.jp)


% Read Output File
M=dlmread(FileName);

% Make Label
Temp_Label=M(:,1);
Label=[];
while ~isempty(Temp_Label)
    Label=[Label,min(Temp_Label)];
    Temp_Label=Temp_Label(find(Temp_Label~=min(Temp_Label)));
end
clear Temp_Label;

% Make Data
for i=1:length(Label)
    Data(:,:,i)=M(find(M(:,1)==Label(i)),:);
end