-
Notifications
You must be signed in to change notification settings - Fork 28
/
palm_configrw.m
84 lines (78 loc) · 2.57 KB
/
palm_configrw.m
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function varargout = palm_configrw(varargin)
% Read and write PALM configuration files.
%
% Usage:
% cfg = palm_configrw(fname)
% palm_configrw(cfg,fname)
%
% cfg : Configurations (cell array).
% fname : Text-file with the configurations.
%
% _____________________________________
% Anderson M. Winkler
% FMRIB / University of Oxford
% Jan/2013
% http://brainder.org
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% PALM -- Permutation Analysis of Linear Models
% Copyright (C) 2015 Anderson M. Winkler
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if nargin == 1
% Read files
plmfile = varargin{1};
fid = fopen(plmfile,'r');
cfg = textscan(fid,'%s','CommentStyle','#');
fclose(fid);
if nargout == 1
varargout = cfg;
end
elseif nargin == 2
% Version & environment
ver = fliplr(strtok(fliplr(palm_help('version')),' '));
if palm_isoctave
envrun = 'Octave';
else
envrun = 'MATLAB';
end
% Write files
cfg = varargin{1};
plmfile = varargin{2};
fid = fopen(plmfile,'w');
fprintf(fid,'# Configuration file for PALM.\n');
fprintf(fid,'# Version %s, running in %s %s.\n',ver,envrun,version);
fprintf(fid,'# %s\n',datestr(now));
fprintf('Running PALM %s using %s %s with the following options:',ver,envrun,version);
for c = 1:numel(cfg)
s2d = str2double(cfg{c});
if strcmp(cfg{c}(1),'-') && (isnan(s2d) || ~isreal(s2d))
fprintf( '\n%s',cfg{c});
fprintf(fid,'\n%s',cfg{c});
else
if ischar(cfg{c})
fprintf( ' %s',cfg{c});
fprintf(fid,' %s',cfg{c});
else
fprintf( ' %s',num2str(cfg{c}));
fprintf(fid,' %s',num2str(cfg{c}));
end
end
end
fprintf( '\n');
fprintf(fid,'\n');
fclose(fid);
else
error('Incorrect number of input arguments.');
end