diff --git a/utilities/misc/loadR2.m b/utilities/misc/loadR2.m new file mode 100644 index 000000000..61e24d7ba --- /dev/null +++ b/utilities/misc/loadR2.m @@ -0,0 +1,15 @@ + +function [problem,varargout] = loadR2(dirName) +% Loads in a RasCAL2 project... + +% Load the project... +projectFile = fullfile(dirName,'project.json'); +problem = jsonToProject(projectFile); + +% If there is a second argument, also load results.. +if nargout > 1 + resultsFile = fullfile(dirName, 'results.json'); + varargout{1} = jsonToResults(resultsFile); +end + +end \ No newline at end of file diff --git a/utilities/misc/saveR2.m b/utilities/misc/saveR2.m new file mode 100644 index 000000000..cb66b23fb --- /dev/null +++ b/utilities/misc/saveR2.m @@ -0,0 +1,40 @@ + +function saveR2(dirName,problem,results,controls) + +% Saves the current project in RasCAL2 format... + +arguments + dirName {mustBeText} + problem {mustBeA(problem, 'projectClass')} + results + controls {mustBeA(controls, 'controlsClass')} +end + +% Check whether the save directory exists, create it if necessary +if exist(dirName,'dir') ~= 7 + mkdir(dirName); +end +currentDir = pwd; % Save the current directory name + +% Do some custom file housekeeping. We need to copy these to our new +% folder if there are any.. +filesTable = problem.customFile.varTable; +for i = size(filesTable,1) + thisFile = fullfile(filesTable{i,'Path'},filesTable{i,'Filename'}); + copyfile(thisFile,dirName) + + % Change the paths of our custom files in projectClass to point to our + % new files.. + problem.setCustomFile(i,'path',fullfile(currentDir,dirName)); +end + +% Go to our new directory and export the jsons... +cd(dirName); +projectToJson(problem,'project.json'); +resultsToJson(results,'results.json'); +controlsToJson(controls,'controls.json'); + +% Go back to our original dir and we are done... +cd(currentDir); + +end \ No newline at end of file