COMPARESOLVEFILES - look for an equivalent file in same directory - Step 1: compare to other *.m in /solve/ - Step 2: if match: remove(solve_file); solve_file=match; If mexPath is specified, then will do a comparison to other files in the mexPath, as opposed to the current solve folder See also: dsGetSolveFile, dsSimulate, dsCreateBatch % Example code for testing mex_dir options: eqns={ 's=10; r=27; b=2.666' 'dx/dt=s*(y-x)' 'dy/dt=r*x-y-x*z' 'dz/dt=-b*z+x*y' }; data=dsSimulate(eqns, 'tspan',[0 100], 'ic',[1 2 .5],'verbose',1, 'solver','rk4', 'study_dir','demo_lorenz','compile_flag',1,'mex_dir_flag',0,'mex_dir',[]); data=dsSimulate(eqns, 'tspan',[0 100], 'ic',[1 2 .5],'verbose',1, 'solver','rk4', 'study_dir','demo_lorenz','compile_flag',1,'mex_dir_flag',1,'mex_dir',[]); data=dsSimulate(eqns, 'tspan',[0 100], 'ic',[1 2 .5],'verbose',1, 'solver','rk4', 'study_dir','demo_lorenz','compile_flag',1,'mex_dir_flag',1,'mex_dir','mexes_temp'); Author: Jason Sherfey, PhD <jssherfey@gmail.com> Copyright (C) 2016 Jason Sherfey, Boston University, USA
0001 function solve_file_m = dsCompareSolveFiles(solve_file_m,mexPath,verbose_flag) 0002 %COMPARESOLVEFILES - look for an equivalent file in same directory 0003 % 0004 % - Step 1: compare to other *.m in /solve/ 0005 % - Step 2: if match: remove(solve_file); solve_file=match; 0006 % 0007 % If mexPath is specified, then will do a comparison to other files 0008 % in the mexPath, as opposed to the current solve folder 0009 % 0010 % See also: dsGetSolveFile, dsSimulate, dsCreateBatch 0011 % 0012 % % Example code for testing mex_dir options: 0013 % eqns={ 0014 % 's=10; r=27; b=2.666' 0015 % 'dx/dt=s*(y-x)' 0016 % 'dy/dt=r*x-y-x*z' 0017 % 'dz/dt=-b*z+x*y' 0018 % }; 0019 % data=dsSimulate(eqns, 'tspan',[0 100], 'ic',[1 2 .5],'verbose',1, 'solver','rk4', 'study_dir','demo_lorenz','compile_flag',1,'mex_dir_flag',0,'mex_dir',[]); 0020 % data=dsSimulate(eqns, 'tspan',[0 100], 'ic',[1 2 .5],'verbose',1, 'solver','rk4', 'study_dir','demo_lorenz','compile_flag',1,'mex_dir_flag',1,'mex_dir',[]); 0021 % data=dsSimulate(eqns, 'tspan',[0 100], 'ic',[1 2 .5],'verbose',1, 'solver','rk4', 'study_dir','demo_lorenz','compile_flag',1,'mex_dir_flag',1,'mex_dir','mexes_temp'); 0022 % 0023 % Author: Jason Sherfey, PhD <jssherfey@gmail.com> 0024 % Copyright (C) 2016 Jason Sherfey, Boston University, USA 0025 0026 [solvePath,fname,fext]=fileparts(solve_file_m); 0027 0028 if nargin < 2 0029 mexPath = solvePath; 0030 end 0031 0032 if nargin < 3 0033 verbose_flag = false; 0034 end 0035 0036 % get list of files in where solve_file is located 0037 D=dir(mexPath); 0038 files={D(~[D.isdir]).name}; 0039 files=files(cellfun(@any,regexp(files,'.m$'))); 0040 files=setdiff(files,[fname fext]); 0041 0042 % compare solve_file_m to each file 0043 for f=1:length(files) 0044 [~,diffs] = system(['diff ' solve_file_m ' ' fullfile(mexPath,files{f})]); 0045 if isempty(diffs) 0046 %dbstack 0047 old_solve_file_m=solve_file_m; 0048 delete(old_solve_file_m); 0049 0050 if ~strcmp(mexPath,solvePath) 0051 % Copy mex file and solve file from mexPath into solve path 0052 copyfile(fullfile(mexPath,files{f}),solvePath); 0053 [~,fname] = fileparts(files{f}); 0054 if ~isempty(dir(fullfile(mexPath,[fname '_mex*']))) 0055 copyfile(fullfile(mexPath,[fname '_mex*']),solvePath); 0056 if verbose_flag 0057 fprintf(['Copying mex file from ' fullfile(mexPath,[fname '_mex*']) ' to ' solvePath]); 0058 end 0059 end 0060 end 0061 0062 solve_file_m=fullfile(solvePath,files{f}); 0063 break; 0064 end 0065 end 0066 end