-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaedes_resviewer.m
1160 lines (1028 loc) · 34.4 KB
/
aedes_resviewer.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function aedes_resviewer(Res_in)
% AEDES_RESVIEWER - View and convert Aedes statistics results
%
%
% Synopsis:
% aedes_resviewer(Res)
%
% Description:
% The AEDES_RESVIEWER function opens a graphical user interface (GUI) for
% handling Res-structures or *.res files saved from AEDES. If
% the function is called with the optional input argument Res, the
% GUI opens in a single-file mode. Multi-file mode is used if the
% function is called without input arguments.
%
% Examples:
% reviewer % Open the user interface
%
% % or
%
% tmp=load('resfile.res','mat'); % Read saved Res-file
% Res=tmp.Res;
% aedes_resviewer(Res) % Open the loaded Res-structure
%
% See also:
% AEDES
% This function is a part of Aedes - A graphical tool for analyzing
% medical images
%
% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
%
% Department of Physics, Department of Neurobiology
% University of Kuopio, FINLAND
%
% This program may be used under the terms of the GNU General Public
% License version 2.0 as published by the Free Software Foundation
% and appearing in the file LICENSE.TXT included in the packaging of
% this program.
%
% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
% Public variables
H = []; % Object handles
Dat = []; % GUI internal variables
Dat.SingleFileMode = false;
Dat.Res=[];
% If Res-structure is given as an input argument, go to "single-file" mode
if nargin == 1
% Check that the Res structure is valid
if isstruct(Res_in) && isfield(Res_in,'Stat') && ...
isfield(Res_in,'FileInfo') && isfield(Res_in,'DateTime')
Dat.SingleFileMode = true;
Dat.Res = Res_in;
else
error('The Res-structure is not valid!')
end
elseif nargin > 1
error('Too many input arguments')
end
l_DrawGUI;
if Dat.SingleFileMode
l_PreviewFile([],[])
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Draw GUI objects
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_DrawGUI
%% Load default font and colors
GD=aedes_gui_defaults;
fig_w = 1000;
fig_h = 600;
fig_location = aedes_dialoglocation([fig_w,fig_h]);
fig_pos = [fig_location(1) fig_location(2) fig_w fig_h];
%% Main Figure ----------------------------
H.MAINFIG = figure('Units','Pixel', ...
'position',fig_pos,...
'Name','Results viewer', ...
'Numbertitle','off', ...
'Tag','aedes_resview_fig', ...
'Color',GD.col.mainfig, ...
'Toolbar','none', ...
'Menubar','none', ...
'DockControls','off',...
'renderer','painters',...
'KeyPressFcn','',...
'CloseRequestFcn',@l_Quit,...
'Handlevisibility','off');
if ~GD.HG2graphics
set(H.MAINFIG,'DoubleBuffer','on')
end
%% Options uipanel ----------------------------
H.MAIN_UIPANEL = uipanel('parent',H.MAINFIG,...
'units','pixel',...
'position',...
[10 10 300 fig_h-2*10],...[10 fig_h-290 fig_w-2*10 280],...
'backgroundcolor',GD.col.frame);
%% Output directory and browse button --------
try
out_str = getpref('Aedes','PutXLSFileDir');
catch
out_str = pwd;
end
if Dat.SingleFileMode
edit_str = '';
enabled = 'off';
else
edit_str = out_str;
enabled = 'on';
end
tmp=get(H.MAIN_UIPANEL,'position');
H.OUTDIR_EDIT=uicontrol('parent',H.MAIN_UIPANEL,...
'style','edit',...
'position',[10 tmp(4)-20-20 240 20],...
'backgroundcolor','w',...
'horizontalalign','left',...
'string',edit_str,...
'userdata',out_str,...
'callback',@l_CheckOutputDir,...
'enable',enabled);
tmp = get(H.OUTDIR_EDIT,'position');
H.OUTDIR_TX = uicontrol('parent',H.MAIN_UIPANEL,...
'style','text',...
'position',[tmp(1) tmp(2)+tmp(4)+2 100 12],...
'string','Output Folder',...
'Horizontalalign','left',...
'enable',enabled,...
'backgroundcolor',GD.col.frame);
H.OUTPUT_BROWSE = uicontrol('parent',H.MAIN_UIPANEL,...
'style','pushbutton',...
'position',[tmp(1)+tmp(3)+5 tmp(2) 35 20],...
'string','...',...
'callback',@l_BrowseFolders,...
'enable',enabled);
%% Selected files -listbox ------------------------------------
%% Disable multi-file selection in single-file mode
if Dat.SingleFileMode
isEnabled = 'off';
else
isEnabled = 'on';
end
btn_cdata = load('aedes_cdata.mat');
tmp = get(H.OUTDIR_EDIT,'position');
H.SELFILES_UIPANEL = uipanel('parent',H.MAIN_UIPANEL,...
'units','pixel',...
'position',[tmp(1) tmp(2)-10-185 280 ...
185],...
'title','Selected Files',...
'backgroundcolor',GD.col.frame);
tmp=get(H.SELFILES_UIPANEL,'position');
H.SELFILES_LBOX = uicontrol('parent',H.SELFILES_UIPANEL,...
'units','pixel',...
'position',[60 25 tmp(3)-60-20 tmp(4)-45],...
'style','listbox',...
'backgroundcolor','w',...
'callback',@l_ListBoxCallBack,...
'min',0,...
'max',2,...
'Enable',isEnabled);
H.SHOWPATH = uicontrol('parent',H.SELFILES_UIPANEL,...
'units','pixel',...
'position',[60 7 tmp(3)-60-20 15],...
'style','checkbox',...
'value',0,...
'string','Show full path',...
'callback',@l_ShowFullPath,...
'backgroundcolor',GD.col.frame,...
'enable',isEnabled);
H.ADDFILES = uicontrol('parent',H.SELFILES_UIPANEL,...
'units','pixel',...
'position',[10 tmp(4)-20-40 40 40],...
'style','pushbutton',...
'tooltip','Add files to list',...
'CData',btn_cdata.cdata.add,...
'callback',{@l_AddRemoveFiles,'add'},...
'Enable',isEnabled);
H.REMFILES = uicontrol('parent',H.SELFILES_UIPANEL,...
'units','pixel',...
'position',[10 tmp(4)-20-2*40-17 40 40],...
'style','pushbutton',...
'tooltip','Remove selected files from list',...
'CData',btn_cdata.cdata.delete,...
'callback',{@l_AddRemoveFiles,'remove'},...
'Enable','off');
H.REMALLFILES = uicontrol('parent',H.SELFILES_UIPANEL,...
'units','pixel',...
'position',[10 tmp(4)-20-3*40-2*17 40 40],...
'style','pushbutton',...
'tooltip','Remove all files from list',...
'CData',btn_cdata.cdata.deleteall,...
'callback',{@l_AddRemoveFiles,'remove_all'},...
'Enable','off');
%% Export file types uicontrols ----------------------------
tmp = get(H.SELFILES_UIPANEL,'position');
H.EXPORT_FILETYPES_GRP = uibuttongroup('parent',H.MAIN_UIPANEL,...
'units','pixel',...
'position',[10 tmp(2)-70-10 280 70],...
'title','Export file types',...
'backgroundcolor',GD.col.frame);
if ispref('Aedes','ResViewerWriteXLS')
val = getpref('Aedes','ResViewerWriteXLS');
else
val = 1;
setpref('Aedes','ResViewerWriteXLS',val);
end
H.OUTPUTTYPE_XLS = uicontrol('parent',H.EXPORT_FILETYPES_GRP,...
'style','checkbox',...
'position',[10 30 150 15],...
'value',val,...
'string','Excel sheet (XLS)',...
'backgroundcolor',GD.col.frame);
if isunix
% Excel export is only supported in Windows...
set(H.OUTPUTTYPE_XLS,'value',0,'enable','off')
end
tmp = get(H.OUTPUTTYPE_XLS,'position');
if ispref('Aedes','ResViewerWriteTXT')
val = getpref('Aedes','ResViewerWriteTXT');
else
val = 1;
setpref('Aedes','ResViewerWriteTXT',val);
end
H.OUTPUTTYPE_TXT = uicontrol('parent',H.EXPORT_FILETYPES_GRP,...
'style','checkbox',...
'position',[10 tmp(2)-15-5 150 15],...
'value',val,...
'string','Text file (TXT)',...
'backgroundcolor',GD.col.frame);
%% Export options ------------------------------------------
tmp = get(H.EXPORT_FILETYPES_GRP,'position');
H.EXPORT_OPTIONS_GRP = uibuttongroup('parent',H.MAIN_UIPANEL,...
'units','pixel',...
'position',[10 tmp(2)-10-220 280 220],...
'title','Export options',...
'backgroundcolor',GD.col.frame);
tmp = get(H.EXPORT_OPTIONS_GRP,'position');
H.SORTBY_TX = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[10 tmp(4)-2*10-15 70 15],...
'style','text',...
'string','Sort by:',...
'horizontalalign','left',...
'backgroundcolor',GD.col.frame);
tmp=get(H.SORTBY_TX,'position');
H.SORTBY = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[280-tmp(1)-10-100 tmp(2)+3 100 15],...
'style','popup',...
'string',{'ROI','File'},...
'value',1,...
'backgroundcolor','w',...
'callback',@l_PreviewFile);
H.DECSEPARATOR_TX = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[tmp(1) tmp(2)-tmp(4)-10 ...
130 15],...
'style','text',...
'string','Decimal separator:',...
'horizontalalign','left',...
'backgroundcolor',GD.col.frame);
tmp = get(H.DECSEPARATOR_TX,'position');
try
val=getpref('Aedes','ResViewerDecSep');
catch
val=1;
setpref('Aedes','ResViewerDecSep',1);
end
H.DECSEPARATOR = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[280-tmp(1)-10-100 tmp(2)+3 100 15],...
'style','popup',...
'string',{', (comma)','. (point)'},...
'value',val,...
'backgroundcolor','w',...
'callback',@l_PreviewFile);
H.NUMDEC_TX = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[tmp(1) tmp(2)-tmp(4)-10 ...
150 15],...
'style','text',...
'string','Number of decimals:',...
'horizontalalign','left',...
'backgroundcolor',GD.col.frame);
tmp = get(H.NUMDEC_TX,'position');
if ispref('Aedes','ResViewerNumDec')
val=getpref('Aedes','ResViewerNumDec');
val = num2str(val);
else
val = '3';
end
H.NUMDEC = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[280-tmp(1)-10-100 tmp(2)-1 100 19],...
'style','edit',...
'string',val,...
'backgroundcolor','w',...
'callback',@l_PreviewFile);
% Get default print directions
if ispref('Aedes','StatPrintDirs')
Dat.dirs = getpref('Aedes','StatPrintDirs');
else
Dat.dirs = 'TXYZ';
end
if any(Dat.dirs=='T')
total_val = 1;
else
total_val = 0;
end
if any(Dat.dirs=='X')
x_val = 1;
else
x_val = 0;
end
if any(Dat.dirs=='Y')
y_val = 1;
else
y_val = 0;
end
if any(Dat.dirs=='Z')
z_val = 1;
else
z_val = 0;
end
if any(Dat.dirs=='V')
v_val = 1;
else
v_val = 0;
end
H.PRINT_TOTAL = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[tmp(1) tmp(2)-5-19 250 19],...
'style','checkbox',...
'string','Print total',...
'backgroundcolor',GD.col.frame,...
'value',total_val,...
'callback',@l_PreviewFile);
tmp = get(H.PRINT_TOTAL,'position');
H.PRINT_XDIR = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[tmp(1) tmp(2)-5-19 250 19],...
'style','checkbox',...
'string','Print X-Dir',...
'backgroundcolor',GD.col.frame,...
'value',x_val,...
'callback',@l_PreviewFile);
tmp = get(H.PRINT_XDIR,'position');
H.PRINT_YDIR = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[tmp(1) tmp(2)-5-19 250 19],...
'style','checkbox',...
'string','Print Y-Dir',...
'backgroundcolor',GD.col.frame,...
'value',y_val,...
'callback',@l_PreviewFile);
tmp = get(H.PRINT_YDIR,'position');
H.PRINT_ZDIR = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[tmp(1) tmp(2)-5-19 250 19],...
'style','checkbox',...
'string','Print Z-Dir',...
'backgroundcolor',GD.col.frame,...
'value',z_val,...
'callback',@l_PreviewFile);
tmp = get(H.PRINT_ZDIR,'position');
H.PRINT_VDIR = uicontrol('parent',H.EXPORT_OPTIONS_GRP,...
'units','pixel',...
'position',[tmp(1) tmp(2)-5-19 250 19],...
'style','checkbox',...
'string','Print V-Dir',...
'backgroundcolor',GD.col.frame,...
'value',v_val,...
'callback',@l_PreviewFile);
%% RESTABLE -----------------------------------
%ResTable=aedes_res2table('..\ROI_test\t1001001.res');
tmp=get(H.MAIN_UIPANEL,'position');
H.RESTABLE = uitable('Parent',H.MAINFIG,'position',[tmp(1)+tmp(3)+10 10 fig_w-2.5*10-tmp(3) fig_h-3*10]);
H.RESFRAME = uicontrol('parent',H.MAINFIG,...
'units','pixel',...
'style','frame',...
'position',[tmp(1)+tmp(3)+10 10 fig_w-2.5*10-tmp(3) fig_h-3*10],...
'backgroundcolor',GD.col.frame);
% Check Matlab version since uitable properties have changed in R2008a
Dat.MatlabVersion = aedes_getmatlabversion;
if Dat.MatlabVersion>=7.06
set(H.RESTABLE,'Enable','on','visible','off');
else
set(H.RESTABLE,'Editable',false,'visible',false)
end
tmp=get(H.RESTABLE,'position');
H.RESTABLE_TX = uicontrol('Parent',H.MAINFIG,...
'Units','pixel',...
'style','text',...
'position',[tmp(1) tmp(2)+tmp(4) tmp(3) 15],...
'string','Output preview ("N/A")',...
'horizontalalign','left',...
'fontweig','bold',...
'backgroundcolor',GD.col.mainfig);
% Display "Current results" text in single file mode
if Dat.SingleFileMode
set(H.RESTABLE_TX,'string','Output preview ("Current results")')
end
%% Export and Cancel buttons ----------------------
tmp=get(H.SELFILES_UIPANEL,'position');
H.EXPORT = uicontrol('parent',H.MAIN_UIPANEL,...
'units','pixel',...
'position',[tmp(1)+tmp(3)-80 5 80 25],...
'string','Export',...
'callback',@l_Export);
tmp = get(H.EXPORT,'position');
H.CANCEL = uicontrol('parent',H.MAIN_UIPANEL,...
'units','pixel',...
'position',[tmp(1)-80-5 5 80 25],...
'string','Close',...
'callback',@l_Quit);
% Some internal variable defaults
if isfield(Dat.Res,'Stat') && Dat.Res.Stat(1).isMixed==0
if strcmpi(Dat.Res.FileInfo.DataFileName{1},'fid')
[fp,fn,fe]=fileparts(Dat.Res.FileInfo.DataPathName{1}(1:end-1));
Dat.ResFileName = fn;
else
Dat.ResFileName = Dat.Res.FileInfo.DataFileName{1};
end
else
Dat.ResFileName = '';
end
Dat.OldFigSize = get(H.MAINFIG,'position');
% Set resize function
set(H.MAINFIG,'resizefcn',@l_Resize)
end % function l_DrawGUI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Resize Function
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_Resize(h,evd)
fig_pos = get(H.MAINFIG,'position');
if fig_pos(4)<400 || fig_pos(3)<400
set(H.MAINFIG,'position',Dat.OldFigSize)
return
end
tmp=get(H.MAIN_UIPANEL,'position');
set(H.MAIN_UIPANEL,'position',[tmp(1) fig_pos(4)-tmp(4)-10 tmp(3:4)]);
%set(H.MAIN_UIPANEL,'position',...
% [10 10 300 fig_pos(4)-2*10]);
main_panel_pos = get(H.MAIN_UIPANEL,'position');
set(H.RESTABLE,'position',[main_panel_pos(1)+main_panel_pos(3)+10 10 fig_pos(3)-2.5*10-main_panel_pos(3) fig_pos(4)-3*10]);
set(H.RESFRAME,'position',[main_panel_pos(1)+main_panel_pos(3)+10 10 fig_pos(3)-2.5*10-main_panel_pos(3) fig_pos(4)-3*10]);
tmp=get(H.RESFRAME,'position');
set(H.RESTABLE_TX,'position',[tmp(1) tmp(2)+tmp(4) tmp(3) 15])
% % Reposition uipanels
% tmp=get(H.MAIN_UIPANEL,'position');
% set(H.OUTDIR_EDIT,'position',[10 tmp(4)-20-20 240 20])
% tmp = get(H.OUTDIR_EDIT,'position');
% set(H.OUTDIR_TX,'position',[tmp(1) tmp(2)+tmp(4)+2 100 12])
% set(H.OUTPUT_BROWSE,'position',[tmp(1)+tmp(3)+5 tmp(2) 35 20])
%
% tmp = get(H.OUTDIR_EDIT,'position');
% set(H.SELFILES_UIPANEL,'position',[tmp(1) tmp(2)-10-185 280 185])
% tmp = get(H.SELFILES_UIPANEL,'position');
% set(H.EXPORT_FILETYPES_GRP,'position',[10 tmp(2)-70-10 280 70])
% tmp = get(H.EXPORT_FILETYPES_GRP,'position');
% set(H.EXPORT_OPTIONS_GRP,'position',[10 tmp(2)-10-220 280 220])
Dat.OldFigSize = fig_pos;
end % function l_Resize(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ADD/REMOVE FILES
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_AddRemoveFiles(h,evd,opt)
%% Add files -----------------------
if strcmpi(opt,'add')
[fname,pname]=aedes_juigetfiles({'*.res;*.RES','Aedes Res-files (*.res)';...
'*.*','All Files (*.*)'},...
'Select Res-files',pwd);
if ~iscell(fname)
% Canceled
return
end
%% Add selected files to the list
FileList = get(H.SELFILES_LBOX,'string');
FileListUD = get(H.SELFILES_LBOX,'userdata');
if isempty(FileList)
if get(H.SHOWPATH,'value')
tmpstr = {};
for ii=1:length(fname)
tmpstr{ii} = [pname{ii},fname{ii}];
end
set(H.SELFILES_LBOX,'string',tmpstr);
else
set(H.SELFILES_LBOX,'string',fname);
end
FileListNewUD=cell(length(fname),2);
FileListNewUD(:,1) = pname(:);
FileListNewUD(:,2) = fname(:);
set(H.SELFILES_LBOX,'userdata',FileListNewUD)
else
FileListNewUD=cell(length(fname),2);
FileListNewUD(:,1) = pname(:);
FileListNewUD(:,2) = fname(:);
%% Remove dublicates
tmp={FileListUD{all(ismember(FileListUD, ...
FileListNewUD),2),:}};
rm_ind=find(all(ismember(FileListNewUD,tmp),2));
if ~isempty(rm_ind)
isDublicate = true;
DublicateList = FileListNewUD(rm_ind,:);
FileListNewUD(rm_ind,:)=[];
else
isDublicate = false;
DublicateList = {};
end
NewFileList = cell(size(FileListUD,1)+size(FileListNewUD,1),2);
NewFileList(1:size(FileListUD,1),:)=FileListUD;
NewFileList(size(FileListUD,1)+1:end,:)=FileListNewUD;
if get(H.SHOWPATH,'value')
FileListNewCell={}
for ii=1:size(NewFileList,1)
FileListNewCell{ii} = [NewFileList{:,1},NewFileList{:,2}];
end
else
FileListNewCell = {NewFileList{:,2}};
end
set(H.SELFILES_LBOX,'string',FileListNewCell);
set(H.SELFILES_LBOX,'userdata',NewFileList);
set(H.SELFILES_LBOX,'value',[]);
%% Warn about dublicates that were not added to the list
if isDublicate
warndlg({'The following dublicate files were ignored:',...
'',DublicateList{:,2}},...
'Dublicate files ignored','modal');
end
end
% Enable remove buttons
set([H.REMFILES,H.REMALLFILES],'enable','on')
%% Remove files ------------------
elseif strcmpi(opt,'remove')
% Ask confirmation
resp=questdlg('Remove selected files from list?',...
'Remove selected files?','Yes','No','No');
if strcmpi(resp,'No')
return
end
val = get(H.SELFILES_LBOX,'value');
str = get(H.SELFILES_LBOX,'string');
% Return if files are not selected
if isempty(val)
return
end
NewStr = str;
NewUD = get(H.SELFILES_LBOX,'userdata');
NewStr(val)=[];
NewUD(val,:)=[];
set(H.SELFILES_LBOX,'value',[],'string',NewStr,...
'userdata',NewUD)
if isempty(NewStr)
% Disable remove buttons
set([H.REMFILES,H.REMALLFILES],'enable','off')
end
% Check if preview needs to be cleared
if ~isempty(Dat.ResFileName) && ~isempty(NewUD)
[fp,fn,fe]=fileparts(Dat.ResFileName);
fp = [fp,filesep];
fn = [fn,fe];
tmp1 = strcmp(fn,{NewUD{:,2}});
tmp2 = strcmp(fp,{NewUD{:,1}});
tmp1=tmp1(:);
tmp2=tmp2(:);
bool=prod(double([tmp2 tmp1]),2);
if ~any(bool==1)
l_ResetPreview([],[])
end
else
l_ResetPreview([],[])
end
%% Remove ALL files --------------
elseif strcmpi(opt,'remove_all')
% Ask confirmation
resp=questdlg('Remove ALL files from list?',...
'Remove ALL files?','Yes','No','No');
if strcmpi(resp,'No')
return
end
set(H.SELFILES_LBOX,'value',[],'string',{},'userdata',{})
set([H.REMFILES,H.REMALLFILES],'enable','off')
% Clear preview
l_ResetPreview([],[])
end
end % function l_AddRemoveFiles(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% LISTBOX CALLBACK
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_ListBoxCallBack(h,evd)
% Return immediately if not double-clicked
SelType = get(H.MAINFIG,'selectiontype');
if ~strcmpi(SelType,'open')
return
end
% Set mouse pointer to hourglass
set(H.MAINFIG,'pointer','watch')
drawnow
% Get file for preview
val=get(H.SELFILES_LBOX,'value');
if length(val)==0 || length(val)>1
set(H.MAINFIG,'pointer','arrow')
return
end
UD = get(H.SELFILES_LBOX,'userdata');
fname = [UD{val,1},UD{val,2}];
% Try to load Res-file
try
tmp = load(fname,'-mat');
catch
errordlg({'Could not open Res-file',fname,...
'','Either the file is not a valid Res-file or it is corrupt.'},...
'Could not open Res-file','modal');
set(H.MAINFIG,'pointer','arrow')
return
end
if ~isfield(tmp,'Res') || ~isfield(tmp.Res,'Stat') || ...
~isfield(tmp.Res,'FileInfo') || ~isfield(tmp.Res,'DateTime')
errordlg({'Could not open Res-file',fname,...
'','Required fields are missing from the structure!'},...
'Could not open Res-file','modal');
set(H.MAINFIG,'pointer','arrow')
return
end
Dat.Res = tmp.Res;
Dat.ResFileName = fname;
% Preview file
l_PreviewFile([],[]);
set(H.MAINFIG,'pointer','arrow')
drawnow
end % function l_ListBoxCallBack(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PREVIEW FILE
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_PreviewFile(h,evd)
if isempty(Dat.Res)
return
end
% Get export options
sortbyroi = get(H.SORTBY,'value');
if sortbyroi==1
sortbyroi = true;
else
sortbyroi = false;
end
decsepval = get(H.DECSEPARATOR,'value');
setpref('Aedes','ResViewerDecSep',decsepval)
if decsepval==1
decsep = ',';
else
decsep = '.';
end
numdec = get(H.NUMDEC,'string');
numdec = str2num(numdec);
numdec = floor(numdec);
if isempty(numdec) || ~isreal(numdec) || numdec<0
errordlg('The "Number of decimals" value must be a positive integer!',...
'Error in "Number of decimals" field','modal')
return
end
% Get print directions
Dat.dirs = '';
if get(H.PRINT_TOTAL,'value')
Dat.dirs(end+1) = 'T';
end
if get(H.PRINT_XDIR,'value')
Dat.dirs(end+1) = 'X';
end
if get(H.PRINT_YDIR,'value')
Dat.dirs(end+1) = 'Y';
end
if get(H.PRINT_ZDIR,'value')
Dat.dirs(end+1) = 'Z';
end
if get(H.PRINT_VDIR,'value')
Dat.dirs(end+1) = 'V';
end
% Save number of decimals
setpref('Aedes','ResViewerNumDec',numdec)
% Save printed directions
setpref('Aedes','StatPrintDirs',Dat.dirs)
% Generate cell table from Res
ResTable = aedes_res2table(Dat.Res,'sortbyroi',sortbyroi,...
'decsep',decsep,'numdec',numdec,...
'resfilename',Dat.ResFileName,...
'dirs',Dat.dirs);
set(H.RESFRAME,'visible','off')
drawnow
drawnow
% Clear restable
if Dat.MatlabVersion>=7.06
set(H.RESTABLE,'data',[])
set(H.RESTABLE,'Data',ResTable,...
'visible','on',...
'ColumnWidth',...
{140,80,80,80,80,80,80},...
'ColumnFormat',repmat({'char'},1,7),...
'ColumnName',[])
else
set(H.RESTABLE,'NumRows',2,...
'NumColumns',2);
drawnow
drawnow
tmp={'','';'',''};
set(H.RESTABLE,'Data',tmp)
drawnow
drawnow
% Update res table
set(H.RESTABLE,'visible',true)
drawnow
drawnow
set(H.RESTABLE,'NumRows',size(ResTable,1),...
'NumColumns',size(ResTable,2))
drawnow
drawnow
set(H.RESTABLE,'Data',ResTable);
drawnow
drawnow
end
%drawnow
if ~Dat.SingleFileMode
set(H.RESTABLE_TX,'string',['Output preview ("' Dat.ResFileName '")'])
end
end % function l_PreviewFiles(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RESET FILE PREVIEW
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_ResetPreview(h,evd)
Dat.Res = [];
Dat.ReFileName = '';
if Dat.MatlabVersion>=7.06
set(H.RESTABLE,'visible','off',...
'Data',[]);
else
set(H.RESTABLE,'visible',false,...
'Data',[]);
end
set(H.RESFRAME,'visible','on')
set(H.RESTABLE_TX,'string','Output preview ("N/A")')
drawnow
end % function l_ResetPreview(h,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% EXPORT RESULTS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function l_Export(h,evd)
% Check if there is something to export
if ~Dat.SingleFileMode
UD = get(H.SELFILES_LBOX,'userdata');
if isempty(UD)
h=errordlg('Nothing to export!','Error Exporting Files','modal');
return
end
end
% Get Export types
WriteXLS = get(H.OUTPUTTYPE_XLS,'value');
WriteTXT = get(H.OUTPUTTYPE_TXT,'value');
if ~WriteXLS && ~WriteTXT
h=errordlg('Export file type not selected!','Error Exporting Files','modal');
return
end
% Save values to preferences
setpref('Aedes','ResViewerWriteXLS',WriteXLS)
setpref('Aedes','ResViewerWriteTXT',WriteTXT)
% Get export parameters
outdir = get(H.OUTDIR_EDIT,'string');
if ~isempty(outdir) && outdir(end)~=filesep
outdir = [outdir,filesep];
end
sortbyroi = get(H.SORTBY,'value');
if sortbyroi==1
sortbyroi = true;
else
sortbyroi = false;
end
decsepval = get(H.DECSEPARATOR,'value');
if decsepval==1
decsep = ',';
else
decsep = '.';
end
numdec = get(H.NUMDEC,'string');
numdec = str2num(numdec);
numdec = floor(numdec);
if isempty(numdec) || ~isreal(numdec) || numdec<0
errordlg('The "Number of decimals" value must be a positive integer!',...
'Error in "Number of decimals" field','modal')
return
end
%% Start Exporting files --------------------------
if ~Dat.SingleFileMode
wbar_h=aedes_wbar(0,{'Processing file','""'});
set(get(findall(wbar_h,'type','axes'),'title'),'interpreter','none')
nFiles = size(UD,1);
success = true(1,nFiles);
for ii=1:nFiles
resfilename = [UD{ii,1},UD{ii,2}];
[fp,fn,fe]=fileparts(UD{ii,2});
outfilename = [outdir,fn];
aedes_wbar(ii/nFiles,wbar_h,{'Processing file',['"',resfilename,'"']});
% Open file
try
tmp = load([UD{ii,1},UD{ii,2}],'-mat');
catch
success(ii)=false;
fprintf(1,'Could not open file "%s". Skipping...\n',resfilename)
continue;
end
if ~isfield(tmp,'Res') || ~isfield(tmp.Res,'Stat') || ...
~isfield(tmp.Res,'FileInfo') || ~isfield(tmp.Res,'DateTime')
success(ii)=false;
fprintf(1,'Required field(s) missing! Skipping file "%s".\n',...
resfilename)
continue;
end
% Generate cell table
ResTable = aedes_res2table(tmp.Res,'sortbyroi',sortbyroi,...
'decsep',decsep,'numdec',numdec,...
'resfilename',resfilename,...
'dirs',Dat.dirs);
% Write XLS
if WriteXLS
bool = xlswrite([outfilename,'.xls'],ResTable);
if ~bool
success(ii)=false;
fprintf(1,'Could not write "%s". Skipping file...\n',[outfilename,'.xls'])
end
end
% Write TXT
if WriteTXT
bool = aedes_cellwrite(ResTable,[outfilename,'.txt'],...
'delimitter','tab');
if ~bool
success(ii)=false;
fprintf(1,'Could not write "%s". Skipping file...\n',[outfilename,'.txt'])
end
end
end
close(wbar_h)
if all(success)
h=helpdlg(['Successfully exported ',num2str(nFiles),' files!'],...
'Export Success');
else
SkippedFiles={};
count=1;
for ii=1:nFiles
if success(ii)==0
SkippedFiles{count} = [UD{ii,1},UD{ii,2}];
count=count+1;
end
end
h=warndlg({['Errors occurred while exporting.',...
' The following files could not be exported:'],'',...
SkippedFiles{:}},'Errors occurred while exporting');
end
% Save export directory to preferences
setpref('Aedes','PutXLSFileDir',outdir);
else % Export in single file mode
success = true;
try
outdir = getpref('Aedes','PutXLSFileDir');
catch
outdir = pwd;
end
if ~strcmp(outdir(end),filesep)
outdir = [outdir,filesep];
end
%[fp,fn,fe]=fileparts(Dat.Res.FileInfo.DataFileName{1});
% Ask for a file
[fname,fpath,findex]=uiputfile({'*.xls;*.XLS;*.txt;*.TXT',...
'Excel and Text Files (*.xls,*.txt)';...
'*.*','All Files (*.*)'},'Export Results As',...
[outdir,Dat.ResFileName]);
if isequal(fname,0) || isequal(fpath,0)
% Action cancelled
return
end
% Check filename
CheckXLS = true;
CheckTXT = true;
[fp,fn,fe]=fileparts(fname);
if strcmpi(fe,'.xls')
CheckXLS = false;
xlsfname = [fn,fe];
txtfname = [fn,'.txt'];
elseif strcmpi(fe,'.txt')
CheckTXT = false;