function [gene_data,...
discret_data,...
bound_data,...
ode_data,...
phys_data,...
fish] = bht_data_compile(varargin)
% BHT_DATA_COMPILE
% Compile user's DAT-File.
%
% Syntax
%
% BHT_DATA_COMPILE('DataFilename',filename1)
%
% BHT_DATA_COMPILE('DataFilename',filename1,'ControlsFilename',filename2)
%
% Description
%
% The statement:
%
% BHT_DATA_COMPILE('DataFilename',filename1)
%
% does the following:
%
% * It compiles the data contained in the user's DAT-File
% filename1.dat, checks them and turns them into MATLAB tructure array
% variables (see the page List of output variables in BhT's
% documentation). These variables are next saved on disk into the
% MAT-File filename1_data.mat.
% * It generates the M-File filename1_kine.m by which bodies' kinematics
% are handled in the computations.
%
% The command line:
%
% BHT_DATA_COMPILE(...,'ControlsFilename',filename2)
%
% generates furthermore a pattern of the M-File filename2.m (the
% controls M-File). This M-File has to be completed by the user. It
% drives the time-evolving angles of the articulated bodies' hinges.
%
% The function BHT_DATA_COMPILE runs successively the M-Files
% bht_translation, bht_boundaries_init, bht_solids_data_init,
% bht_g_kinematics and bht_g_controls.
%
% See also BHT_BOUNDARY_CHECK, BHT_KINE_CHECK, BHT_CONTROLS_CHECK
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 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 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%##########################################################################
% default values
no_filename = 1;
is_cont_filename = 0;
%==========================================================================
% reading options
%================
nb_varargin = numel(varargin);
kk = 1;
while kk <= nb_varargin
if ~ischar(varargin{kk})
error(['Unknown option ',num2str(varargin{kk})]) %#ok<ST2NM>
end
%------------------------------------------------------------------
switch lower(varargin{kk})
%--------------------------------------------------------------
case 'datafilename'
if ischar(varargin{kk+1})
filename = varargin{kk+1};
exten = regexp(filename,'\w*\.(\w*)', 'tokens');
no_filename = 0;
if isempty(exten)
filename = [filename,'.dat']; %#ok<AGROW>
end
else
error('Unexpected expression for option DataFilename.')
end
kk = kk+2;
%--------------------------------------------------------------
case 'controlsfilename'
if ischar(varargin{kk+1})
cont_filename = varargin{kk+1};
cont_filename = regexp(cont_filename,'(\w*)', 'tokens');
cont_filename = cont_filename{1}{1};
is_cont_filename = 1;
else
error('Unexpected expression for option ControlsFilename.')
end
kk = kk+2;
%--------------------------------------------------------------
otherwise
error(['Unknown option ''',varargin{kk},''''])
end
end
% =========================================================================
% DataFilename is missing
if no_filename
filename = input('Enter data file''s name (hit Return to browse): ','s');
if isempty(filename);
filename = uigetfile('*.dat','Select data file');
end
end
%##########################################################################
% Running 'bht_translation.m' function
%--------------------------------
[gene_data,...
discret_data,...
bound_data,...
ode_data,...
phys_data,fish] = bht_translation(filename);
%==========================================================================
% Running 'bht_boundaries_init.m' function
%------------------------------------
[discret_data,...
bound_data] = bht_boundaries_init(gene_data,...
discret_data,...
bound_data);
%==========================================================================
% Running 'bht_solids_data_init.m' function
%-------------------------------------
[phys_data,...
bound_data] = bht_solids_data_init(gene_data,...
bound_data,...
phys_data);
%==========================================================================
% Building the name that describes the kinematics of the fishes ;
% Running 'g_kinematic.m' function
%--------------------------------
kine_filename = regexpi(filename,'(\w*)', 'tokens');
kine_filename = kine_filename{1}{1};
kine_filename = [kine_filename,'_kine'];
bht_g_kinematics(fish,kine_filename)
disp(['File ''',kine_filename,'.m'' successfully generated']);
%==========================================================================
% Running 'bht_g_controls.m' function
%-------------------------------
if is_cont_filename
test_cont_filename = [cont_filename,'.m'];
if exist(test_cont_filename,'file')
is_cont_filename = 0;
overw = input(['File ''',test_cont_filename,...
''' already exists. Do you want to overwrite it? '],'s');
if strcmpi(overw,'yes') || strcmpi(overw,'y')
is_cont_filename = 1;
end
end
end
if is_cont_filename
bht_g_controls(cont_filename,fish)
disp(['Pattern of file ''',cont_filename,'.m'' successfully generated']);
end
%##########################################################################
% Saving output cell array and struct array variables
%----------------------------------------------------
filename1 = [gene_data.base_filename,'_data'];
save(filename1,'gene_data','discret_data','bound_data','ode_data',...
'phys_data','fish');
disp(['Data saved in file ''',filename1,''''])
end