function  generateModelFile( name, path )
%GENERATEMODELFILE Generates a file stubs for a new model.  This function
% is used to generate three stub files for a new model.  The files can then
% be filled in with the details of the model.  The files will be named
%
%       <name>_reactions.txt
%       <name>_parameters.txt
%       <name>_species.txt
%   
%  generateModelFile(name) creates the new files in the current directory
%  generateModelFile(name, path) creates the new files in the given folder
%
%  If the files already exist then the function will throw an error

% This work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative 
% Works 3.0 United States License. To view a copy of this license, visit 
% http://creativecommons.org/licenses/by-nc-nd/3.0/us/ or send a letter to Creative Commons,
% 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

if(nargin == 1)
    path = '.';
end

rxn = [path, filesep, name, '_reactions.txt'];
prm = [path, filesep, name, '_parameters.txt'];
spc = [path, filesep, name, '_species.txt'];


assert(~exist(rxn, 'file'), 'Kronecker:FileExists', '%s already exists', rxn);
assert(~exist(prm, 'file'), 'Kronecker:FileExists', '%s already exists', prm);
assert(~exist(spc, 'file'), 'Kronecker:FileExists', '%s already exists', spc);

writeStub(rxn, 'Reactant1\tReactant2\tProduct\tkForward\tkReverse\tComment\n');
writeStub(prm, 'Name\tValue\tComment\n');
writeStub(spc, 'Name\tInitial\tInput\tOutput1\tOutput2\tComment\n');

end

function writeStub(name, txt)
    fid = fopen(name, 'w');
    fprintf(fid, txt);
    fclose(fid);
end