Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions utilities/misc/loadR2.m
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions utilities/misc/saveR2.m
Original file line number Diff line number Diff line change
@@ -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