-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckHeaderCB.m
More file actions
176 lines (176 loc) · 8.43 KB
/
checkHeaderCB.m
File metadata and controls
176 lines (176 loc) · 8.43 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
% Callback function for checkHeaderGUI. Apart from the 'metaData', which
% is part of the 'UserData' variable of the current figure, uses paths
% structures 'Survey' and 'original', and a two-dimensional array 'Data',
% which are all assumed defined.
hcb = gcbo;
hfig = get(hcb,'Parent');
SavedMetaData = get(hfig,'UserData');
UIstyle = get(hcb,'style');
UItag = get(hcb,'tag');
fileRoot = SavedMetaData.edited.runID;
task = SavedMetaData.task;
getOS;
switch UIstyle
case 'pushbutton'
switch UItag
case 'OK'
% check edited meta data; make sure it is written out
updateUserData(hfig);
SavedMetaData = get(hfig,'UserData');
[metaData,clean] = cleanMetaData(SavedMetaData.edited);
reloadMetaData(hfig,metaData);
if clean
% write *.xml file
xml_file = [original.Path metaData.runID];
writeMetaData(metaData,xml_file);
% activate PLOT/PROCESS pushbuttons
button = findobj(hfig,'tag','PLOT');
set(button,'Enable','on');
button = findobj(hfig,'tag','PROCESS');
set(button,'Enable','on');
else
% deactivate PLOT/PROCESS pushbuttons
button = findobj(hfig,'tag','PLOT');
set(button,'Enable','off');
button = findobj(hfig,'tag','PROCESS');
set(button,'Enable','off');
end
if ~isempty(metaData.runID)
cd (original.Path);
save (metaData.runID, 'metaData',...
'Header','Data','GPS','README', ...
'seq','stat','tBox','tHead',...
'dupl','duplData','spike','spikeData','iERR','-v7.3');
end
case 'RESTORE'
% delete figure; create new figure with unedited fields
delete(hfig)
checkHeaderGUI(SavedMetaData.raw);
case 'PLOT'
% uses Data and metaData to run TSplot
plotData
case 'PROCESS'
% go to data directory and write a *.bin file
% always write the *.bin file even if it already exists
% (something could have changed, e.g. gain)
hwb = waitbar(0,'Writing temporary data files needed for processing...');
cd (Survey.data);
binFile = [fileRoot '.bin'];
writeNIMSbin(Data,metaData,binFile);
% call processing steps -- will only work if you have EMTF
% utilities in your path & if Matlab is called from a linux
% environment or cygwin
if exist(Survey.CF,'dir')==0;
errors = ['For processing, please copy EMTF/CF to ' Survey.home];
waitbar(0,hwb,errors);
SavedMetaData.edited.errors = errors;
reloadMetaData(hfig,SavedMetaData.edited);
set(hfig,'UserData',SavedMetaData);
else
waitbar(1/4,hwb,'Starting data processing. This might take some time...');
disp('Starting data processing. This might take some time...')
% go to SP directory and write a *.sp file
if ~exist(Survey.SP,'dir'); mkdir(Survey.SP); end
cd (Survey.SP);
writeSp(metaData,fileRoot);
% go back to the root directory and start data processing
cd (Survey.home);
% a) run dnff
if ~exist(Survey.FC,'dir'); mkdir(Survey.FC); end
fid = fopen('dnff.cfg','w');
fprintf(fid,'%s\n',binFile);
fprintf(fid,'n\n');
fclose(fid);
MTbin = getenv('MTbin');
if ~isempty(MTbin)
if ~strcmp(MTbin(end),'/')
MTbin = [MTbin '/'];
end
end
disp(['cd ' Survey.home '; ' cmd MTbin 'dnff -B < dnff.cfg']);
[status, output] = system([cmd MTbin 'dnff -B < dnff.cfg']); %#ok<NASGU>
if status~=0
waitbar(1,hwb,['System command ' MTbin 'dnff -B < dnff.cfg failed. Exiting...']);
disp('Error; type "output" to debug');
error('Unable to run dnff. Exiting...');
else
waitbar(3/4,hwb,['System command ' MTbin 'dnff -B < dnff.cfg completed']);
end
% b) create tranmt.cfg
if metaData.nsec > 3600*24*60 % > 2 months of data
optionsFile = 'options_bb_SS.cfg';
elseif round(1/metaData.dt) == 8 % 8 Hz data
optionsFile = 'options_8hz_SS.cfg';
elseif round(1/metaData.dt) == 1024 % 1kHz data
optionsFile = 'options_1khz_SS.cfg';
else
optionsFile = 'options_1hz_SS.cfg';
end
CFdir = relativepath(Survey.CF,Survey.home);
fid = fopen('tranmt.cfg','w');
fprintf(fid,'%s\n',fileRoot);
fprintf(fid,'%s\n',[CFdir optionsFile]);
fprintf(fid,'1\n');
fprintf(fid,'1 5\n');
fprintf(fid,'%s\n',[fileRoot '.f5']);
fprintf(fid,'n\n');
fclose(fid);
% c) run tranmtlr
if ~exist(Survey.MT,'dir'); mkdir(Survey.MT); end
% NB: for some reason the pipe
% echo tranmt.cfg | tranmtlr
% is not working from Matlab+Cygwin; using a workaround
disp(['cd ' Survey.home '; ' cmd MTbin 'tranmtlr -ftranmt.cfg']);
[status, output] = system([cmd MTbin 'tranmtlr -ftranmt.cfg']);
if status~=0
waitbar(1,hwb,['System command ' MTbin 'tranmtlr -ftranmt.cfg failed. Exiting...']);
disp('Error; type "output" to debug');
error('Unable to run tranmtlr. Exiting...');
else
waitbar(1,hwb,'Processing successful. Plotting the transfer functions...');
end
% d) run apresplt.m to plot transfer functions
MKPLTIND = 'pltind = [pltind; ones(nbt,1)];';
cdir = Survey.MT; cfile = [fileRoot '.zss']; z_mtem
if (polx || poly)
hw=warndlg({'Check polarity of both electrodes';...
' and write a detailed comment!!!'},'FIELD CHECK !!!');
set(hw,'color','r');
end
close(hwb);
end
case 'SAVE TO XML'
% only called when the task is 'xmlEdit'
updateUserData(hfig);
SavedMetaData = get(hfig,'UserData');
[metaData,clean] = cleanMetaData(SavedMetaData.edited);
reloadMetaData(hfig,metaData);
[file,path] = uiputfile('*.xml','Save Meta Data as XML file',[fileRoot '.xml']);
xml_file = fullfile(path,file);
writeMetaData(metaData,xml_file);
case 'CLOSE'
% delete figure
delete(hfig);
case 'QUIT'
% delete all open figures
delete(get(0,'Children'));
end
case 'checkbox'
switch UItag
case 'GPS EDIT'
gpsEdit(hfig,get(hcb,'value'));
otherwise % nothing
end
case 'edit'
newValue = get(hcb,'string');
% modify SavedMetaData.edited as required
editHeaderCB;
SavedMetaData.edited.GPS_ERROR = 1;
reloadMetaData(hfig,SavedMetaData.edited);
set(hfig,'UserData',SavedMetaData);
% deactivate PLOT/PROCESS pushbuttons until we click 'OK'
button = findobj(hfig,'tag','PLOT');
set(button,'Enable','off');
button = findobj(hfig,'tag','PROCESS');
set(button,'Enable','off');
end