-
Notifications
You must be signed in to change notification settings - Fork 8
/
gps_init.m
143 lines (131 loc) · 5.44 KB
/
gps_init.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
function gps_init()
% Initializes GPS directories on a new computer
%
% Author: Alexander Conrad Nied ([email protected])
%
% Changelog:
% 2013-11-22 Created
% 2013-11-24 Finished
% 2014-01-02 GPS1.9 Adds the image directory
% 2014-01-06 Removed PLV from stages and added a new stage names field
%
% GPS is a GUI-based program composed by David Gow and members of his lab
% at the Massachusetts General Hospital to automate MNE and FSL analyses
% of MR-constrained MEG/EEG data and to perform Kalman filter based Granger
% analyses of those data.
%
% Copyright (C) 2014 Alexander Conrad Nied and David Gow
%
% 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
% (at your option) 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/>.
% Confirm
files = dir();
if(sum(strcmp({files.name},'parameters')))
answer = questdlg('This will reset GPS, are you sure?');
if(~strcmp(answer, 'Yes'))
return
end
end
% Get some information
user = getenv('USER');
gpsdir = pwd;
date = datestr(now, 'YYYY-mm-DD');
% Ask the user about folders
folders = {pwd, [pwd '/parameters'], [pwd '/images'], [pwd '/logs']};
folders = inputdlg({'Main GPS folder', 'Parameters Folder', 'Images Folder', 'Logs Folder'}, 'Select where you would like to store GPS data', [1 50], folders);
% Citation tag
citation = sprintf('%%\n%% Author: Alexander Conrad Nied ([email protected])\n%%\n%% Changelog:\n%% %s Automatically generated by gps_init to format GPS by user %s\n', date, user);
% Change the directory pointing program
fid = fopen([folders{1} '/functions/gps/gps_dir.m'], 'w');
fprintf(fid, 'function direc = %s\n', folders{1});
fprintf(fid, '%% Returns just the main GPS directory\n');
fprintf(fid, '%s\n', citation);
fprintf(fid, '\ndirec = ''%s/'';', folders{1});
fprintf(fid, '\n\nend\n');
fclose(fid);
% Preset Program
fid = fopen([gpsdir '/gps_presets.m'], 'w');
fprintf(fid, 'function preset = gps_presets(name)\n');
fprintf(fid, '%% Returns preset variables.\n');
fprintf(fid, '%s\n', citation);
fprintf(fid, 'switch lower(name)\n');
fprintf(fid, ' case {''gpsnum'', ''gpsfig'', ''menu figure''}\n');
fprintf(fid, ' preset = 6750000;\n');
fprintf(fid, ' case {''gpsanum'', ''gpsafig'', ''analysis figure''}\n');
fprintf(fid, ' preset = 6754000;\n');
fprintf(fid, ' case {''gpsenum'', ''gpsefig'', ''edit figure''}\n');
fprintf(fid, ' preset = 6753000;\n');
fprintf(fid, ' case {''gpsrnum'', ''gpsrfig'', ''region figure''}\n');
fprintf(fid, ' preset = 6752000;\n');
fprintf(fid, ' case {''gpspnum'', ''gpspfig'', ''plotting figure''}\n');
fprintf(fid, ' preset = 6757000;\n');
fprintf(fid, ' case {''dir'', ''directory''}\n');
fprintf(fid, ' preset = ''%s'';\n', folders{1});
fprintf(fid, ' case {''functions'', ''functiondir'', ''fdir''}\n');
fprintf(fid, ' preset = ''%s/functions'';\n', folders{1});
fprintf(fid, ' case {''parameters'', ''parameterdir'', ''pdir''}\n');
fprintf(fid, ' preset = ''%s'';\n', folders{2});
fprintf(fid, ' case {''images'', ''imagedir'', ''idir''}\n');
fprintf(fid, ' preset = ''%s'';\n', folders{3});
fprintf(fid, ' case {''logs'', ''logdir'', ''ldir''}\n');
fprintf(fid, ' preset = ''%s'';\n', folders{4});
fprintf(fid, ' case {''study''}\n');
fprintf(fid, ' preset = ''SampleStudy'';\n');
fprintf(fid, ' case {''stages''}\n');
fprintf(fid, ' preset = {''util'', ''mri'', ''meg'', ''mne'', ''granger''};\n');
fprintf(fid, ' %%preset = {''util'', ''mri'', ''meg'', ''mne'', ''plv'', ''granger''};\n');
fprintf(fid, ' case {''stage names''}\n');
fprintf(fid, ' preset = {''Utilities'', ''MRI'', ''MEG'', ''MNE'', ''Granger''};\n');
fprintf(fid, ' %%preset = {''Utilities'', ''MRI'', ''MEG'', ''MNE'', ''PLV'', ''Granger''};\n');
fprintf(fid, 'end %% switch\n');
fprintf(fid, '\nend %% function\n');
fclose(fid);
% Erase the parameters directory with everything but the sample study
answer = questdlg('Clear Parameters Folder?');
if(strcmp(answer, 'Yes'))
parameters = dir(folders{2});
for i = 1:length(parameters)
folderName = parameters(i).name;
switch folderName
case {'.', '..'}
case 'SampleStudy'
% Do nothing
case 'GPS'
% reset userstudies.mat
save([folders{2} '/GPS/userstudies.mat'], '');
otherwise
rmdir([folders{2} '/' folderName], 's')
end % switch on the folder name
end % for all parameter folders
end
% Clear images and logs folder
files = dir(folders{3});
for i_file = 1:length(files)
filename = files(i_file).name;
if(filename(1) ~= '.')
if(files(i_file).isdir)
rmdir([folders{3} '/' filename], 's');
else
delete([folders{3} '/' filename]);
end
end
end
if(~exist(folders{3}, 'dir'))
mkdir(folders{3});
end
% Clear the logs folder
if(~exist(folders{4}, 'dir'))
mkdir(folders{4});
end
delete([folders{4} '/*']);
end % function