File: SaveCalFile.m

package info (click to toggle)
psychtoolbox-3 3.0.9%2Bsvn2579.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 63,408 kB
  • sloc: ansic: 73,310; cpp: 11,139; objc: 3,129; sh: 1,669; python: 382; php: 272; makefile: 172; java: 113
file content (48 lines) | stat: -rw-r--r-- 1,577 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function SaveCalFile(cal, filespec, dir)
% SaveCalFile(cal, [filespec], [dir])
%
% Saves calibration data in the structure "cal" to a
% calibration file in the CalData folder.
%
% If filespec is not passed, then it saves to default.mat
% in the CalData folder.  If filespec is an integer, saves
% to screenN.mat.  If filespec is a string, saves to string.mat.

% 5/28/96  dgp  Wrote it.
% 6/6/96   dgp  Use CalibrationsFolder.
% 7/25/96  dgp  Use CalDataFolder.
% 8/4/96   dhb  More flexible filename interface.
% 8/21/97	 dhb  Rewrite for cell array convention.
% 8/25/97  dhb, pbe  Fix bug in cell array handling.
% 8/26/97  dhb  Make saving code parallel LoadCalFile.
% 5/18/99  dhb  Add optional directory arg.
% 8/10/00  dhb  Fix loading code for default.mat
% 7/9/02   dhb  Incorporate filespec/filename fix as suggested by Eiji Kimura.
% 3/27/12  dhb  Pass dir to LoadCalFile call, so that it does the right thing
%               in cases where cal file location is expilcitly passed.

% Set the filename
if nargin < 3 || isempty(dir)
	dir = CalDataFolder;
end
if nargin < 2 || isempty(filespec)
	filespec = 'default';
	filename = [dir 'default.mat'];
elseif ischar(filespec)
	filename = [dir filespec '.mat'];
else
	filename = [dir sprintf('screen%d.mat',filespec)];
end

% Load the file to get older calibrations
[oldCal, oldCals] = LoadCalFile(filespec, [], dir);
if isempty(oldCals)
	cals = {cal}; %#ok<NASGU>
else
	nOldCals = length(oldCals);
	cals = oldCals;
	cals{nOldCals+1} = cal; %#ok<NASGU>
end

% Save the file
eval(['save ' QuoteString(filename) ' cals']);