7
7
% If filespec is not passed, then it saves to default.mat
8
8
% in the CalData folder. If filespec is an integer, saves
9
9
% to screenN.mat. If filespec is a string, saves to string.mat.
10
% You can also pass the name with the training .mat already there.
12
% Saves to existing file if it is found, otherwise creates a
13
% new calibration file.
15
% See also LoadCalFile, CalDataFolder.
11
17
% 5/28/96 dgp Wrote it.
12
18
% 6/6/96 dgp Use CalibrationsFolder.
13
19
% 7/25/96 dgp Use CalDataFolder.
14
20
% 8/4/96 dhb More flexible filename interface.
15
% 8/21/97 dhb Rewrite for cell array convention.
21
% 8/21/97 dhb Rewrite for cell array convention.
16
22
% 8/25/97 dhb, pbe Fix bug in cell array handling.
17
23
% 8/26/97 dhb Make saving code parallel LoadCalFile.
18
24
% 5/18/99 dhb Add optional directory arg.
20
26
% 7/9/02 dhb Incorporate filespec/filename fix as suggested by Eiji Kimura.
21
27
% 3/27/12 dhb Pass dir to LoadCalFile call, so that it does the right thing
22
28
% in cases where cal file location is expilcitly passed.
29
% 4/2/13 dhb Updated for subdir searching logic.
30
% 4/12/13 dhb Make this save to cal file folder when file doesn't yet exist.
31
% 6/2/13 dhb More robust about whether passed filespec contains the trailing '.mat'.
25
if nargin < 3 || isempty(dir)
28
34
if nargin < 2 || isempty(filespec)
29
35
filespec = 'default';
30
filename = [dir 'default.mat'];
36
filename = ['default.mat'];
31
37
elseif ischar(filespec)
32
filename = [dir filespec '.mat'];
38
if (~strcmp(filespec(end-3:end),'.mat'))
39
filename = [filespec '.mat'];
34
filename = [dir sprintf('screen%d.mat',filespec)];
44
filename = [sprintf('screen%d.mat',filespec)];
47
if nargin < 3 || isempty(dir)
48
dir = CalDataFolder(0,filename);
37
51
% Load the file to get older calibrations
38
[oldCal, oldCals] = LoadCalFile(filespec, [], dir);
52
[oldCal, oldCals, fullFilename] = LoadCalFile(filespec, [], dir);
39
53
if isempty(oldCals)
40
54
cals = {cal}; %#ok<NASGU>
55
eval(['save ' QuoteString(fullFilename) ' cals']);
42
57
nOldCals = length(oldCals);
44
59
cals{nOldCals+1} = cal; %#ok<NASGU>
60
eval(['save ' QuoteString(fullFilename) ' cals']);
48
eval(['save ' QuoteString(filename) ' cals']);