-
Notifications
You must be signed in to change notification settings - Fork 2
/
valid_ww3.m
2685 lines (2171 loc) · 101 KB
/
valid_ww3.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
clear
close_all=1;
if close_all==1; close all; end
warning off
tic
% Daily time
time_lima=datenum(1983,1,1,0,0,0):1:datenum(1983,3,31,0,0,0); % hindcast
%time_lima=datenum(1983,1,1,0,0,0):1:datenum(2002,12,31,0,0,0); % hindcast
time_lima=datenum(2014,1,1,0,0,0):1:datenum(2022,12,31,0,0,0); % hindcast
%time_lima=datenum(1996,1,1,0,0,0):1:datenum(2002,12,31,0,0,0); % hindcast
%time_lima=datenum(2020,12,1,0,0,0):1:datenum(2020,12,15,0,0,0); % 1-year experiments
time_lima=datenum(2003,1,1,0,0,0):1:datenum(2005,12,31,0,0,0); %
%time_lima=datenum(2014,7,9,0,0,0):1:datenum(2014,9,3,0,0,0); % initial date NZLAM hindcast
%time_lima=datenum(2018,1,6,0,0,0):1:datenum(2023,11,15,0,0,0); % Graham Harrington ECAN request on 18/09/2023
%time_lima=datenum(2014,8,5,0,0,0):1:datenum(2014,8,17,0,0,0); % 9-m wave event
%time_lima=datenum(2018,1,20,0,0,0):1:datenum(2020,12,1,0,0,0); % crossing between hindcast and ecoconnect
%time_lima=datenum(2021,1,8,0,0,0):1:datenum(2021,1,15,0,0,0); % Baring head wave direction, time series
%time_lima=datenum(2021,1,13,0,0,0):1:datenum(2021,1,13,0,0,0); % Baring head wave direction and currents, maps
%time_lima=datenum(2021,5,20,0,0,0):1:datenum(2021,5,27,0,0,0); % Baring Head tide and swell
%time_lima=datenum(2021,10,19,0,0,0):1:datenum(2021,10,24,0,0,0); % Banks Peninsula head tide and swell
%time_lima=datenum(2021,10,20,0,0,0):1:datenum(2021,10,22,0,0,0); % Banks Peninsula head tide and direction
%time_lima=datenum(2021,10,1,0,0,0):1:datenum(2021,10,24,0,0,0); % Banks Peninsula data assimilation
%time_lima=datenum(2021,6,27,0,0,0):1:datenum(2021,7,2,0,0,0); % Banks Peninsula data assimilation
%time_lima=datenum(2029,12,1,0,0,0):1:datenum(2030,1,1,0,0,0); % climate projections
stations=[0]; % 0 = coastal stations (points)
files={'Banks_Peninsula','Baring_Head','wairewa_lake_forsyth','Pelorus_Sound','Taumutu'};% 'SteepHead_SP_FullRecord_QC';
runs=[10];
%runs=[3,13];
%runs=[1:5];
expt_names={'GLOBALWAVE' ,'NZWAVE' ,'NZWAVE-ST6' ,'NZWAVE-HR-NOTIDES','NZWAVE-HR',... 5
'GLOBALWAVE-GFDL-CCAM','NZWAVE-ST4-GLOBALUM','NZWAVE-ST6-GLOBALUM','NZWAVE-GFDL-CCAM' ,'NZWAVE-ERA5',...10
'GLOBALWAVE-ERA5' ,'NZWAVE-ERA5-2021' ,'NZWAVE-ST6-NZLAM'};
plot_series=0; % stations=0, plot_series=1, plot_coastm=1 to save the coastal points
plot_rose =0;
plot_disp =0;
plot_eva =0;
plot_coastm=1; % statistical maps for coastal points
plot_map =0; % daily station maps
plot_downs =0; % daily downscaled maps
plot_mmap =0; % mean model maps
plot_mserie=0; % mean model series
plot_amap =0; % altimeter maps
plot_aserie=0; % altimeter series
plot_obs =0;
proc_obs =0;
ck_mod_mat =1;
save_csv =0;
save_fig =0;
save_video =0;
save_gif =0;
set_xlim =1;
obs_first =0;
add_stats =1;
portrait =0;
correct_model=0; % -1=scatter_kde, 0=binscatter, 1=nothing, >1 correct it
time_limab=time_lima;
% series, rose, dispersion, eva
dcol=[1,4,5,9]; %[6,1,2]; % Tp, Tm01, Tm02
%dcol=[6,5,8,9]; %[6,1,2]; % Tp, Tm01, Tm02
dcol=[6,1,2]; % Hs, Tp, dir
%dcol=[6,1,8]; % Hs, Tp, dir
dcol=[6]; % Hs, wlv
%dcol=[6]; % Hs, wlv
% 1 {'PeakPerid'} 2 {'PeakDirection'} 3 {'Directional spread'} 4 {'Tm01'} 5 {'Tm02'} 6 {'Hs'} 7 {'Qp'} 8 Tm
% 9 wlv 10 ucurr 11 vcurr
% maps
pcname ='hs'; % m_pcolor: wlv, hs, curr
vecname='hs'; % m_vec: hs, curr
% mmaps
mcol=[1,3]; % selected variables from mvalm
mvalm={'hs_m_mean','tp_m_mean','we_m_mean'};
mvals={'hs_mean','tp_mean','we_mean'}; % 1=hs, 2=tp, 3=we
% altimeter stats
acol=[1:6];
acol=[7:12];
avals={'hs_mean_rmse','hs_maxi_rmse','hs_mean_bias','hs_maxi_bias','hs_mean_corr','hs_maxi_corr',...
'hs_mean_frmse','hs_maxi_frmse','hs_mean_fbias','hs_maxi_fbias','hs_mean_fcorr','hs_maxi_fcorr'};
avalm={'hs_mean_mrmse','hs_maxi_mrmse','hs_mean_mbias','hs_maxi_mbias','hs_mean_mcorr','hs_maxi_mcorr',...
'hs_mean_fmrmse','hs_maxi_fmrmse','hs_mean_fmbias','hs_maxi_fmbias','hs_mean_fmcorr','hs_maxi_fmcorr'}; %
colors={'b','c','r','m','k','c'};
for i=1:length(runs)
expts{i}=expt_names{runs(i)};
end
%sufixes in netcdf files
gnames={'globalwave+globalum','nzwave+nzlam','nzwave_hr+nzcsm','tongawave+globalum','nzwave_era5'};
path_source=['/scale_wlg_nobackup/filesets/nobackup/niwa03150/WAVE/hindcast/']; % GLOBALWAVE/'];%2018/01/05/00'];
path_santanarc='/scale_wlg_persistent/filesets/project/niwa03150/santanarc/';
path_obs=[path_santanarc,'data/obs/'];
path_fig='/scale_wlg_nobackup/filesets/nobackup/niwa03150/santanarc/figures/';
% stations or grids - stations are bad in Baring_Head
ww3pre={'ww3p_interp','ww3g'};
ww3pre=ww3pre{2};
% Loading satellite obs
if plot_aserie || plot_amap
atype='cmems_l4';
% cmems_l4
if strcmp(atype,'cmems_l4')
path_cop='/scale_wlg_persistent/filesets/project/niwa03150/santanarc/data/copernicus-l4-wave-data/';
file_cop=[path_cop,'cmems_obs-wave_glo_phy-swh_my_multi-l4-2deg_P1D_multi-vars_143.00E-185.00E_53.00S-21.00S_2002-01-15-2020-12-31.nc'];
time_cop=ncread(file_cop,'time')+datenum('1950-01-01');
lon_cop=ncread(file_cop,'longitude');
lat_cop=ncread(file_cop,'latitude');
hs_cop_mean=ncread(file_cop,'VAVH_DAILY_MEAN');
hs_cop_maxi=ncread(file_cop,'VAVH_DAILY_MAX');
end
end
%fname=[pname,ww3pre,'_',ftime,'-utc_',gnames{ig},'.nc'];
fname='/scale_wlg_nobackup/filesets/nobackup/niwa03150/WAVE/hindcast/NZWAVE/2021/01/01/00/ww3g_2021010100-utc_nzwave+nzlam.nc';
depth_mod=double(ncread(fname,'depth',[1 1 1],[Inf Inf 1]));
lon_mod=double(ncread(fname,'lon'));
lat_mod=double(ncread(fname,'lat'));
fname='/scale_wlg_nobackup/filesets/nobackup/niwa03150/WAVE/hindcast/NZWAVE-HR/2021/01/01/00/ww3g_2021010100-utc_nzwave_hr+nzcsm.nc';
depth_hr=double(ncread(fname,'depth',[1 1 1],[Inf Inf 1]));
lon_hr=double(ncread(fname,'lon'));
lat_hr=double(ncread(fname,'lat'));
if plot_downs %|| plot_coastm
%if plot_map || plot_mmap || plot_downs || plot_coastm
% gebco bathy
gebco_nc='/scale_wlg_persistent/filesets/project/niwa00020/data/topography/gebco/1-min/gridone.nc';
spac=double(ncread(gebco_nc,'spacing'));
lon_gebco=double(ncread(gebco_nc,'x_range')); lon_gebco=lon_gebco(1):spac(1):lon_gebco(end);
lat_gebco=double(ncread(gebco_nc,'y_range')); lat_gebco=lat_gebco(end):-spac(2):lat_gebco(1);
bat_gebco=double(ncread(gebco_nc,'z'));
bat_gebco=reshape(bat_gebco,length(lon_gebco),length(lat_gebco));
lon_gebco=lon_gebco(1:10:end);
lat_gebco=lat_gebco(1:10:end);
bat_gebco=bat_gebco(1:10:end,1:10:end);
lon_gebco=wrapTo360(lon_gebco);
end
if plot_coastm || stations==0
% finding the closest points to the coast
np=1; % number of the closest points
xl=[390,605]; yl=[180,520];
xl=[390,700]; yl=[180,520]; % including the Chatam Islands
dep=depth_mod(xl(1):xl(2),yl(1):yl(2));
% finding y points in the x direction
k=0;
for i=1:size(dep,1)
[ngap,igap,fgap,sizegap] = findgap(dep(i,:)');
if ngap>0
for j=1:ngap; k=k+1;
points=[igap(j)-np:igap(j)-1,fgap(j)+1:fgap(j)+np];
yp(k).p=points;
xp(k).p(1:length(points))=i;
end; end; end
% finding x points in the y direction
k=0;
for i=1:size(dep,2)
[ngap,igap,fgap,sizegap] = findgap(dep(:,i));
if ngap>0
for j=1:ngap; k=k+1;
points=[igap(j)-np:igap(j)-1,fgap(j)+1:fgap(j)+np];
xpp(k).p=points;
ypp(k).p(1:length(points))=i;
end; end; end
% concatenating x and y points
xpoints=[]; ypoints=[];
for i=1:length(xp)
xpoints=[xpoints,xp(i).p];
ypoints=[ypoints,yp(i).p];
end
for i=1:length(xpp)
xpoints=[xpoints,xpp(i).p];
ypoints=[ypoints,ypp(i).p];
end
% cleaning repeated pair of points
points=[xpoints',ypoints'];
points=unique(points,'rows');
points(:,1)=points(:,1)+xl(1)-1;
points(:,2)=points(:,2)+yl(1)-1;
% selecting from spectral points
spec_points=0;
if spec_points
fname='/scale_wlg_nobackup/filesets/nobackup/niwa03150/WAVE/hindcast/NZWAVE-ERA5/2021/01/01/00/ww3p_2021010100-utc_nzwave_era5.nc';
lon_spe=double(ncread(fname,'lon'));
lat_spe=double(ncread(fname,'lat'));
depth_spe=double(ncread(fname,'depth'));
a=find(lon_spe(:,1)<=178.7 & lon_spe(:,1)>=166.2 & lat_spe(:,1)<=-34 & lat_spe(:,1)>=-48);
b=find(depth_spe(a,1)<=1000);
c=a(b);
a=find(lon_spe(c,1)<=170.6 & lon_spe(c,1)>=168 & lat_spe(c,1)<=-37.5 & lat_spe(c,1)>=-42.5);
c(a)=nan; return
c(isnan(c))=[];
figure; hold on; plot(lon_spe(c,1),lat_spe(c,1),'.'); xlim([165 180]); ylim([-50 -30])
end
end
lon_obss=[]; lat_obss=[];
if plot_coastm==1 & plot_series==0
stations=1:length(points);
end
return
% biggest loop on stations
for fobs=stations
% OBS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if plot_coastm==1 & plot_series==0
file=['i',num2str(points(fobs,1)),'_j',num2str(points(fobs,2)),'_grid_point_'];
elseif plot_coastm==1 & plot_series==1
file=['bla'];
%file=['i',num2str(points(fobs,1)),'_j',num2str(points(fobs,2)),'_grid_point_'];
else
file=files{fobs};
file=replace(file,' ','_');
file_obs=[path_obs,file];
[obs,time_obs,lon_obs,lat_obs]=proc_wave_obs(file,proc_obs); %,plot_obs);
end
if plot_series
scrsz=[1 1 1366 768];
%scrsz=get(0,'screensize');
if close_all==1; figure('position',scrsz,'color',[1 1 1],'visible','on'); end
hold on
set(gca,'fontsize',12,'fontweight','bold')
if obs_first
legh={'Obs'}; legt={'Obs'};
else
legh=[]; legt=[];
end
ke=0;
for expt=expts
ke=ke+1;
expt=expt{1};
[ig,ltime]=grab_nc_sufix(expt);
path_expt=[path_source,expt,'/']; % GLOBALWAVE/'];%2018/01/05/00'];
path_dm=[path_expt,'matlab/'];
system(['mkdir -p ',path_dm]);
%filename=[path_dm,file,'_',datestr(time_lima(1),'YYYYmmDDHH'),'_',datestr(time_lima(end),'YYYYmmDDHH'),'.mat'];
hs_mod=[];tp_mod=[]; pd_mod=[];time_mod=[];
tm01_mod=[];tm_mod=[]; pd_mod=[]; we_mod=[];
tm02_mod=[];ds_mod=[]; wlv_mod=[];time_mod=[];
ucur_mod=[];vcur_mod=[];
checkin=0;
% Loop in model time
for t=time_lima
%tic
if plot_coastm==1 & plot_series==0 % plot_series=0 needed to save the coastal points
file=['i',num2str(points(fobs,1)),'_j',num2str(points(fobs,2)),'_grid_point_'];
elseif plot_coastm==1 & plot_series==1
file=['bla'];
%file=['i',num2str(points(fobs,1)),'_j',num2str(points(fobs,2)),'_grid_point_'];
else
file=files{fobs};
file=replace(file,' ','_');
file_obs=[path_obs,file];
[obs,time_obs,lon_obs,lat_obs]=proc_wave_obs(file,proc_obs); %,plot_obs);
end
filename=[path_dm,file,'_',datestr(t,'YYYYmmDDHH'),'.mat'];
if ck_mod_mat==1 && exist(filename)==2
display(['Loading: ',filename])
load(filename)%,'time_mod','model')
if exist('ucur','var')~=1
wlv=nan(size(hs)); ucur=nan(size(hs)); vcur=nan(size(hs));
end
elseif fobs==0 %plot_coastm==1
ptime=datestr(t,'YYYY/mm/DD/HH/');
ftime=datestr(t,'YYYYmmDDHH');
pname=[path_expt,ptime];
fname=[pname,ww3pre,'_',ftime,'-utc_',gnames{ig},'.nc'];
display(['Loading: ',fname]);
if checkin==0; % t==time_lima(1)
checkin=1;
lon_mod=double(ncread(fname,'lon'));
lat_mod=double(ncread(fname,'lat'));
end
stations=1:length(points);
for fobss=stations
%tic;
file=['i',num2str(points(fobss,1)),'_j',num2str(points(fobss,2)),'_grid_point_'];
filename=[path_dm,file,'_',datestr(t,'YYYYmmDDHH'),'.mat'];
display(['Checking: ',filename])
if ck_mod_mat==0 || exist(filename)~=2
lon_obs=lon_mod(points(fobss,1));
lat_obs=lat_mod(points(fobss,2));
[dif ilon]=nanmin(abs(lon_mod-lon_obs));
[dif ilat]=nanmin(abs(lat_mod-lat_obs));
dis=sqrt((lon_mod(ilon)-lon_obs).^2 + (lat_mod(ilat)-lat_obs).^2)*111;
%display(['Distance between obs ',file,' and grid point is: ',num2str(dis),' km'])
time=squeeze(double(ncread(fname,'time')))./24+t; time=time(1:ltime-1);
if strncmp(ww3pre,'ww3p',4)
elseif strncmp(ww3pre,'ww3g',4)
hs=squeeze(double(ncread(fname,'hsig', [ilon ilat 1],[1 1 ltime]))); hs=hs(1:end-1);
tp=squeeze(double(ncread(fname,'tpeak', [ilon ilat 1],[1 1 ltime]))); tp=tp(1:end-1);
%tm01=squeeze(double(ncread(fname,'tmean01', [ilon ilat 1],[1 1 ltime]))); tm01=tm01(1:end-1);
%tm02=squeeze(double(ncread(fname,'tmean02', [ilon ilat 1],[1 1 ltime]))); tm02=tm02(1:end-1);
%tm=squeeze(double(ncread(fname,'tmean', [ilon ilat 1],[1 1 ltime]))); tm=tm(1:end-1);
pd=squeeze(double(ncread(fname,'peak_direction',[ilon ilat 1],[1 1 ltime]))); pd=pd(1:end-1);
%ds=squeeze(double(ncread(fname,'directional_spread',[ilon ilat 1],[1 1 ltime]))); ds=ds(1:end-1);
if strcmp(expt,'NZWAVE-HR')
wlv=squeeze(double(ncread(fname,'wlv', [ilon ilat 1],[1 1 ltime-1])));
model(ke).wlv=wlv;
ucur=squeeze(double(ncread(fname,'ucur', [ilon ilat 1],[1 1 ltime-1])));
model(ke).ucur=ucur;
vcur=squeeze(double(ncread(fname,'vcur', [ilon ilat 1],[1 1 ltime-1])));
model(ke).vcur=vcur;
else
wlv=nan(size(hs));
ucur=nan(size(hs));
vcur=nan(size(hs));
end
end
%wave energy (we) = (1/16)*rho*g*(hs.^2); % https://www.coastalwiki.org/wiki/Shallow-water_wave_theory#Introduction
we=(1/16)*1025*9.8*(hs.^2);
display(['Saving: ',filename])
save(filename,'time','tp','hs','pd')%,'ds','tm01','tm02','pd','tm','wlv','ucur','vcur','we')
end %if ck_mod_mat==0 || exist(filename)~=2
%toc
end % for fobss=stations
else
ptime=datestr(t,'YYYY/mm/DD/HH/');
ftime=datestr(t,'YYYYmmDDHH');
pname=[path_expt,ptime];
fname=[pname,ww3pre,'_',ftime,'-utc_',gnames{ig},'.nc'];
%fname=[pname,'ww3g_',ftime,'-utc_',gnames{1},'.nc'];
display(['Loading: ',fname]);
if checkin==0; % t==time_lima(1)
checkin=1;
lon_mod=double(ncread(fname,'lon'));
lat_mod=double(ncread(fname,'lat'));
% coastal points
if plot_coastm==1
lon_obs=lon_mod(points(fobs,1));
lat_obs=lat_mod(points(fobs,2));
end
[dif ilon]=nanmin(abs(lon_mod-lon_obs));
[dif ilat]=nanmin(abs(lat_mod-lat_obs));
if strcmp(file,'SteepHead_SP_FullRecord_QC')
%ilon=ilon+3;
elseif strcmp(file,'wairewa_lake_forsyth') & ig==2 % NZWAVE
ilat=ilat-2;
end
dis=sqrt((lon_mod(ilon)-lon_obs).^2 + (lat_mod(ilat)-lat_obs).^2)*111;
display(['Distance between obs ',file,' and grid point is: ',num2str(dis),' km'])
end
time=squeeze(double(ncread(fname,'time')))./24+t; time=time(1:ltime-1);
if strncmp(ww3pre,'ww3p',4)
hs=squeeze(double(ncread(fname,'hsig', [ilon 1],[1 ltime]))); hs=hs(1:end-1)';
tp=squeeze(double(ncread(fname,'tpeak', [ilon 1],[1 ltime]))); tp=tp(1:end-1)';
tm01=squeeze(double(ncread(fname,'tmean01', [ilon 1],[1 ltime]))); tm01=tm01(1:end-1)';
tm=squeeze(double(ncread(fname,'tmean', [ilon 1],[1 ltime]))); tm=tm(1:end-1)';
pd=squeeze(double(ncread(fname,'peak_direction',[ilon 1],[1 ltime]))); pd=pd(1:end-1)';
elseif strncmp(ww3pre,'ww3g',4)
hs=squeeze(double(ncread(fname,'hsig', [ilon ilat 1],[1 1 ltime]))); hs=hs(1:end-1);
tp=squeeze(double(ncread(fname,'tpeak', [ilon ilat 1],[1 1 ltime]))); tp=tp(1:end-1);
tm01=squeeze(double(ncread(fname,'tmean01', [ilon ilat 1],[1 1 ltime]))); tm01=tm01(1:end-1);
tm02=squeeze(double(ncread(fname,'tmean02', [ilon ilat 1],[1 1 ltime]))); tm02=tm02(1:end-1);
tm=squeeze(double(ncread(fname,'tmean', [ilon ilat 1],[1 1 ltime]))); tm=tm(1:end-1);
pd=squeeze(double(ncread(fname,'peak_direction',[ilon ilat 1],[1 1 ltime]))); pd=pd(1:end-1);
ds=squeeze(double(ncread(fname,'directional_spread',[ilon ilat 1],[1 1 ltime]))); ds=ds(1:end-1);
if strcmp(expt,'NZWAVE-HR')
wlv=squeeze(double(ncread(fname,'wlv', [ilon ilat 1],[1 1 ltime-1])));
model(ke).wlv=wlv;
ucur=squeeze(double(ncread(fname,'ucur', [ilon ilat 1],[1 1 ltime-1])));
model(ke).ucur=ucur;
vcur=squeeze(double(ncread(fname,'vcur', [ilon ilat 1],[1 1 ltime-1])));
model(ke).vcur=vcur;
else
wlv=nan(size(hs));
ucur=nan(size(hs));
vcur=nan(size(hs));
end
end
%wave energy (we) = (1/16)*rho*g*(hs.^2); % https://www.coastalwiki.org/wiki/Shallow-water_wave_theory#Introduction
we=(1/16)*1025*9.8*(hs.^2);
display(['Saving: ',filename])
save(filename,'time','tp','pd','ds','tm01','tm02','hs','tm','wlv','ucur','vcur','we')
end % if ck_mod_mat==1 && exist(filename)==2
if plot_coastm==0
time_mod=[time_mod;time];
hs_mod=[hs_mod;hs];
tp_mod=[tp_mod;tp];
tm01_mod=[tm01_mod;tm01];
tm02_mod=[tm02_mod;tm02];
tm_mod=[tm_mod;tm];
pd_mod=[pd_mod;pd];
ds_mod=[ds_mod;ds];
wlv_mod=[wlv_mod;wlv];
if exist('ucur','var')==1
ucur_mod=[ucur_mod;ucur];
vcur_mod=[vcur_mod;vcur];
we_mod=[we_mod;we];
end
clear model
% 1 {'PeakPerid'} 2 {'PeakDirection'} 3 {'Directional spread'} 4 {'Tm01'} 5 {'Tm02'} 6 {'Hs'} 7 {'Qp'} 8 Tm
model.data(:,9)=wlv_mod; % we_mod
model.data(:,8)=tm_mod;
model.data(:,1)=tp_mod;
model.data(:,2)=pd_mod;
model.data(:,3)=ds_mod;
model.data(:,4)=tm01_mod;
model.data(:,5)=tm02_mod;
model.data(:,6)=hs_mod;
model.data(:,7)=nan;
if exist('ucur','var')==1
model.data(:,10)=ucur_mod;
model.data(:,11)=vcur_mod;
model.data(:,12)=we_mod;
end
%path_dm=[path_expt,'matlab/'];
%system(['mkdir -p ',path_dm]);
%display(['Saving: ',filename])
%save(filename,'time_mod','model')
end
end % for t=time_lima
if plot_coastm==1
display(['Finished processing coastal stations from: ',datestr(time_lima(1)),' to ',datestr(time_lima(end))])
toc
return
end
if save_csv==1
fda=[filename(1:end-14),datestr(time_lima(1),'YYYYmmDDHH'),'_',datestr(time_lima(end),'YYYYmmDDHH'),'.csv'];
display(['Saving: ',fda]);
if exist(fda)==2
system(['rm -rf ',fda]);
end
model.data(:,7)=nan;
csvdata=model.data;
csvdata=num2cell(csvdata);
for i=1:length(time_mod); csvtime{i,1}=datestr(time_mod(i),'yyyy-mm-ddTHH:MM:SS'); end
csvhead={'date','PeakPeriod','PeakDirection','Directional spread','Tm01','Tm02','Hs','Qp','Tm','Water level','U current','V current','Wave Energy (J/m2)'};
% concatenating str matrices
csvall=[csvtime,csvdata];
%csvall=[csvhead;csvall];
%csvwrite(fda,csvall);
T = cell2table(csvall,'VariableNames',csvhead);
writetable(T,fda)
fclose('all');
end
% Plotting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tnames={'Peak Period', 'Peak Direction', 'Directional spread', 'Tm01','Tm02','Significant Wave Height (Hs)','Qp','Tm','Water Level','U current','V current','Wave Energy (J/m2)'};
for i=1:length(dcol)
subplot(length(dcol),1,i);
set(gca,'fontsize',12,'fontweight','bold')
hold on
if ke==1 & plot_obs==1
if obs_first==1;
if dcol(i)<=size(obs,2)
plot(time_obs,obs(:,dcol(i))','.','markersize',12,'color',[0 .7 0],'linewidth',2)
end
end
for eix=1:length(expts); plot(nan,nan,'.','markersize',12,'color',colors{eix},'linewidth',2); end
plot(nan,nan,'.','markersize',12,'color',[0 .7 0],'linewidth',2)
end
plot(time_mod,model.data(:,dcol(i))','.','markersize',12,'color',colors{ke},'linewidth',2)
if obs_first==0;
if ke==length(expts) & plot_obs==1
if dcol(i)<=size(obs,2)
plot(time_obs,obs(:,dcol(i))','.','markersize',12,'color',[0 .7 0],'linewidth',2)
end
end
end
if set_xlim==1;
xlim([time_lima(1) time_lima(end)])
end
%if i==3
datetick('x','dd/mmm/yyyy','keeplimits')
%end
title([replace(file,'_',' '),' ',tnames{dcol(i)}])
grid('on')
if plot_obs==1
modeli=interp1(time_mod,model.data(:,dcol(i)),time_obs);
if (dcol(i)~=2 || dcol(i)~=1) & i==1
mod_rmse=nanrmse(obs(:,dcol(i)),modeli');
mod_corr=nancorr(obs(:,dcol(i)),modeli');
mod_bias=nanmean(modeli')-nanmean(obs(:,dcol(i)));
if add_stats
legh=[legh,{[expt,' rmse=',num2str(mod_rmse,'%.2f'),' corr=',num2str(mod_corr,'%.2f'),', bias=',num2str(mod_bias,'%.2f')]}];
else
legh=[legh,{[expt]}];%,' rmse=',num2str(mod_rmse,'%.2f'),' corr=',num2str(mod_corr,'%.2f'),', bias=',num2str(mod_bias,'%.2f')]}];
end
elseif dcol(i)==2 || dcol(i)==1
ylim([0 360])
end
else
legh=[legh,{[expt]}];%,' rmse=',num2str(mod_rmse,'%.2f'),' corr=',num2str(mod_corr,'%.2f'),', bias=',num2str(mod_bias,'%.2f')]}];
end
end % for i=1:length(dcol)
end % for expt=expts
if obs_first==0;
legh=[legh,{['Obs.']}]; %,' rmse=',num2str(mod_rmse,'%.2f'),' corr=',num2str(mod_corr,'%.2f'),', bias=',num2str(mod_bias,'%.2f')]}];
end
%if ~isempty(find(dcol==6))
% subplot(length(dcol),1,find(dcol==6));
subplot(length(dcol),1,1);
legend([legh],'location','best')
%end
if save_fig==1
%export_fig(gcf,'steephead_period','-png','-r150');
end
end % if plot_series
if plot_rose
legh={'Obs'}; legt={'Obs'};
ke=0;
for expt=expts
ke=ke+1;
expt=expt{1};
[ig,ltime]=grab_nc_sufix(expt);
path_expt=[path_source,expt,'/']; % GLOBALWAVE/'];%2018/01/05/00'];
path_dm=[path_expt,'matlab/'];
system(['mkdir -p ',path_dm]);
%filename=[path_dm,file,'_',datestr(time_lima(1),'YYYYmmDDHH'),'_',datestr(time_lima(end),'YYYYmmDDHH'),'.mat'];
hs_mod=[];tp_mod=[]; pd_mod=[];time_mod=[];
tm01_mod=[];tm_mod=[]; pd_mod=[];time_mod=[];
tm02_mod=[];ds_mod=[]; wlv_mod=[];time_mod=[];
checkin=0;
% Loop in model time
for t=time_lima
filename=[path_dm,file,'_',datestr(t,'YYYYmmDDHH'),'.mat'];
if ck_mod_mat==1 && exist(filename)==2
display(['Loading: ',filename])
load(filename)%,'time_mod','model')
else
display(['File doenst exist: ',filename])
display(['Run with plot_series=1 first'])
return
end % if ck_mod_mat==1 && exist(filename)==2
time_mod=[time_mod;time];
hs_mod=[hs_mod;hs];
tp_mod=[tp_mod;tp];
tm01_mod=[tm01_mod;tm01];
tm02_mod=[tm02_mod;tm02];
tm_mod=[tm_mod;tm];
pd_mod=[pd_mod;pd];
ds_mod=[ds_mod;ds];
wlv_mod=[wlv_mod;wlv];
end % for t=time_lima
clear model
% 1 {'PeakPerid'} 2 {'PeakDirection'} 3 {'Directional spread'} 4 {'Tm01'} 5 {'Tm02'} 6 {'Hs'} 7 {'Qp'} 8 Tm
model.data(:,9)=wlv_mod;
model.data(:,8)=tm_mod;
model.data(:,1)=tp_mod;
model.data(:,2)=pd_mod;
model.data(:,3)=ds_mod;
model.data(:,4)=tm01_mod;
model.data(:,5)=tm02_mod;
model.data(:,6)=hs_mod;
% wave rose options
Option = {'vWinds', [0:6],'anglenorth', 0, 'angleeast', 90, 'labels', {'N (0°)', 'E (90°)', 'S (180°)', 'W (270°)'}, 'freqlabelangle', 45, 'legendtype', 0};
%Option={'legendtype', 0, 'vWinds', [0:6]};
tnames={'Peak Period', 'Peak Direction', 'Directional spread', 'Tm01','Tm02','Significant Wave Height','Qp','Tm','Water Level'};
vnames={'Tp', 'Dp', 'Spr', 'Tm01','Tm02','Hs', 'Qp' ,'Tm','Wlv'};
for i=1:length(dcol)
if portrait
scrsz=[2 42 958 953];
else
scrsz=[1 41 1920 962];
end
h=figure(i);
set(h,'position',scrsz,'color',[1 1 1],'visible','on')
if length(runs)==1
lsub=2; csub=1;
elseif length(runs)==2
lsub=3; csub=1;
elseif mod(length(runs),2)==1
lsub=round(length(runs)/2); csub=round(length(runs)/2)-1;
elseif mod(length(runs),2)==0
lsub=round(length(runs)/2); csub=round(length(runs)/2);
end
if portrait
ax=subplot(lsub,csub,ke);
else
ax=subplot(csub,lsub,ke);
end
Options = [Option, {'axes', ax, 'cmap', 'invbone','TitleString', {['(a) ',replace(file,'_',' '), ' obs. ',tnames{dcol(i)}];''},...
'LegendType', 0, 'LegendPosition', 'north','LegendOrientation', 'vertical', 'LabLegend',vnames{dcol(i)} , 'LegendVariable', vnames{dcol(i)}, 'scalefactor', 1.0}];%, 'vWinds', [0:.5 1 1.2 2 5]}];
if ke==1
[dif is]=nanmin(abs(time_obs-time_lima(1)));
[dif ie]=nanmin(abs(time_obs-time_lima(end)));
dp_obs=obs(is:ie,2)';
data_obs=obs(is:ie,dcol(i))';
[figure_handle, count, speeds, directions, Table] = WindRose(dp_obs,data_obs,Options);
%title('Obs')
end
if portrait
ax=subplot(lsub,csub,ke+1);
else
ax=subplot(csub,lsub,ke+1);
end
lett={'(b)','(c)','(d)','(e)','(f)','(g)','(h)','(i)','(j)','(k)','(l)','(m)','(n)','(o)','(p)','(q)','(r)','(s)','(t)','(u)','(v)','(w)','(x)','(y)','(z)'};
ltype=0; if length(runs)==ke; ltype=2; end
Options = [Option, {'axes', ax, 'cmap', 'invbone','TitleString', {[lett{ke},' ',expt];''},...
'LegendType', ltype, 'LegendPosition', 'west','LegendOrientation','vertical', 'LabLegend', vnames{dcol(i)} , 'LegendVariable', vnames{dcol(i)}, 'scalefactor', 1.0}];
[figure_handle, count, speeds, directions, Table] = WindRose(model.data(:,2)',model.data(:,dcol(i))',Options);
end
end
if save_fig==1
%export_fig(gcf,'steephead_period','-png','-r150');
end
path_dm=strcat(path_fig,'paper_1/');
system(['mkdir -p ',path_dm]);
figname=[path_dm,file,'_wave_rose_',replace(tnames{dcol(i)},' ','_'),'_',datestr(time_lima(1),'YYYY_mm_DD_HH_MM'),'_',datestr(time_lima(end),'YYYY_mm_DD_HH_MM'),'.png'];
display(['Plotting: ',figname]);
if save_fig==1
display(['Saving: ',figname]);
export_fig(gcf,figname,'-png','-r150');
%close
%clf('reset')
end
end % if plot_rose
if plot_disp
scrsz=[1 1 1366 768];
%scrsz=get(0,'screensize');
if portrait==1
scrsz=[2 42 958 953];
else
scrsz=[1 1 1910 990];
end
figure('position',scrsz,'color',[1 1 1],'visible','on')
hold on
set(gca,'fontsize',12,'fontweight','bold')
legh={'Obs'}; legt={'Obs'};
ke=0;
for expt=expts
ke=ke+1;
expt=expt{1};
[ig,ltime]=grab_nc_sufix(expt);
path_expt=[path_source,expt,'/']; % GLOBALWAVE/'];%2018/01/05/00'];
path_dm=[path_expt,'matlab/'];
system(['mkdir -p ',path_dm]);
%filename=[path_dm,file,'_',datestr(time_lima(1),'YYYYmmDDHH'),'_',datestr(time_lima(end),'YYYYmmDDHH'),'.mat'];
hs_mod=[];tp_mod=[]; pd_mod=[];time_mod=[];
tm01_mod=[];tm_mod=[]; pd_mod=[]; we_mod=[];
tm02_mod=[];ds_mod=[]; wlv_mod=[];time_mod=[];
checkin=0;
% Loop in model time
for t=time_lima
filename=[path_dm,file,'_',datestr(t,'YYYYmmDDHH'),'.mat'];
if ck_mod_mat==1 && exist(filename)==2
display(['Loading: ',filename])
load(filename)%,'time_mod','model')
else
display(['NOT FOUND: ',filename])
display(['Run with plot_series=1 first'])
return
end % if ck_mod_mat==1 && exist(filename)==2
time_mod=[time_mod;time];
hs_mod=[hs_mod;hs];
tp_mod=[tp_mod;tp];
tm01_mod=[tm01_mod;tm01];
tm02_mod=[tm02_mod;tm02];
tm_mod=[tm_mod;tm];
pd_mod=[pd_mod;pd];
ds_mod=[ds_mod;ds];
wlv_mod=[wlv_mod;wlv];
%we_mod=[we_mod;we];
clear model
% 1 {'PeakPerid'} 2 {'PeakDirection'} 3 {'Directional spread'} 4 {'Tm01'} 5 {'Tm02'} 6 {'Hs'} 7 {'Qp'} 8 Tm
model.data(:,9)=wlv_mod; % we_mod
model.data(:,8)=tm_mod;
model.data(:,1)=tp_mod;
model.data(:,2)=pd_mod;
model.data(:,3)=ds_mod;
model.data(:,4)=tm01_mod;
model.data(:,5)=tm02_mod;
model.data(:,6)=hs_mod;
%path_dm=[path_expt,'matlab/'];
%system(['mkdir -p ',path_dm]);
%display(['Saving: ',filename])
%save(filename,'time_mod','model')
end % for t=time_lima
tnames={'Peak Period (s)', 'Peak Direction (^o)', 'Directional spread (^o)', 'Tm01 (m)','Tm02 (m)','Hs (m)','Qp (^o)','Tm (s)','Water Level (m)'};
for i=1:length(dcol)
modeli=interp1(time_mod,model.data(:,dcol(i)),time_obs)';
if length(runs)==1
%subplot(length(dcol),1,i);
lsub=1; csub=1;
elseif length(runs)==2
%subplot(length(dcol),1,i);
lsub=2; csub=1;
elseif mod(length(runs),2)==1
lsub=round(length(runs)/2); csub=round(length(runs)/2)-1;
elseif mod(length(runs),2)==0
lsub=round(length(runs)/2); csub=round(length(runs)/2);
end
if portrait==1
ax=subplot(lsub,csub,ke);
else
ax=subplot(csub,lsub,ke);
end
yplot=modeli; xplot=obs(:,dcol(i));
if correct_model==-1;
display(['Plotting scatter plot']); tic
scatter_kde(xplot, yplot, 'filled', 'MarkerSize', 10); toc %,'MarkerEdgeColor','k'); toc
colormap(flipud(cmocean('matter')))
set(gca,'fontsize',12,'fontweight','bold')
hold on
% Add Color bar
%cb = colorbar();
%cb.Label.String = 'Probability density estimate';
hold on
plot([0 9],[0 9],'--b','linewidth',2)
inan=isnan(modeli); obs(inan,dcol(i))=nan;
inan=isnan(obs(:,dcol(i))); modeli(inan)=nan;
modi=modeli; inan=isnan(modi); modi(inan)=[];
obsi=obs(:,dcol(i)); inan=isnan(obsi); obsi(inan)=[];
p=polyfit(obsi,modi,1);
%plot([0 9],[0 9*p(1)+p(2)],'--b','linewidth',2)
if ke==length(expts)
h=colorbar;
set(h,'position',[0.915 0.24 0.011 0.44]) % [left bottom width height]
set(get(h,'ylabel'),'string','Probability density estimate','fontsize',10,'fontweight','bold');
else
colorbar('off')
end
%colorbar
caxis([0 1])
%if set_xlim==1;
% xlim([time_lima(1)-2 time_lima(end)+2])
%end
%if i==3
%end
title([expt])% ,': ',replace(file,'_',' '),' ',tnames{dcol(i)}])
grid('on')
xlim([0 9])
ylim([0 9])
%axis('equal')
elseif correct_model==0;
hold on
plot(xplot,yplot,'.','color',[1 1 1],'linewidth',2)
plot(xplot,yplot,'.','color',[1 1 1],'linewidth',2)
plot([0 9],[0 9],'r','linewidth',2)
inan=isnan(modeli); obs(inan,dcol(i))=nan;
inan=isnan(obs(:,dcol(i))); modeli(inan)=nan;
modi=modeli; inan=isnan(modi); modi(inan)=[];
obsi=obs(:,dcol(i)); inan=isnan(obsi); obsi(inan)=[];
p=polyfit(obsi,modi,1);
plot([0 9],[0 9*p(1)+p(2)],'color',[0 0 1],'linewidth',2)
bh=binscatter(xplot,yplot,90);
set(gca,'fontsize',12,'fontweight','bold')
hold on
colormap(flipud(cmocean('matter')))
if ke==length(expts)
h=colorbar;
set(h,'position',[0.915 0.24 0.011 0.44])
set(get(h,'ylabel'),'string','Bin counts','fontsize',14,'fontweight','bold');
else
colorbar('off')
end
%colorbar
caxis([0 250])
%if set_xlim==1;
% xlim([time_lima(1)-2 time_lima(end)+2])
%end
%if i==3
%end
title([expt])% ,': ',replace(file,'_',' '),' ',tnames{dcol(i)}])
grid('on')
%xlim([0 9])
%ylim([0 9])
axis('equal')
elseif correct_model>=1;
set(gca,'fontsize',12,'fontweight','bold')
hold on
plot(xplot,yplot,'.','color',[1 1 1],'linewidth',2)
plot(xplot,yplot,'.','color',[1 1 1],'linewidth',2)
plot([0 9],[0 9],'r','linewidth',2)
plot(xplot,yplot,'.','color',[0 0 0],'linewidth',2)
%if set_xlim==1;
% xlim([time_lima(1)-2 time_lima(end)+2])
%end
%if i==3
%end
title([expt])% ,': ',replace(file,'_',' '),' ',tnames{dcol(i)}])
grid('on')
xlim([0 9])
ylim([0 9])
inan=isnan(modeli); obs(inan,dcol(i))=nan;
inan=isnan(obs(:,dcol(i))); modeli(inan)=nan;
modi=modeli; inan=isnan(modi); modi(inan)=[];
obsi=obs(:,dcol(i)); inan=isnan(obsi); obsi(inan)=[];
p=polyfit(obsi,modi,1);
plot([0 9],[0 9*p(1)+p(2)],'k','linewidth',2)
% correcting model based on the linear relationship
%cfac=(obsi-p(2))/p(1);
if correct_model>1
modc=modi.*(1+(1-p(1)));% + p(2);
p=polyfit(obsi,modc,1)
plot(obsi,modc,'.','color',[0 0 1],'linewidth',2)
plot([0 9],[0 9*p(1)+p(2)],'b','linewidth',2)
xplot=modc; yplot=obsi;
end
end
ylabel(['Forecasted ',tnames{dcol(i)}])
xlabel(['Observed ',tnames{dcol(i)}])
%axis('equal')
%if dcol(i)==6
mod_rmse=nanrmse(xplot,yplot);
mod_corr=nancorr(xplot,yplot);
mod_bias=nanmean(yplot)-nanmean(xplot);
if correct_model<=0;
yd=8.5; dsz=1;
text(-.0,yd,['y=',num2str(p(1),'%.2f'),'*x',num2str(p(2),'%+.2f')],'fontsize',10,'fontweight','bold');
text(-.0,yd-dsz,['rmse=',num2str(mod_rmse,'%.2f')] ,'fontsize',10,'fontweight','bold');
text(-.0,yd-dsz*2,['bias=',num2str(mod_bias,'%.2f')] ,'fontsize',10,'fontweight','bold');
text(-.0,yd-dsz*3,['r=',num2str(mod_corr,'%.2f')] ,'fontsize',10,'fontweight','bold');
elseif correct_model==1;
% legh=[legh,{[expt,' rmse=',num2str(mod_rmse,'%.2f'),' corr=',num2str(mod_corr,'%.2f'),', bias=',num2str(mod_bias,'%.2f')]}];
legh=[{['y=',num2str(p(1),'%.2f'),'*x',num2str(p(2),'%+.2f')];['rmse=',num2str(mod_rmse,'%.2f'),' corr=',num2str(mod_corr,'%.2f'),', bias=',num2str(mod_bias,'%.2f')]}];
legend([legh],'location','south')
end
box('on')
end
end
if ~isempty(find(dcol==6))
%subplot(length(dcol),1,find(dcol==6));
%legend([legh],'location','best')
end
path_dm=strcat(path_fig,expt,'/');
system(['mkdir -p ',path_dm]);
figname=[path_dm,file,'_',replace(tnames{dcol(i)},' ','_'),'_',datestr(time_lima(1),'YYYY_mm_DD_HH_MM'),'_',datestr(time_lima(end),'YYYY_mm_DD_HH_MM'),'.png'];
display(['Plotting: ',figname]);
if save_fig==1
display(['Saving: ',figname]);
export_fig(gcf,figname,'-png','-r150');
%close
%clf('reset')
end
end % if plot_disp
if plot_eva
scrsz=[1 1 1366 768];
%scrsz=get(0,'screensize');
%scrsz=[2 42 958 953];
scrsz=[1 1 1910 990];
figure('position',scrsz,'color',[1 1 1],'visible','on')
hold on
set(gca,'fontsize',12,'fontweight','bold')
legh={'Obs'}; legt={'Obs'};