x = [0.0; 1.265; -pi/2; 0.1; -0.2; pi/2+0.1; 0.5; -1.0; pi/2; ...	% initial q
      1.0; 0.0;   0.0; -1.0; 0.0;  0.0; 2.0;  0.0; 0.0 ; ...		% initial qdots
	zeros(16,1)+1.0; ....	% initial Lce = 2*Lceopt, very long fibers at t=0
	zeros(16,1)+0.5];
t = 0.0;
u = zeros(16,1)+1;

copyfile ('../../mdl/legs2dmex/legs2d.mexw32', 'legs2d.mexw32');
[statedots, cm, grf, mforces, stick, mforcesCE, Premind] = legs2d(t,x,u);

fid = fopen('output.txt','w');

fprintf(fid, 'x \n');
for i = 1:length(x)
    fprintf(fid, '%.4f \t', x(i));
end
fprintf(fid, '\n');

fprintf(fid, 'u \n');
for i = 1:length(u)
    fprintf(fid, '%.4f \t', u(i));
end
fprintf(fid, '\n');

fprintf(fid, 't \n');
fprintf(fid, '%.4f \t', t);
fprintf(fid, '\n');

fprintf(fid, 'statedots \n');
for i = 1:length(statedots)
    fprintf(fid, '%.4f \t', statedots(i));
end
fprintf(fid, '\n');

fprintf(fid, 'cm \n');
for i = 1:length(cm)
    fprintf(fid, '%.4f \t', cm(i));
end
fprintf(fid, '\n');

fprintf(fid, 'grf \n');
for i = 1:length(grf)
    fprintf(fid, '%.4f \t', grf(i));
end
fprintf(fid, '\n');

fprintf(fid, 'mforces \n');
for i = 1:length(mforces)
    fprintf(fid, '%.4f \t', mforces(i));
end
fprintf(fid, '\n');

fprintf(fid, 'stick \n');
for i = 1:length(stick)
    fprintf(fid, '%.4f \t', stick(i));
end
fprintf(fid, '\n');

fprintf(fid, 'mforcesCE \n');
for i = 1:length(mforcesCE)
    fprintf(fid, '%.4f \t', mforcesCE(i));
end
fprintf(fid, '\n');

fprintf(fid, 'Premind \n');
fprintf(fid, '%s', Premind);
fprintf(fid, '\n');

fclose(fid);
