function [] = bht_g_controls(nom,fish)
% BHT_G_CONTROLS
%
% Generate a controls M-File's pattern.
%
% Syntax
%
% BHT_G_CONTROLS(filename,fish)
%
% Description
%
% The function is ran by BHT_DATA_COMPILE on user's request. It generates
% the controls M-File's pattern 'filename.m', based on the bodies'
% architechture as it is described by the structure array variable
% fish. Except when all of the articulated bodies are reduced to single
% solids, the generated M-File is incomplete and can not be used before
% being completed by the user.
%
% See also BHT_DATA_COMPILE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% BIOHYDRODYNAMICS MATLAB TOOLBOX %
% %
% A. MUNNIER and B. PINCON %
% %
% alexandre.munnier@iecn.u-nancy.fr bruno.pincon@iecn.u-nancy.fr %
% http://www.iecn.u-nancy.fr/~munnier http://www.iecn.u-nancy.fr/~pincon %
% %
% %
% INSTITUT ELIE CARTAN, NANCY 1 %
% http://www.iecn.u-nancy.fr/ %
% %
% INRIA Lorraine, Projet CORIDA %
% http://www.iecn.u-nancy.fr/~corida/ %
% %
% %
% %
% %
% August 15th 2008 %
% %
% GNU GPL v3 licence %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%##########################################################################
nom_fichier = [nom, '.m'];
fid = fopen(nom_fichier, 'w');
fprintf(fid, 'function [c,dc,dttc] = %s(t,cont_parameters)\n',nom);
nb_control = 0;
nb_fish = numel(fish);
for k = 1:nb_fish
nb_control = nb_control+numel(fish{k})-1;
end
fprintf(fid,'%% ======================================================\n');
fprintf(fid,'%% preallocating output variables\n');
fprintf(fid,'c = zeros(%d,1);\n',nb_control);
fprintf(fid,'dc = zeros(%d,1);\n',nb_control);
fprintf(fid,'dttc = zeros(%d,1);\n',nb_control);
fprintf(fid,'%% ======================================================\n');
fprintf(fid,'%% Warning: non zero controls velocities (dc) at the\n');
fprintf(fid,'%% time t = 0 may produce strong fish''s drift.\n');
fprintf(fid,'%% ======================================================\n');
fprintf(fid,'%% \n');
fprintf(fid,'%% \n');
%=========================================================================
iter_cont = 0;
iter_cont1 = 0;
for k = 1:nb_fish;
nb_solid = numel(fish{k});
if nb_solid > 1
fprintf(fid,'%% ======================================================\n');
fprintf(fid,'%% fish %d\n',k);
fprintf(fid,'%% ======================================================\n');
fprintf(fid,'%% \t\t\t joint\t\t\t control number\n');
fprintf(fid,'%% ______________________________________________________\n');
for j=2: nb_solid
iter_cont = iter_cont+1;
current = fish{k}(j).label;
father = fish{k}(j).father;
fprintf(fid,'%% %12s-%-12s',father,current);
fprintf(fid,' \t\t %-d\n',iter_cont);
end
for j = 2:nb_solid
iter_cont1 = iter_cont1+1;
fprintf(fid,'%% ======================================================\n');
fprintf(fid,'c(%d) = \n',iter_cont1);
fprintf(fid,'dc(%d) = \n',iter_cont1);
fprintf(fid,'dttc(%d) = \n',iter_cont1);
end
end
end
fprintf(fid,'%% ======================================================\n');
fprintf(fid,'%% Use the fonction BHT_CONTROLS_CHECK to check the formula');
fclose(fid);