forked from sspagnol/easyplot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easyplot.m
1715 lines (1454 loc) · 57.7 KB
/
easyplot.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 varargout = easyplot(varargin)
%EASYPLOT MATLAB code for oceanographic field data viewing using
%imos-toolbox parser routines.
% EASYPLOT, by itself, creates a new EASYPLOT or raises the existing
% singleton*.
%
% H = EASYPLOT returns the handle to a new EASYPLOT or the handle to
% the existing singleton*.
%
% EASYPLOT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EASYPLOT.M with the given input arguments.
%
% EASYPLOT('Property','Value',...) creates a new EASYPLOT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before easyplot_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to easyplot_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help easyplot
% Last Modified by GUIDE v2.5 20-Oct-2015 13:05:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @easyplot_OpeningFcn, ...
'gui_OutputFcn', @easyplot_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end
%% --- Executes just before easyplot is made visible.
function easyplot_OpeningFcn(hObject, eventdata, userData, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to easyplot (see VARARGIN)
% Choose default command line output for easyplot
hFig=ancestor(hObject,'figure');
gData = guidata(hFig);
userData=getappdata(hFig,'UserData');
userData.output = hObject;
% white background
set(gData.figure1,'Color',[1 1 1]);
% create easyplot toolbar
set(gData.figure1,'Toolbar','figure');
%hpt = uipushtool(ht,'CData',icon,'TooltipString','Hello')
userData.xMin=NaN;
userData.xMax=NaN;
userData.yMin=NaN;
userData.yMax=NaN;
% old path for easier importing
[userData.EPdir, name, ext] = fileparts(mfilename('fullpath'));
userData.oldPathname=userData.EPdir;
userData.ini = ini2struct(fullfile(userData.EPdir,'easyplot.ini'));
try
thePath=userData.ini.startDialog.dataDir;
if exist(thePath)
userData.oldPathname=thePath;
end
end
% This is what I am working toward, parsers can be 'queried' for some info
% and file extensions supported
% parsers=listParsers;
% structs={};
% for ii=1:numel(parsers)
% parser=getParser(parsers{ii});
% structs{end+1}=parser('info');
% end
% aStr=cellfun(@(x) x.short_message, structs, 'UniformOutput', false);
% [choice, idx]=optionDialog('Choose instument type','Choose instument type',aStr,1);
%
% But for the moment have this list of instruments and their parsers
ii=0;
% csv file of fully qualified filename and parser to use
ii=ii+1;
parserList.name{ii}='File list (csv)';
parserList.wildcard{ii}={'*.csv'};
parserList.message{ii}='Choose file list:';
parserList.parser{ii}='fileListParse';
ii=ii+1;
parserList.name{ii}='Citadel CTD (csv)';
parserList.wildcard{ii}={'*.csv'};
parserList.message{ii}='Choose Citadel CTD csv files:';
parserList.parser{ii}='citadelParse';
ii=ii+1;
parserList.name{ii}='HOBO U22 Temp (txt)';
parserList.wildcard{ii}={'*.txt'};
parserList.message{ii}='Choose HOBO U22 txt files:';
parserList.parser{ii}='hoboU22Parse';
ii=ii+1;
parserList.name{ii}='Netcdf IMOS toolbox (nc)';
parserList.wildcard{ii}={'*.nc'};
parserList.message{ii}='Choose Netcdf *.nc files:';
parserList.parser{ii}='netcdfParse';
ii=ii+1;
parserList.name{ii}='Netcdf Other (nc)';
parserList.wildcard{ii}={'*.nc'};
parserList.message{ii}='Choose Netcdf *.nc files:';
parserList.parser{ii}='netcdfOtherParse';
ii=ii+1;
parserList.name{ii}='Nortek AWAC (wpr,wpb)';
parserList.wildcard{ii}={'*.wpr', '*.wpb'};
parserList.message{ii}='Choose Nortek *.wpr, *.wpb files:';
parserList.parser{ii}='awacParse';
ii=ii+1;
parserList.name{ii}='Nortek Continental (wpr,wpb)';
parserList.wildcard{ii}={'*.wpr', '*.wpb'};
parserList.message{ii}='Choose Nortek *.wpr, *.wpb files:';
parserList.parser{ii}='continentalParse';
ii=ii+1;
parserList.name{ii}='Nortek Aquadopp Velocity (aqd)';
parserList.wildcard{ii}={'*.aqd'};
parserList.message{ii}='Choose Nortek *.aqd files:';
parserList.parser{ii}='aquadoppVelocityParse';
ii=ii+1;
parserList.name{ii}='Nortek Aquadopp Profiler (prf)';
parserList.wildcard{ii}={'*.prf'};
parserList.message{ii}='Choose Nortek *.prf files:';
parserList.parser{ii}='aquadoppProfilerParse';
ii=ii+1;
parserList.name{ii}='RBR (txt,dat)';
parserList.wildcard{ii}={'*.txt', '*.dat'};
parserList.message{ii}='Choose TR1060/TDR2050 files:';
parserList.parser{ii}='XRParse';
ii=ii+1;
parserList.name{ii}='Reefnet Sensus (csv)';
parserList.wildcard{ii}={'*.csv'};
parserList.message{ii}='Choose SensusUltra files:';
parserList.parser{ii}='sensusUltraParse';
ii=ii+1;
parserList.name{ii}='Teledyne RDI (000,PD0)';
parserList.wildcard{ii}={'*.000', '*.PD0'};
parserList.message{ii}='Choose RDI 000/PD0 files:';
parserList.parser{ii}='workhorseParse';
ii=ii+1;
parserList.name{ii}='SBE37 (asc)';
parserList.wildcard{ii}={'*.asc'};
parserList.message{ii}='Choose SBE37 files:';
parserList.parser{ii}='SBE37Parse';
ii=ii+1;
parserList.name{ii}='SBE37 (cnv)';
parserList.wildcard{ii}={'*.cnv'};
parserList.message{ii}='Choose SBE37 files:';
parserList.parser{ii}='SBE37SMParse';
ii=ii+1;
parserList.name{ii}='SBE39 (asc)';
parserList.wildcard{ii}={'*.asc'};
parserList.message{ii}='Choose SBE39 asc files:';
parserList.parser{ii}='SBE39Parse';
ii=ii+1;
parserList.name{ii}='SBE56 (cnv)';
parserList.wildcard{ii}={'*.cnv'};
parserList.message{ii}='Choose SBE56 cnv files:';
parserList.parser{ii}='SBE56Parse';
ii=ii+1;
parserList.name{ii}='SBE CTD (cnv)';
parserList.wildcard{ii}={'*.cnv'};
parserList.message{ii}='Choose CTD cnv files:';
parserList.parser{ii}='SBE19Parse';
ii=ii+1;
parserList.name{ii}='StarmonMini (dat)';
parserList.wildcard{ii}={'*.dat'};
parserList.message{ii}='Choose StarmonMini dat files:';
parserList.parser{ii}='StarmonMiniParse';
ii=ii+1;
parserList.name{ii}='Vemco Minilog-II-T (csv)';
parserList.wildcard{ii}={'*.csv'};
parserList.message{ii}='Choose VML2T *.csv files:';
parserList.parser{ii}='VemcoParse';
ii=ii+1;
parserList.name{ii}='Wetlabs (FL)NTU (raw)';
parserList.wildcard{ii}={'*.raw'};
parserList.message{ii}='Choose (FL)NTU *.raw files:';
parserList.parser{ii}='ECOTripletParse';
ii=ii+1;
parserList.name{ii}='WQM (dat)';
parserList.wildcard{ii}={'*.dat'};
parserList.message{ii}='Choose WQM files:';
parserList.parser{ii}='WQMParse';
userData.parserList=parserList;
userData.firstPlot = true;
axesInfo.Linked = gData.axes1;
axesInfo.mdformat = 'dd-mmm';
axesInfo.Type = 'dateaxes';
axesInfo.XLabel = 'Time (UTC)';
% why does axes UserData get wiped somewhere later?
axH=handle(gData.axes1);
set(axH, 'UserData', axesInfo);
set(axH, 'XLim', [floor(now) floor(now)+1]);
userData.axesInfo=axesInfo;
% Couldn't get easyplot to function correctly so pulled in code from
% dynamicDateTick into easyplot and modified as required.
%dynamicDateTicks(handles.axes1, [], 'dd-mmm','UseDataTipCursor',false);
% Tried a callback on zoom/pan and XLim listener but that just cause
% massive confusion. At the moment just call updateDateLabel as required,
% if I look into this again think I will create seperate callbacks
% for ActionPostCallback and PostSet XLim listener, which would then
% call common updateDateLabel
z = zoom(hFig);
p = pan(hFig);
set(z,'ActionPostCallback',@updateDateLabel);
set(p,'ActionPostCallback',@updateDateLabel);
%handles.lisH=addlistener(handles.axes1, 'XLim', 'PostSet', @updateDateLabel);
xlabel(gData.axes1,'Time (UTC)');
%hoverlines( handles.figure1 );
% custome data tip with nicely formatted date
dcm_h = datacursormode(gData.figure1);
set(dcm_h, 'UpdateFcn', @customDatacursorText)
% callback for mouse click on plot
set(hFig,'WindowButtonDownFcn', @mouseDownListener);
% Dummy treeTable data
userData.treePanelData{1,1}='None';
userData.treePanelData{1,2}='None';
userData.treePanelData{1,3}='None';
userData.treePanelData{1,4}=false;
userData.treePanelData{1,5}=0;
userData.treePanelHeader = {'','Instrument','Variable','Show','Slice'};
userData.treePanelColumnTypes = {'','char','char','logical','integer'};
userData.treePanelColumnEditable = {false, false, true, true};
userData.jtable = createTreeTable(gData, userData);
setappdata(hFig, 'UserData', userData);
% Call once to ensure proper formatting
updateDateLabel(hFig,struct('Axes', axH), true);
end
%% --- Outputs from this function are returned to the command line.
function varargout = easyplot_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.figure1;
end
%% --- Executes on button press in pushbutton1.
function import_Callback(hObject, eventdata, oldHandles)
%IMPORT_CALLBACk select instrument files to import
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
persistent hash;
if isempty(hash)
hash = java.util.Hashtable;
end
if ~isempty(hash.get(hObject))
return;
end
hash.put(hObject,1);
hFig=ancestor(hObject,'figure');
userData=getappdata(hFig,'UserData');
gData = guidata(hFig);
parserList=userData.parserList;
iParse=menu('Choose instrument type',parserList.name);
if iParse < 1 % no instrument chosen
return;
end
if iParse == 1
% load csv with
% column 1 : fully qualified data file
% column 2 : imos toolbox parser to use
[theFile, thePath, FILTERINDEX] = uigetfile('*.csv', parserList.message{iParse}, 'MultiSelect','off');
fileID = fopen(fullfile(thePath,theFile));
C = textscan(fileID, '%s%s', 'Delimiter', ',');
fclose(fileID);
[FILEpaths, FILEnames, FILEexts] = cellfun(@(x) fileparts(x), C{1}, 'UniformOutput', false);
FILEparsers = C{2};
clear('C');
else
% user selected files for one particular instrument type
filterSpec=fullfile(userData.oldPathname,strjoin(parserList.wildcard{iParse},';'));
pause(0.1); % need to pause to get uigetfile to operate correctly
[theFiles, thePath, FILTERINDEX] = uigetfile(filterSpec, parserList.message{iParse}, 'MultiSelect','on');
if size(theFiles,1) ==1
theFiles = cellstr(theFiles);
thePath = cellstr(thePath);
end
[FILEpaths, FILEnames, FILEexts] = cellfun(@(x) fileparts(x), fullfile(thePath, theFiles), 'UniformOutput', false);
FILEparsers(true(size(FILEnames))) = {parserList.parser{iParse}};
end
%utcOffsets = askUtcOffset(FILENAME);
userData.oldPathname=thePath;
if isequal(FILEnames,0) || isequal(thePath,0)
disp('No file selected.');
else
% if ischar(FILEnames)
% FILEnames = {FILEnames};
% end
if ~isfield(userData,'sample_data')
userData.sample_data={};
end
iFailed=0;
notLoaded=false;
nFiles = length(FILEnames);
for ii=1:nFiles
theFile = char([FILEnames{ii} FILEexts{ii}]);
if isempty(FILEpaths{ii})
theFullFile = which([FILEnames{ii} FILEexts{ii}]);
else
theFullFile = char(fullfile(FILEpaths{ii},[FILEnames{ii} FILEexts{ii}]));
end
% skip any files the user has already imported
notLoaded = ~any(cell2mat((cellfun(@(x) ~isempty(strfind(x.easyplot_input_file, theFile)), userData.sample_data, 'UniformOutput', false))));
if notLoaded
try
set(gData.progress,'String',strcat({'Loading : '}, theFile));
drawnow;
disp(['importing file ', num2str(ii), ' of ', num2str(nFiles), ' : ', theFile]);
% adopt similar code layout as imos-toolbox importManager
% get parser for the filetype
parser = str2func(FILEparsers{ii});
structs = {parser( {theFullFile}, 'TimeSeries' )};
if numel(structs) == 1
% only one struct generated for one raw data file
tmpStruct = finaliseDataEasyplot(structs{1}, theFullFile);
userData.sample_data{end+1} = tmpStruct;
clear('tmpStruct');
else
% one data set may have generated more than one sample_data struct
% eg AWAC .wpr with waves in .wap etc
for k = 1:length(structs)
tmpStruct = finaliseDataEasyplot(structs{k}, theFullFile);
userData.sample_data{end+1} = tmpStruct;
clear('tmpStruct');
end
end
clear('structs');
set(gData.progress,'String',strcat({'Loaded : '}, theFile));
drawnow;
catch ME
astr=['Importing file ', theFile, ' failed due to an unforseen issue. ' ME.message];
disp(astr);
set(gData.progress,'String',astr);
drawnow;
setappdata(hFig, 'UserData', userData);
uiwait(msgbox(astr,'Cannot parse file','warn','modal'));
iFailed=1;
end
else
disp(['File ' theFile ' already loaded.']);
set(gData.progress,'String',strcat({'Already loaded : '}, theFile));
drawnow;
end
end
%setappdata(ancestor(hObject,'figure'), 'UserData', userData);
userData.sample_data = timeOffsetPP(userData.sample_data, 'raw', false);
set(gData.listbox1,'String', getFilelistNames(userData.sample_data),'Value',1);
%setappdata(hFig, 'UserData', userData);
set(gData.progress,'String','Finished importing.');
setappdata(hFig, 'UserData', userData);
drawnow;
if numel(FILEnames)~=iFailed
plotVar=chooseVar(userData.sample_data);
userData.sample_data = markPlotVar(userData.sample_data, plotVar);
userData.treePanelData = generateTreeData(userData.sample_data);
setappdata(ancestor(hObject,'figure'), 'UserData', userData);
% if isfield(handles,'jtable')
% %delete(handles.jtable);
% handles.jtable.getModel.getActualModel.getActualModel.setRowCount(0);
% end
userData.jtable = createTreeTable(gData, userData);
%% trying to just change the table data and redraw
% [data,headers] = getTableData(handles.jtable);
% setTableData(jtable,handles.treePanelData,headers);
% jt.setModel(javax.swing.table.DefaultTableModel(handles.treePanelData,{'','Instrument','Variable','Show','Slice'}));
% model.setDataVector(tdc,num2cell(handles.treePanelHeader));
% model.groupAndRefresh;
% jt.repaint;
% model=handles.jtable.getModel.getActualModel.getActualModel;
% td = model.getDataVector.toArray.cell;
% tdc = cellfun(@(c)c.toArray.cell, td, 'uniform',false);
% jData=java.util.Vector(size(handles.treePanelData,1));
% for ii = 1 : size(handles.treePanelData,1)
% jVec = java.util.Vector(size(handles.treePanelData,2));
% for jj = 1 : size(handles.treePanelData,2)
% jVec.add(handles.treePanelData{ii,jj});
% end
% jData.addElement(jVec);
% clear('jVec');
% end
%
% jHeader= java.util.Vector(numel(handles.treePanelHeader));
% for ii = 1 : numel(handles.treePanelHeader)
% jHeader.add(handles.treePanelHeader{ii});
% end
%
% jt=handles.jtable;
% jt.setModel(javax.swing.table.DefaultTableModel(jData,jHeader));
% %jt.setModel(MultiClassTableModel(jData,jHeader));
% CustomizableCellRenderer
% javax.swing.table.DefaultTableCellRenderer
% % model=handles.jtable.getModel.getActualModel.getActualModel
% % model.groupAndRefresh;
% mmodel = jt.getModel
% jmodel = com.jidesoft.grid.DefaultGroupTableModel(mmodel)
% jmodel.groupAndRefresh;
% jt.repaint;
oldWarnState = warning('off','MATLAB:hg:JavaSetHGProperty');
setappdata(ancestor(hObject,'figure'), 'UserData', userData);
plotData(hFig);
warning(oldWarnState);
end
end
% release rentrancy flag
hash.remove(hObject);
end
%%
function utcOffsets = askUtcOffset(FILENAME)
f = figure('Position',[100 100 400 150]);
startData = {};
for ii=1:numel(FILENAME)
startData{ii,1} = FILENAME;
startData{ii,2} = 0;
end
columnname = {'Filename', 'UTC Offset'};
columnformat = {'char', 'numeric'};
columneditable = [false true];
myTable = uitable('Units','normalized','Position',...
[0.1 0.1 0.9 0.9], 'Data', startData,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable,...
'RowName',[]);
set(h,'CloseRequestFcn',@myCloseFcn);
set(h,'Tag', 'myTag');
set(mytable,'Tag','myTableTag');
waitfor(gcf);
finalData=get(myTable,'Data');
function myCloseFcn(~,~)
myfigure=findobj('Tag','myTag');
myData=get(findobj(myfigure,'Tag','myTableTag'),'Data')
assignin('base','myTestData',myData)
delete(myfigure)
end
end
%%
function sam = finaliseDataEasyplot(sam,fileName)
%FINALISEDATA Adds new TIMEDIFF var
%
% Inputs:
% sam - a struct containing sample data.
%
% Outputs:
% sample_data - same as input, with fields added/modified
% make all dimension names upper case
for ii=1:numel(sam.dimensions)
sam.dimensions{ii}.name = upper(sam.dimensions{ii}.name);
end
idTime = getVar(sam.dimensions, 'TIME');
tmpStruct = struct();
tmpStruct.dimensions = idTime;
tmpStruct.name = 'TIMEDIFF';
theData=sam.dimensions{idTime}.data;
theData = [NaN; diff(theData*86400.0)];
tmpStruct.data = theData;
tmpStruct.iSlice = 1;
tmpStruct.typeCastFunc = sam.dimensions{idTime}.typeCastFunc;
sam.variables{end+1} = tmpStruct;
clear('tmpStruct');
if isfield(sam,'toolbox_input_file')
[PATHSTR,NAME,EXT] = fileparts(sam.toolbox_input_file);
sam.inputFilePath = PATHSTR;
sam.inputFile = NAME;
sam.inputFileExt = EXT;
sam.easyplot_input_file = sam.toolbox_input_file;
else
[PATHSTR,NAME,EXT] = fileparts(fileName);
sam.inputFilePath = PATHSTR;
sam.inputFile = NAME;
sam.inputFileExt = EXT;
sam.easyplot_input_file = fileName;
end
sam.time_coverage_start = sam.dimensions{idTime}.data(1);
sam.time_coverage_end = sam.dimensions{idTime}.data(end);
sam.dimensions{idTime}.comment = '';
sam.meta.site_id = sam.inputFile;
% if ~isfield(sample_data,'utc_offset_hours')
% sample_data.utc_offset_hours = 0;
% end
if isfield(sam.meta,'timezone')
if isempty(sam.meta.timezone)
sam.meta.timezone='UTC';
end
else
sam.meta.timezone='UTC';
end
sam.history = '';
sam.isPlottableVar = false(1,numel(sam.variables));
sam.plotThisVar = false(1,numel(sam.variables));
for kk=1:numel(sam.variables)
isEmptyDim = isempty(sam.variables{kk}.dimensions);
isData = isfield(sam.variables{kk},'data') & any(any(~isnan(sam.variables{kk}.data)));
if ~isEmptyDim && isData
sam.isPlottableVar(kk) = true;
sam.plotThisVar(kk) = false;
end
end
end
%%
function fileListNames = getFilelistNames(sample_data)
%GETFILELISTNAMES make a list of filenames from sample_data structure
fileListNames={};
if ~isempty(sample_data)
for ii=1:numel(sample_data)
fileListNames{end+1}=[sample_data{ii}.inputFile sample_data{ii}.inputFileExt];
end
end
end
%%
function plotVar = chooseVar(sample_data)
% CHOOSEVAR Choose single variable to plot
%
% chooseVar is always called after and data import so if this function ends
% up with no data then abort.
if isempty(sample_data)
error('CHOOSEVAR: empty sample_data');
end
plotVar=[];
varList= {};
for ii=1:numel(sample_data)
for jj=1:numel(sample_data{ii}.variables)
if sample_data{ii}.isPlottableVar(jj)
varList{end + 1}=sample_data{ii}.variables{jj}.name;
end
end
end
varList=unique(varList);
varList{end+1}='ALLVARS';
%disp(sprintf('%s ','Variable list = ',varList{:}));
title = 'Variable to plot?';
prompt = 'Variable List';
defaultanswer = 1;
choice = optionDialog( title, prompt, varList, defaultanswer );
pause(0.1);
if isempty(choice), return; end
if strcmp(choice,'ALLVARS') %choosen plot all variables
plotVar=varList(1:end-1);
else
plotVar={choice};
end
end
%%
function [isPlottable] = isPlottableData( theData )
isPlottable = false;
if isfield(theData,'data')
if isfield(theData,'dimensions') && ~isempty(theData.dimensions)
isPlottable = true;
end
end
end
%%
function [sample_data] = markPlotVar(sample_data, plotVar)
%MARKPLOTVAR Create cell array of plotted data for treeTable data
for ii=1:numel(sample_data)
sample_data{ii}.plotThisVar = cellfun(@(x) any(strcmp(x.name,plotVar)), sample_data{ii}.variables);
for jj=1:numel(sample_data{ii}.variables)
sample_data{ii}.variables{jj}.iSlice=1;
sample_data{ii}.variables{jj}.minSlice=1;
sample_data{ii}.variables{jj}.maxSlice=1;
if ~isvector(sample_data{ii}.variables{jj}.data)
[d1,d2] = size(sample_data{ii}.variables{jj}.data);
sample_data{ii}.variables{jj}.iSlice=floor(d2/2);
sample_data{ii}.variables{jj}.minSlice=1;
sample_data{ii}.variables{jj}.maxSlice=d2;
end
end
end
end
%%
function [treePanelData] = generateTreeData(sample_data)
%GENERATETREEDATA Create cell array for treeTable data
treePanelData={};
kk=1;
for ii=1:numel(sample_data)
for jj=1:numel(sample_data{ii}.variables)
if sample_data{ii}.isPlottableVar(jj)
% group, variable, visible
treePanelData{kk,1}=sample_data{ii}.meta.instrument_model;
treePanelData{kk,2}=sample_data{ii}.meta.instrument_serial_no;
treePanelData{kk,3}=sample_data{ii}.variables{jj}.name;
treePanelData{kk,4}=sample_data{ii}.plotThisVar(jj);
treePanelData{kk,5}=sample_data{ii}.variables{jj}.iSlice;
kk=kk+1;
end
end
end
end
%%
function tableVisibilityCallback(hModel,hEvent, hObject)
% TABLEVISIBILITYCALLBACK callback for treeTable visibility column
%
% Inputs:
% hModel - javahandle_withcallbacks.MultiClassTableModel
% hEvent - javax.swing.event.TableModelEvent
% hObject - hopefully the handle to figure
% cannot use turn off the callback trick here
% from "Undocumented Secrets of MATLAB-Java Programming" pg 167
% prevent re-entry
persistent hash;
if isempty(hash)
hash = java.util.Hashtable;
end
if ~isempty(hash.get(hObject))
return;
end
hash.put(hObject,1);
if ishghandle(hObject)
userData=getappdata(ancestor(hObject,'figure'), 'UserData');
else
disp('I am stuck in tableVisibilityCallback');
return;
end
% Get the modification data, zero indexed
modifiedRow = get(hEvent,'FirstRow');
modifiedCol = get(hEvent,'Column');
theModel = hModel.getValueAt(modifiedRow,0);
theSerial = hModel.getValueAt(modifiedRow,1);
if isempty(theSerial)
theSerial = '';
end
theVariable = hModel.getValueAt(modifiedRow,2);
plotTheVar = hModel.getValueAt(modifiedRow,3);
iSlice = hModel.getValueAt(modifiedRow,4);
% update flags/values in userData.sample_data
for ii=1:numel(userData.sample_data) % loop over files
for jj=1:numel(userData.sample_data{ii}.variables)
if strcmp(userData.sample_data{ii}.meta.instrument_model, theModel) && ...
strcmp(userData.sample_data{ii}.meta.instrument_serial_no, theSerial) &&...
strcmp(userData.sample_data{ii}.variables{jj}.name, theVariable)
userData.sample_data{ii}.plotThisVar(jj) = plotTheVar;
if isvector(userData.sample_data{ii}.variables{jj}.data)
hModel.setValueAt(1,modifiedRow,4);
userData.sample_data{ii}.variables{jj}.iSlice = 1;
else
[d1,d2] = size(userData.sample_data{ii}.variables{jj}.data);
if iSlice<1
hModel.setValueAt(1,modifiedRow,4);
userData.sample_data{ii}.variables{jj}.iSlice = 1;
elseif iSlice>d2
hModel.setValueAt(d2,modifiedRow,4);
userData.sample_data{ii}.variables{jj}.iSlice = d2;
else
userData.sample_data{ii}.variables{jj}.iSlice = iSlice;
end
end
end
end
end
% model = getOriginalModel(handles.jtable);
% model.groupAndRefresh;
% handles.jtable.repaint;
setappdata(ancestor(hObject,'figure'), 'UserData', userData);
plotData(ancestor(hObject,'figure'));
% not sure user always want rezoom on y
%zoomYextent_Callback(hObject);
% release rentrancy flag
hash.remove(hObject);
end % tableChangedCallback
%%
function originalModel = getOriginalModel(jtable)
%GETORIGINALMODEL Get original jtable model
originalModel = [];
if ~isempty(jtable)
originalModel = jtable.getModel;
try
while(true)
originalModel = originalModel.getActualModel;
end;
catch
% never mind - bail out...
end
end
end % getOriginalModel
%%
function fig = getParentFigure(fig)
%GETPARENTFIGURE Get the parent figure of an object
%
% If the object is a figure or figure descendent, return the
% figure. Otherwise return [].
while ~isempty(fig) & ~strcmp('figure', get(fig,'type'))
fig = get(fig,'parent');
end
end
%%
function plotData(hObject)
%PLOTDATA plot marked variables in sample_data
%
% Inputs:
% hObject - handle to figure
% set re-entrancy flag
persistent hash;
if isempty(hash)
hash = java.util.Hashtable;
end
if ~isempty(hash.get(hObject))
return;
end
hash.put(hObject,1);
if isempty(hObject), return; end
hFig = ancestor(hObject,'figure');
if isempty(hFig), return; end
userData = getappdata(hFig, 'UserData');
if isempty(userData.sample_data), return; end
figure(hFig); %make figure current
gData = guidata(hFig);
hAx=gData.axes1;
%Create a string for legend
legendStr={};
%legend(hAx,'off');
if isfield(userData,'legend_h')
if ~isempty(userData.legend_h), delete(userData.legend_h); end
end
%children = get(handles.axes1, 'Children');
children = findobj(gData.axes1,'Type','line');
if ~isempty(children)
delete(children);
end
varNames={};
%allVarInd=cellfun(@(x) cellfun(@(y) getVar(x.variables, char(y)), varName,'UniformOutput',false), handles.sample_data,'UniformOutput',false);
for ii=1:numel(userData.sample_data) % loop over files
for jj=1:numel(userData.sample_data{ii}.variables)
if strcmp(userData.sample_data{ii}.variables{jj}.name,'TIMEDIFF')
lineStyle='none';
markerStyle='.';
else
lineStyle='-';
markerStyle='none';
end
if userData.sample_data{ii}.plotThisVar(jj)
idTime = getVar(userData.sample_data{ii}.dimensions, 'TIME');
instStr=strcat(userData.sample_data{ii}.variables{jj}.name, '-',userData.sample_data{ii}.meta.instrument_model,'-',userData.sample_data{ii}.meta.instrument_serial_no);
%disp(['Size : ' num2str(size(handles.sample_data{ii}.variables{jj}.data))]);
%[PATHSTR,NAME,EXT] = fileparts(userData.sample_data{ii}.toolbox_input_file);
tagStr = [userData.sample_data{ii}.inputFile userData.sample_data{ii}.inputFileExt];
try
if isvector(userData.sample_data{ii}.variables{jj}.data)
% 1D var
line('Parent',hAx,'XData',userData.sample_data{ii}.dimensions{idTime}.data, ...
'YData',userData.sample_data{ii}.variables{jj}.data, ...
'LineStyle',lineStyle, 'Marker', markerStyle,...
'DisplayName', instStr, 'Tag', tagStr);
else
% 2D var
iSlice = userData.sample_data{ii}.variables{jj}.iSlice;
line('Parent',hAx,'XData',userData.sample_data{ii}.dimensions{idTime}.data, ...
'YData',userData.sample_data{ii}.variables{jj}.data(:,iSlice), ...
'LineStyle',lineStyle, 'Marker', markerStyle,...
'DisplayName', instStr, 'Tag', tagStr);
end
catch
error('PLOTDATA: plot failed.');
end
hold(hAx,'on');
legendStr{end+1}=strrep(instStr,'_','\_');
varNames{end+1}=userData.sample_data{ii}.variables{jj}.name;
set(gData.progress,'String',strcat('Plot : ', instStr));
%setappdata(ancestor(hObject,'figure'), 'UserData', userData);
%drawnow;
end
end
end
varNames=unique(varNames);
dataLimits=findVarExtents(userData.sample_data);
userData.xMin = dataLimits.xMin;
userData.xMax = dataLimits.xMax;
userData.yMin = dataLimits.yMin;
userData.yMax = dataLimits.yMax;
if userData.firstPlot
set(hAx,'XLim',[userData.xMin userData.xMax]);
set(hAx,'YLim',[userData.yMin userData.yMax]);
userData.firstPlot=false;
end
if isempty(varNames)
ylabel(hAx,'No Variables');
elseif numel(varNames)==1
ylabel(hAx,strrep(char(varNames{1}),'_','\_'));
else
ylabel(hAx,'Multiple Variables');
end
grid on
h = findobj(hAx,'Type','line','-not','tag','legend','-not','tag','Colobar');
% mapping = round(linspace(1,64,length(h)))';
% colors = colormap('jet');
% func = @(x) colorspace('RGB->Lab',x);
% c = distinguishable_colors(25,'w',func);
cfunc = @(x) colorspace('RGB->Lab',x);
colors = distinguishable_colors(length(h),'white',cfunc);
for jj = 1:length(h)
%dstrings{jj} = get(h(jj),'DisplayName');
try
%set(h(jj),'Color',colors( mapping(j),: ));
set(h(jj),'Color',colors(jj,:));
catch e
fprintf('Error changing plot colours in plot %s \n',get(gcf,'Name'));
disp(e.message);
end
end
[legend_h,object_h,plot_h,text_str]=legend(hAx,legendStr,'Location','Best', 'FontSize', 8);
% legendflex still has problems
%[legend_h,object_h,plot_h,text_str]=legendflex(hAx, legendStr, 'ref', hAx, 'xscale', 0.5, 'FontSize', 8);
userData.legend_h = legend_h;
set(gData.progress,'String','Done');
setappdata(hFig, 'UserData', userData);
updateDateLabel(hFig,struct('Axes', hAx), true);
drawnow;
% release rentrancy flag
hash.remove(hObject);
end
%% --- Executes on button press in saveImage.
function saveImage_Callback(hObject, eventdata, oldHandles)
%SAVEIMAGE_CALLBACK Easyplot save image
%
% hObject handle to saveImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
theParent = ancestor(hObject,'figure');
userData=getappdata(theParent, 'UserData');
gData = guidata(theParent);
if isfield(userData,'sample_data') && numel(userData.sample_data) > 0
[FILENAME, PATHNAME, FILTERINDEX] = uiputfile('*.png', 'Filename to save png');
if isequal(FILENAME,0) || isequal(PATHNAME,0)
disp('No file selected.');
else
%print(handles.axes1,'-dpng','-r300',fullfile(PATHNAME,FILENAME));
export_fig(fullfile(PATHNAME,FILENAME),'-png',gData.axes1);
end
%uiresume(handles.figure1);
end
end
%% --- Executes on button press in clearPlot.
function clearPlot_Callback(hObject, eventdata, oldHandles)
%CLEARPLOT_CALLBACK Clear easyplot plot window
%
% hObject handle to clearPlot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
theParent = ancestor(hObject,'figure');
userData=getappdata(theParent, 'UserData');
gData = guidata(theParent);
% clear plot