11
2- function saveR2(dirName ,problem ,results ,controls )
3-
4- % Saves the current project in RasCAL2 format...
5-
6- arguments
7- dirName {mustBeText }
8- problem {mustBeA(problem , ' projectClass' )}
9- results
10- controls {mustBeA(controls , ' controlsClass' )}
11- end
12-
13- % Check whether the save directory exists, create it if necessary
14- if exist(dirName ,' dir' ) ~= 7
15- mkdir(dirName );
16- end
17- currentDir = pwd ; % Save the current directory name
18-
19- % Do some custom file housekeeping. We need to copy these to our new
20- % folder if there are any..
21- filesTable = problem .customFile .varTable ;
22- for i = size(filesTable ,1 )
23- thisFile = fullfile(filesTable{i ,' Path' },filesTable{i ,' Filename' });
24- copyfile(thisFile ,dirName )
25-
26- % Change the paths of our custom files in projectClass to point to our
27- % new files..
28- problem .setCustomFile(i ,' path' ,fullfile(currentDir ,dirName ));
29- end
30-
31- % Go to our new directory and export the jsons...
32- cd(dirName );
33- projectToJson(problem ,' project.json' );
34- resultsToJson(results ,' results.json' );
35- controlsToJson(controls ,' controls.json' );
36-
37- % Go back to our original dir and we are done...
38- cd(currentDir );
2+ function saveR2(dirName , problem , results , controls )
3+ % Saves the current project in RasCAL2 format.
4+ %
5+ % Examples
6+ % --------
7+ % >>> saveR2("r2_example", problem, results, controls); % Save project to a given directory
8+ %
9+ % Parameters
10+ % ----------
11+ % dirName : string or char array
12+ % The path to save the R2 project files.
13+ % project : projectClass
14+ % An instance of the ``projectClass`` which should be saved.
15+ % results : struct
16+ % A result struct which should be saved.
17+ % controls : controlsClass
18+ % An instance of the ``controlsClass`` which should be saved.
19+
20+ arguments
21+ dirName {mustBeTextScalar , mustBeNonempty }
22+ problem {mustBeA(problem , ' projectClass' )}
23+ results
24+ controls {mustBeA(controls , ' controlsClass' )}
25+ end
26+
27+ tmpProblem = problem .clone();
28+ % Check whether the save directory exists, create it if necessary
29+ if exist(dirName ,' dir' ) ~= 7
30+ mkdir(dirName );
31+ end
32+ currentDir = pwd ; % Save the current directory name
33+
34+ % Do some custom file housekeeping. We need to copy these to our new
35+ % folder if there are any..
36+ filesTable = tmpProblem .customFile .varTable ;
37+ for i = 1 : size(filesTable ,1 )
38+ thisFile = fullfile(filesTable{i ,' Path' },filesTable{i ,' Filename' });
39+ copyfile(thisFile ,dirName )
40+
41+ % Change the paths of our custom files in projectClass to point to our
42+ % new files..
43+ tmpProblem .setCustomFile(i ,' path' ,fullfile(currentDir ,dirName ));
44+ end
45+
46+ % Go to our new directory and export the jsons...
47+ cd(dirName );
48+ projectToJson(problem ,' project.json' );
49+ resultsToJson(results ,' results.json' );
50+ controlsToJson(controls ,' controls.json' );
51+
52+ % Go back to our original dir and we are done...
53+ cd(currentDir );
3954
4055end
0 commit comments