pathstr = [fileparts(which('mfsetpath')) filesep];

addpath([pathstr 'write']);
addpath([pathstr 'read']);
addpath([pathstr 'etc']);
addpath([pathstr 'gridcoords']);
addpath([pathstr 'fdm']);


%% filling in the pathtoexecutables in mflab/mfiles/write/setExecutables.m

%% get path to executables relative to current directory
cd ..

pathtoexecutables=[pwd filesep 'bin' filesep];

cd mfiles

%% Read setPathtoexecutables.txt

fid=fopen([pathstr 'write/setExecutables.m'],'r');

A=fscanf(fid,'%c',Inf);

fclose(fid);

%% Writing setPathtoexecutables.m replacing the string pathtoexecutableshere
% with the actual path
% if it doesn't work you have to do it by hand
% on PC change the path to the form like
% 'Z:\tolsthoorn On My Mac\GRWMODELS\mflab\mfiles\bin'
%instead of 
%'vmware-host\Shared Folders\tolsthoorn On My Mac\GRWMODELS\mflab\bin'
% otherwise windows is unaware of file changes during a session.

fid=fopen([pathstr 'write/setExecutables.m'],'w');

n=findstr('MODELS=',A)+length('MODELS=')-1;

if ismac n=n(1); else n=n(2); end

m=findstr('''',A(n:end)); m=m(2);

fprintf(fid,'%s',A(1:n));

fprintf(fid,'%c%s%c','''',pathtoexecutables,'''');


fprintf(fid,'%s',A(n+m:end));

fclose(fid);
