forked from derpycode/muffingen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makecookie.m
1943 lines (1938 loc) · 88.7 KB
/
makecookie.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 [] = makecookie(POPT)
% makecookie
%
% ***********************************************************************
% *** makecookie [MAKE COOKIE CONFIG] ***********************************
% ***********************************************************************
%
% makecookie(POPT)
% takes 1 argument:
% POPT [STRING] (e.g., 'EXAMPLE_BLANK')
% --> the string for the configuration parameter file
% --> if an empty (i.e., '') value is passed to this parameter
% then the default parameter set is used (makecookie_settings_BLANK)
%
% NOTE: grid/matrix orientations are :: [LAT,LON] (rows x columns)
% (i.e., the orientation as you would view the raw data)
%
% NOTE: for plotting grids (plot_2dgridded)
% arrays need to be flipped up-down
% (to un-do the visually-correct orientation used as standard)
%
% ***********************************************************************
% *** HISTORY ***********************************************************
% ***********************************************************************
%
% 24/10/11: forked from muffingen
% *** v0.9.99 *************************************************
%
% ***********************************************************************
%%
% *********************************************************************** %
% *** INITIALIZE MUFFINGEN ********************************************** %
% *********************************************************************** %
%
% *** initialize cookiegen ********************************************** %
%
disp([' ']);
disp(['>>> INITIALIZING ...']);
% set function name
str_function = 'makecookie';
% set version!
str_cookiegen_ver = 'v0.9.99';
% set date
str_date = [datestr(date,11), datestr(date,5), datestr(date,7)];
% close existing plot windows
close all;
% end any active journaling
ans = get(0,'Diary');
if strcmp(ans,'on'), diary off; end
%
% *** initialize primary paths ****************************************** %
%
% add library path to cookiegen functions
% NOTE: find where cookie lives ...
% remove its name (+ '.m' extension) from the returned path ...
% add relative source path to it
tmp_path = which(str_function);
tmp_path = tmp_path(1:end-length(str_function)-3);
addpath([tmp_path '/' 'source']);
addpath([tmp_path '/' 'DATA']);
addpath([tmp_path '/' 'CONFIGS']);
%
% *** load cookiegen configuration ************************************** %
%
% load configurqation options file
if isempty(POPT)
% WARNING
disp([' ** WARNING: No config file given -- using cookiegen_config_BLANKGRID.']);
disp([' ']);
POPT='cookiegen_config_BLANKGRID';
eval([CONFIGS '/' POPT]);
elseif exist([POPT '.m'],'file')
eval(POPT);
else
% ERROR
disp([' ** ERROR: Cannot find config file: ' POPT '.m']);
disp([' ']);
return;
end
%
% *** cookiegen additional user settings ******************************** %
%
% NOTE: mostly these are parameter previously in the config file
%
% [0-99] # of ocean levels that are 'extra'
if ~exist('par_add_Dk','var'), par_add_Dk=0; end
% surface layer reference thickness (m)
if ~exist('par_sur_D','var'), par_sur_D = 0.0; end
% [0.0-1.0] land fractional area threshold
if ~exist('par_A_frac_threshold','var'), par_A_frac_threshold=0.5; end
% mask mask!
if ~exist('par_mask_name','var'), par_mask_name = ''; end
% [false/true] filter land-sea mask?
if ~exist('opt_filtermask','var'), opt_filtermask=true; end
% [false/true] filter topography?
if ~exist('opt_filtertopo','var'), opt_filtertopo=true; end
% [0-9999] minimum lake size (# cells)
if ~exist('par_min_oceann','var'), par_min_oceann=20; end
% [false/true] edit borders?
if ~exist('opt_user_borders','var'), opt_user_borders=false; end
%
% [0/1/2/3] zonal windstress generation option
% #0 == automatically determine best choice for each hemispheres
% #1 == land world (modern NH / paleo Eocene (both hemispheres))
% #2 == water world (hi lat ocean gateway in both hemispheres))
% #3 == grey world (mean of land-blocked and hi lat ocean gateway)
if ~exist('par_tauopt','var'), par_tauopt=3; end
% [false/true] use random runoff scheme
if ~exist('opt_makerndrunoff','var'), opt_makerndrunoff=false; end
%
% [false/true] create 2x res sediment grid
if ~exist('opt_makehighresseds','var'), opt_makehighresseds=false; end
% minimm (random, option 2) sediment depth
if ~exist('par_sed_Dmin','var'), par_sed_Dmin=1000.0; end
% maximum (random, option 2) sediment depth
if ~exist('par_sed_Dmax','var'), par_sed_Dmax=6000.0; end
%
% [false/true] ask for output directory?
if ~exist('opt_outputdir','var'), opt_outputdir=false; end
% [false/true] debug output?
if ~exist('opt_debug','var'), opt_debug=false; end
% ['STRING'] templarte base-config name (optional)
if ~exist('par_cfgid','var'), par_cfgid=''; end
%
% *** cookiegen derived user settings *********************************** %
%
par_min_Dk = par_max_k - par_max_k_shallow + 1;
%
% *** check / filter options ******************************************** %
%
% age parameter
if ~exist('par_age','var')
par_age = 0.0;
par_age_emty = true;
else
par_age_emty = false;
end
% process GCM name string
if strcmp(par_gcm,'hadcm3l'), par_gcm = 'hadcm3l'; end
if strcmp(par_gcm,'HadCM3L'), par_gcm = 'hadcm3l'; end
if strcmp(par_gcm,'HADCM3L'), par_gcm = 'hadcm3l'; end
if strcmp(par_gcm,'hadcm3'), par_gcm = 'hadcm3'; end
if strcmp(par_gcm,'HadCM3'), par_gcm = 'hadcm3'; end
if strcmp(par_gcm,'HADCM3'), par_gcm = 'hadcm3'; end
if strcmp(par_gcm,'um'), par_gcm = 'hadcm3'; end
if strcmp(par_gcm,'UM'), par_gcm = 'hadcm3'; end
if strcmp(par_gcm,'FOAM'), par_gcm = 'foam'; end
if strcmp(par_gcm,'CESM'), par_gcm = 'cesm'; end
if strcmp(par_gcm,'ROCKEE'), par_gcm = 'rockee'; end
if strcmp(par_gcm,'K1'), par_gcm = 'k1'; end
if strcmp(par_gcm,'.k1'), par_gcm = 'k1'; end
if strcmp(par_gcm,'.K1'), par_gcm = 'k1'; end
if strcmp(par_gcm,'K2'), par_gcm = 'k2'; end
if strcmp(par_gcm,'MASK'), par_gcm = 'mask'; end
if strcmp(par_gcm,'dat'), par_gcm = 'mask'; end
if strcmp(par_gcm,'.dat'), par_gcm = 'mask'; end
if strcmp(par_gcm,'txt'), par_gcm = 'mask'; end
if strcmp(par_gcm,'.txt'), par_gcm = 'mask'; end
if strcmp(par_gcm,'.mat'), par_gcm = 'mat'; end
if strcmp(par_gcm,'.MAT'), par_gcm = 'mat'; end
if strcmp(par_gcm,''), par_gcm = 'blank'; end
if strcmp(par_gcm,'BLANK'), par_gcm = 'blank'; end
if strcmp(par_gcm,'none'), par_gcm = 'blank'; end
if strcmp(par_gcm,'NONE'), par_gcm = 'blank'; end
%
% rename variables
% NOTE: for some earlier code consistency ... now redundant ...
imax = par_max_i;
jmax = par_max_j;
kmax = par_max_k;
str_nameout = par_wor_name;
% initialize optional netCDF filenames
if ~exist('par_nc_topo_name','var'), par_nc_topo_name = ''; end
if ~exist('par_nc_mask_name','var'), par_nc_mask_name = ''; end
if ~exist('par_nc_axes_name','var'), par_nc_axes_name = ''; end
if ~exist('par_nc_atmos_name','var'), par_nc_atmos_name = ''; end
if ~exist('par_nc_ocean_name','var'), par_nc_ocean_name = ''; end
if ~exist('par_nc_coupl_name','var'), par_nc_coupl_name = ''; end
if ~exist('par_nc_biome_name','var'), par_nc_biome_name = ''; end
if ~exist('par_nc_orog_name','var'), par_nc_orog_name = ''; end
% -> set default variable names
% NOTE: it is not obvious where originally why 'hadcm3','hadcm3l'
% options required: par_expid(1:5)
% (but I have removed it now to enable 6-character UM codes)
switch par_gcm
case {'hadcm3','hadcm3l'}
if isempty(par_nc_topo_name), par_nc_topo_name = [par_expid '.qrparm.omask']; end
if isempty(par_nc_mask_name), par_nc_mask_name = [par_expid '.qrparm.mask']; end
if isempty(par_nc_axes_name), par_nc_axes_name = [par_expid 'a.pdclann']; end
if isempty(par_nc_atmos_name), par_nc_atmos_name = [par_expid '_sed']; end
if isempty(par_nc_ocean_name), par_nc_ocean_name = [par_expid '.qrparm.mask']; end
if isempty(par_nc_coupl_name), par_nc_coupl_name = [par_expid 'a.pdclann']; end
if isempty(par_nc_biome_name), par_nc_biome_name = [par_expid '_inputdata']; end
if isempty(par_nc_orog_name), par_nc_orog_name = [par_expid '.qrparm.orog']; end
case ('foam')
if isempty(par_nc_topo_name), par_nc_topo_name = 'topo'; end
if isempty(par_nc_mask_name), par_nc_mask_name = par_nc_topo_name; end
if isempty(par_nc_axes_name), par_nc_axes_name = par_nc_topo_name; end
if isempty(par_nc_atmos_name), par_nc_atmos_name = 'atmos'; end
if isempty(par_nc_ocean_name), par_nc_ocean_name = ''; end
if isempty(par_nc_coupl_name), par_nc_coupl_name = 'coupl'; end
case {'cesm'}
if isempty(par_nc_topo_name), par_nc_topo_name = 'climo'; end
if isempty(par_nc_mask_name), par_nc_mask_name = par_nc_topo_name; end
if isempty(par_nc_axes_name), par_nc_axes_name = par_nc_topo_name; end
if isempty(par_nc_atmos_name), par_nc_atmos_name = par_nc_topo_name; end
if isempty(par_nc_ocean_name), par_nc_ocean_name = par_nc_topo_name; end
if isempty(par_nc_coupl_name), par_nc_coupl_name = par_nc_topo_name; end
case ('rockee')
if isempty(par_nc_topo_name), par_nc_topo_name = ''; end
if isempty(par_nc_mask_name), par_nc_mask_name = par_nc_topo_name; end
if isempty(par_nc_atmos_name), par_nc_atmos_name = ''; end
if isempty(par_nc_ocean_name), par_nc_ocean_name = ''; end
if isempty(par_nc_axes_name), par_nc_axes_name = par_nc_ocean_name; end
if isempty(par_nc_coupl_name), par_nc_coupl_name = ''; end
end
% set default annual wind averaging to not based on monthly winds
switch par_gcm
case {'hadcm3'}
if ~exist('par_wspeed_avstr','var'), par_wspeed_avstr = 'uvaa'; end
case {'hadcm3l'}
if ~exist('par_wspeed_avstr','var'), par_wspeed_avstr = 'uvaa'; end
case ('foam')
if ~exist('par_wspeed_avstr','var'), par_wspeed_avstr = 'uvaa'; end
case {'cesm'}
if ~exist('par_wspeed_avstr','var'), par_wspeed_avstr = 'wsma'; end
case {'rockee'}
if ~exist('par_wspeed_avstr','var'), par_wspeed_avstr = 'wsaa'; end
otherwise
if ~exist('par_wspeed_avstr','var'), par_wspeed_avstr = ''; end
end
% plot format option
switch par_plotformat
case {'pdf','png','jpg','jpeg','gif','tif','tiff'}
% valid options -- leave alone
otherwise
par_plotformat = '';
end
%
% *** initialize I/O **************************************************** %
%
% set full file name string
if ~isempty(par_gcm)
str_file = [str_function '.' par_gcm '.' str_nameout];
else
str_file = [str_function '.' str_nameout];
end
% set/create output directory
if opt_outputdir
str_dirout = uigetdir(par_pathout);
else
if isempty(par_pathout)
str_dirout = [pwd '/' par_wor_name];
else
if ~(exist(par_pathout,'dir') == 7), mkdir(par_pathout); end
str_dirout = [pwd '/' par_pathout '/' par_wor_name];
end
if ~(exist(str_dirout,'dir') == 7), mkdir(str_dirout); end
end
%
% *** create strings object ********************************************* %
%
str = struct('gcm', {}, 'exp', {}, 'path', {}, 'dir', {}, 'nc', {});
str = setfield(str, {1}, 'gcm', par_gcm);
str = setfield(str, {1}, 'exp', par_expid);
str = setfield(str, {2}, 'exp', str_nameout);
str = setfield(str, {1}, 'path', par_pathin);
str = setfield(str, {2}, 'path', par_pathout);
str = setfield(str, {1}, 'dir', '');
str = setfield(str, {2}, 'dir', str_dirout);
str = setfield(str, {1}, 'nc', par_nc_axes_name);
str = setfield(str, {2}, 'nc', par_nc_topo_name);
str = setfield(str, {3}, 'nc', par_nc_atmos_name);
str = setfield(str, {4}, 'nc', par_nc_mask_name);
str = setfield(str, {5}, 'nc', par_nc_coupl_name);
str = setfield(str, {6}, 'nc', par_nc_ocean_name);
str = setfield(str, {7}, 'nc', par_nc_biome_name);
str = setfield(str, {8}, 'nc', par_nc_orog_name);
str = setfield(str, {1}, 'wspd', par_wspeed_avstr);
str = setfield(str, {1}, 'mask', par_mask_name);
%
% *** initialize reporting ********************************************** %
%
% create copy of .m file options
% NOTE: find where the config file lives ...
% remove its name (+ '.m' extension) from the returned path ...
% add relative source path to it
tmp_path = which([POPT '.m']);
tmp_path = tmp_path(1:end-length(POPT)-3);
copyfile([tmp_path '/' POPT '.m'],[str(2).dir '/' POPT '_' str_date '.m'])
% start logging
% NOTE: delete any existing (current date) log file in the directory first
str_log = [str(2).dir '/' 'log.' str_function '.' str_date '.txt'];
if (exist(str_log,'file') == 2), delete(str_log); end
diary(str_log)
% display warm and comforting welcoming message
disp([' ']);
disp(['------------------------------------------------------------']);
disp([' Hello! Welcome to cookiegen ',str_cookiegen_ver]);
disp([' We are going to make a GREAT model configuration!']);
disp(['------------------------------------------------------------']);
disp([' ']);
% initialize cookiegen step number
n_step = 0;
%
% *********************************************************************** %
% *********************************************************************** %
% *** GET SH*T DONE ***************************************************** %
% *********************************************************************** %
%
% %%% SUMMARY OF STEP SEQUENCE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NOTE: not all of these steps are carried out, depending on the options
% (initialize)
% CONFIRM OPTIONS
% CREATING GENIE GRID
% READ AXES INFORMATION
% LOAD TOPO & MASK DATA
% RE-GRID MASK
% FILTER MASK
% ADJUST MASK -- USER!
% RE-GRID TOPO
% RE-GRID VERTICALLY
% ADJUST TOPO -- AUTOMATIC BATHYMETRY FILTERING
% ADJUST TOPO -- USER!
% CALCULATE RUNOFF & COMPLETE k1 FILE
% IDENTIFY ISLANDS
% UPDATE ISLANDS AND ISLAND PATHS
% GENERATE ISLAND PATHS
% GENERATE PSI ISLANDS
% GENERATE SEDIMENT GRID
% RE-GRID WIND SPEED/STRESS DATA
% LOAD ALBEDO DATA
% RE-GRID & PROCESS ALBEDO
% LOAD OROGRAPHY AND ICEMASK
% RE-GRID & PROCESS OROGRAPHY AND ICEMASK
% GENERATE CONFIG FILE PARAMETER LINES
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% *** CONFIRM OPTIONS *************************************************** %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. CHECKING PRIMARY OPTIONS ...']);
% check world name
if (length(par_wor_name) ~= 8)
disp([' * ERROR: World name (par_wor_name) must be 8 characters long.']);
disp(['--------------------------------------------------------']);
disp([' ']);
diary off;
return;
end
% check GCM options
switch str(1).gcm
case {'hadcm3','hadcm3l','foam','cesm','rockee'}
disp([' * GCM == ' str(1).gcm ' (OK)']);
case {'mat'}
disp([' * A high resolution topography (only) file: ' str(1).exp]);
case {'k1','mask','k2'}
disp([' * GENIE grid will be loaded directly from k1, mask, or k2 text file: ' str(1).exp]);
case {'blank'}
disp([' * A blank template grid will be generated: ' str(1).exp]);
otherwise
disp([' * ERROR: Unknown GCM name or input format. Maybe it is LOSCAR? Good luck to you! (Bye bye)']);
disp(['--------------------------------------------------------']);
disp([' ']);
diary off;
return;
end
% check compatibility of GCM with cookiegen settings
switch str(1).gcm
case {'cesm','rockee'}
opt_makeents=false;
disp([' * ERROR: ' str(1).gcm ' input is not (yet) supported to generate ENTS fields :(']);
disp([' ----> set opt_makeents=.FALSE. and continue cookiegen']);
disp(['--------------------------------------------------------']);
otherwise
%
end
% adjust options
switch str(1).gcm
case {'hadcm3','hadcm3l','foam'}
%
case {'cesm','rockee'}
%
case {'mat'}
opt_makezonalwind=true;
opt_makezonalalbedo=true;
case {'k1','mask','k2'}
opt_filtermask=false;
opt_makezonalwind=true;
opt_makezonalalbedo=true;
case {'blank'}
opt_makezonalwind=true;
opt_makezonalalbedo=true;
otherwise
%
end
%
% *** SET UP OUTPUT GRID ************************************************ %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. CREATING GENIE GRID ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
% create GENIE grid
[go_lonm,go_lone,go_latm,go_late,go_dm,go_de] = make_genie_grid(imax,jmax,kmax,par_max_D,par_lon_off,opt_equalarea,par_add_Dk);
disp([' - GENIE grid generated.']);
%
% *** LOAD GRID (AXES) DATA ********************************************* %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. READING AXES INFORMATION ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
%
switch str(1).gcm
case {'hadcm3','hadcm3l','foam','cesm','rockee'}
% read axes
if strcmp(str(1).gcm,'hadcm3')
% NOTE: axes need to be re-generated later (for winds etc.)
[gi_loncm,gi_lonce,gi_latcm,gi_latce] = fun_read_axes_hadcm3(str);
elseif strcmp(str(1).gcm,'hadcm3l')
[gi_loncm,gi_lonce,gi_latcm,gi_latce,gi_lonpm,gi_lonpe,gi_latpm,gi_latpe,gi_lonam,gi_lonae,gi_latam,gi_latae] = fun_read_axes_hadcm3x(str);
elseif strcmp(str(1).gcm,'foam')
[gi_loncm,gi_lonce,gi_latcm,gi_latce,gi_lonpm,gi_lonpe,gi_latpm,gi_latpe,gi_lonam,gi_lonae,gi_latam,gi_latae] = fun_read_axes_foam(str);
elseif strcmp(str(1).gcm,'cesm')
[gi_loncm,gi_lonce,gi_latcm,gi_latce,gi_lonam,gi_lonae,gi_latam,gi_latae] = fun_read_axes_cesm(str);
elseif strcmp(str(1).gcm,'rockee')
[gi_loncm,gi_lonce,gi_latcm,gi_latce,gi_lonam,gi_lonae,gi_latam,gi_latae] = fun_read_axes_rockee(str);
else
disp([' * ERROR: Unknown GCm name.']);
disp([' ']);
diary off;
return;
end
disp([' - Axis info read.']);
case {'mat'}
% NOTE: assume equal Dlon, Dlat grid (non equal area) and 1 degree
% also that the input grid starts at -180E
% >>> EDIT ME >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
gi_lonce = [-180.0:1.0:180.0];
gi_latce = [-90.0:1.0:90.0];
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
otherwise
% DO NOTHING
disp([' (Nothing to load.)']);
end
%
% *** LOAD TOPO & MASK DATA ********************************************* %
%
% NOTE: mask is defined with '1' for ocean
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. READING MASK & TOPO GRIDS ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
%
switch str(1).gcm
case {'hadcm3','hadcm3l','foam','cesm','rockee'}
% read topo
if (strcmp(str(1).gcm,'hadcm3') || strcmp(str(1).gcm,'hadcm3l'))
[gi_mask] = fun_read_omask_hadcm3x(str);
[gi_topo] = fun_read_topo_hadcm3x(str);
elseif strcmp(str(1).gcm,'foam')
[gi_topo,gi_mask] = fun_read_topomask_foam(str);
elseif strcmp(str(1).gcm,'cesm')
[gi_topo,gi_mask] = fun_read_topomask_cesm(str);
elseif strcmp(str(1).gcm,'rockee')
[gi_topo,gi_mask] = fun_read_topomask_rockee(str);
end
disp([' - Mask & topo info read.']);
% plot input mask & topo
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(gi_mask),2.0,'',[[str_dirout '/' str_nameout] '.mask_in'],'mask in');
plot_2dgridded(flipud(gi_topo),6000.0,'',[[str_dirout '/' str_nameout] '.topo_in'],'topo in');
else
figure; imagesc(gi_mask); colorbar; title('mask in'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.mask_in'] '.' str_date '.' par_plotformat]);
figure; imagesc(gi_topo); colorbar; title('topo in'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.topo_in'] '.' str_date '.' par_plotformat]);
end
case {'mat'}
% read topo
% NOTE: assume specific (rows==lat, col==lon) orientation
% => flip up/down when loaded
% NOTE: assume topography is positive height (above sealevel)
% >>> EDIT ME >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if isempty(str(1).path)
loc_str_file = [par_expid '.' par_gcm];
else
loc_str_file = [str(1).path '/' par_expid '.' par_gcm];
end
data = load('-mat',loc_str_file);
vars = fieldnames(data);
gi_topo = data.(vars{1});
gi_topo = flipud(gi_topo);
gi_mask = zeros(size(gi_topo));
gi_mask(find(gi_topo < 0.0)) = 1.0;
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
disp([' - Mask & topo info read.']);
% plot input mask & topo
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(gi_mask),2.0,'',[[str_dirout '/' str_nameout] '.mask_in'],'mask in');
plot_2dgridded(flipud(gi_topo),6000.0,'',[[str_dirout '/' str_nameout] '.topo_in'],'topo in');
else
figure; imagesc(gi_mask); colorbar; title('mask in'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.mask_in'] '.' str_date '.' par_plotformat]);
figure; imagesc(gi_topo); colorbar; title('topo in'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.topo_in'] '.' str_date '.' par_plotformat]);
end
case {'k1','k2','mask'}
% load topo directly
[go_k1,go_mask,imax,jmax] = fun_read_k1(str);
disp([' - k1 read.']);
% re-create GENIE grid with derived (/updated?) grid dimensions
% NOTE: the value of kmax is taken from the config file
% (while imax and jmax are deduced from the file)
[go_lonm,go_lone,go_latm,go_late,go_dm,go_de] = make_genie_grid(imax,jmax,kmax,par_max_D,par_lon_off,opt_equalarea,par_sur_D);
disp([' - GENIE grid re-generated.']);
otherwise
% DO NOTHING
disp([' (Nothing to load.)']);
end
%
% *** RE-GRID MASK ****************************************************** %
%
% NOTE: go_fmask == fractional land-sea mask
% used to track whether there is going to be any (GCM) bathymetry
% available (if the original ocean fraction in that cell is not zero)
n_step = n_step+1;
disp(['> ' num2str(n_step) '. RE-GRIDING MASK ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
%
switch str(1).gcm
case {'hadcm3','hadcm3l','foam','cesm','rockee','mat'}
% initial re-gridding of mask
% NOTE: need to transpose around [gi_mask] to have correct input format
% to make_regrid_2d
% similarly, output needs to be transposed back again
% NOTE: pass edges of c-grid
[go_mask,go_tmp] = make_regrid_2d(gi_lonce,gi_latce,gi_mask',go_lone,go_late,opt_debug);
disp([' - Mask re-gridded.']);
go_mask = go_mask';
go_fmask = go_mask;
% create mask (<>= par_A_frac_threshold fractional area thresold)
% NOTE: 1.0 == 100% ocean
go_mask(find(go_mask>=par_A_frac_threshold)) = 1.0;
go_mask(find(go_mask<par_A_frac_threshold)) = 0.0;
% calculate respective fractional areas
[si_farea,si_farearef] = fun_grid_calc_ftotarea(gi_mask,gi_lonce,gi_latce);
[so_farea,so_farearef] = fun_grid_calc_ftotarea(go_mask,go_lone,go_late);
disp([' * Original land area fraction = ', num2str(1.0-si_farea)]);
disp([' * Re-gridded land area fraction = ', num2str(1.0-so_farea)]);
case {'k1','k2','mask'}
disp([' (Nothing to do ... k1/k2/mask file already loaded.)']);
go_fmask = zeros(jmax,imax) + 1;
otherwise
go_mask = zeros(jmax,imax) + 1;
disp([' - Blank mask created (nothing to re-grid).']);
go_fmask = go_mask;
end
% plot & save initial mask re-grid
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_mask),2.0,'',[[str_dirout '/' str_nameout] '.omask_out.RAW'],'ocean mask out -- RAW re-gridded');
else
figure; imagesc(go_mask); colorbar; title('ocean mask out -- RAW re-gridded'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.omask_out.RAW'] '.' str_date '.' par_plotformat]);
end
%
% *** FILTER MASK ******************************************************* %
%
n_step = n_step+1;
if (opt_debug), input('Press return to CONTINUE ...'); end
% filter mask if requested
% NOTE: when loading in a default 'k1' file, best to skip this step
% set VERSION 0 (raw)
grid_ver = 0;
str_ver = num2str(grid_ver);
%
if (opt_filtermask || (par_min_oceann > 0))
%
disp(['> ' num2str(n_step) '. FILTERING MASK ...']);
%
if opt_filtermask
%
% BASIC MASK FILTERING
%
% filter out single cell embayments iteratively
% initialize
go_mask_fills_cnt = 1;
% LOOP >>>
while (go_mask_fills_cnt > 0)
% increment VERSION
grid_ver = grid_ver + 1;
str_ver = num2str(grid_ver);
% fill in 4-surrounded cells
go_mask_fills = find_grid_4cells(go_mask);
% fill in 3-surrounded cells (excepting open ocean bordering ones)
go_mask_fills = go_mask_fills + find_grid_3cells(go_mask);
% update mask
go_mask = go_mask - go_mask_fills;
% count number of cell changes
go_mask_fills_cnt = sum(sum(go_mask_fills));
end
% <<< LOOP
fprintf(' - Single cell embayments filtered out.\n')
% plot mask
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_mask),2.0,'',[[str_dirout '/' str_nameout] '.omask_out.v' str_ver],['ocean mask out -- version ' str_ver]);
else
figure; imagesc(go_mask); colorbar; title(['ocean mask out -- version ' str_ver]); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.omask_out.v' str_ver] '.' str_date '.' par_plotformat]);
end
%
end
%
if opt_filtermask
%
% ADJUST MASK -- CLEAN UP POLAR CONNECTIONS
%
% increment VERSION
grid_ver = grid_ver + 1;
str_ver = num2str(grid_ver);
% open up narrow polar connections
go_mask_fills = find_grid_poleopen(go_mask);
% update mask
go_mask = go_mask + go_mask_fills;
%
fprintf(' - Polar connections cleaned up.\n')
% plot mask
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_mask),2.0,'',[[str_dirout '/' str_nameout] '.omask_out.v' str_ver],['ocean mask out -- version ' str_ver]);
else
figure; imagesc(go_mask); colorbar; title(['ocean mask out -- version ' str_ver]); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.omask_out.v' str_ver] '.' str_date '.' par_plotformat]);
end
%
end
%
if (par_min_oceann > 0)
%
% SMALL WATER BODY FILTERING MASK FILTERING
%
[go_oceans,n_oceans,i_oceans] = find_grid_oceans(go_mask);
% plot oceans!
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf')),
plot_2dgridded(flipud(go_oceans),999,'',[[str_dirout '/' str_nameout] '.ocean_out.INIT'],'oceans out -- INITIAL');
else
figure; imagesc(go_mask); colorbar; title('oceans out -- INITIAL'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.ocean_out.INIT'] '.' str_date '.' par_plotformat]);
end
% increment VERSION
grid_ver = grid_ver + 1;
str_ver = num2str(grid_ver);
% clean up small water bodies
[go_mask,go_oceans,n_oceans] = find_grid_oceans_update(go_mask,go_oceans,n_oceans,par_min_oceann);
fprintf(' - Small water bodies cleaned up.\n')
% plot mask
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_mask),2.0,'',[[str_dirout '/' str_nameout] '.omask_out.v' str_ver],['ocean mask out -- version ' str_ver]);
else
figure; imagesc(go_mask); colorbar; title(['ocean mask out -- version ' str_ver]); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.omask_out.v' str_ver] '.' str_date '.' par_plotformat]);
end
%
end
%
% calculate new fractional area
[so_farea,so_farearef] = fun_grid_calc_ftotarea(go_mask,go_lone,go_late);
disp([' * Revised land area fraction = ', num2str(1.0-so_farea)]);
%
end
%
% *** ADJUST MASK -- APPLY OPTIONAL PRESCRIBED MASK CHANGES ************* %
%
% load and apply mask to the ocean mask!
if ~isempty(str(1).mask)
n_step = n_step+1;
if (opt_debug), input('Press return to CONTINUE ...'); end
disp(['> ' num2str(n_step) '. APPLYING LAND-SEA MASK ADJUSTMENTS FROM FILE: ' [str(1).mask '.txt']]);
% read in mask file ... exit if it cannot be found ...
loc_mask = fun_read_mask(str);
% for a '1' in the mask => force to ocean
% for a '-1' in the mask => force to land
go_mask(find(loc_mask == 1)) = 1;
go_mask(find(loc_mask == -1)) = 0;
end
%
% *** ADJUST MASK -- USER! ********************************************** %
%
n_step = n_step+1;
if (opt_debug), input('Press return to CONTINUE ...'); end
%
if opt_user
%
disp(['> ' num2str(n_step) '. USER EDITING OF MASK ...']);
%
[go_mask] = fun_grid_edit_mask(go_mask,go_fmask);
% increment VERSION
grid_ver = grid_ver + 1;
str_ver = num2str(grid_ver);
% plot mask
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_mask),2,'',[[str_dirout '/' str_nameout] '.omask_out.v' str_ver],['ocean mask out -- version ' str_ver]);
else
figure; imagesc(go_mask); colorbar; title(['ocean mask out -- version ' str_ver]); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.omask_out.v' str_ver] '.' str_date '.' par_plotformat]);
end
% calculate new fractional area
[so_farea,so_farearef] = fun_grid_calc_ftotarea(go_mask,go_lone,go_late);
disp([' * Revised land area fraction = ', num2str(1.0-so_farea)]);
%
fprintf(' - User-editing complete.\n')
%
end
%
% *** CREATE FINAL MASK ************************************************* %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. CREATE FINAL MASK ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
%
% create GENIE NaN masks
go_masknan = go_mask;
go_masknan(find(go_mask == 0)) = NaN;
go_masknotnan = go_mask;
go_masknotnan(find(go_mask ~= 0)) = NaN;
go_masknotnan(find(go_masknotnan == 0)) = 1;
%
% plot final mask
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_mask),99999.0,'',[[str_dirout '/' str_nameout] '.omask_out.FINAL'],'ocean mask out -- FINAL version');
else
figure; imagesc(go_mask); colorbar; title('ocean mask out -- FINAL version'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.omask_out.FINAL'] '.' str_date '.' par_plotformat]);
end
%
% save mask for reference (not used as an input)
fprint_2DM(go_mask(:,:),[],[[str_dirout '/' str_nameout] '.omask_out.FINAL.txt'],'%4.1f','%4.1f',true,false);
fprintf(' - .mask_out.FINAL.dat saved\n')
%
% calculate new fractional area
[so_farea,so_farearef] = fun_grid_calc_ftotarea(go_mask,go_lone,go_late);
disp([' * Final land area fraction = ', num2str(1.0-so_farea)]);
%
% *** RE-GRID TOPO ****************************************************** %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. RE-GRIDING TOPOGRAPHY ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
%
switch str(1).gcm
case {'hadcm3','hadcm3l','foam','cesm','rockee','mat'}
% initial re-gridding of topo
% NOTE: need to transpose around [gi_topo] to have correct input format
% to make_regrid_2d
% similarly, output needs to be transposed back again
% NOTE: pass edges of c-grid
[go_topo,go_ftopo] = make_regrid_2d(gi_lonce,gi_latce,gi_topo',go_lone,go_late,opt_debug);
disp([' - Topography re-gridded.']);
go_topo = go_topo';
go_ftopo = go_ftopo';
case {'k1','k2'}
% ensure that any new 'land' is assigned '90' in the k1
loc_dry = intersect(find(go_mask == 0),find(go_k1 <= par_max_k));
if ~isempty(loc_dry)
go_k1(loc_dry) = 90;
end
% convert k1 to depth
[go_topo] = fun_conv_k1(go_de,go_k1);
disp([' (Nothing to re-grid -- convert k1 file data.)']);
otherwise
% create a k1 first and convert to depth
% (even though later this is converted back again ...)
% NOTE: scale depth cannot be used because it is not necessary
% the final maximum ocean depth
% filter mask value 0 (land) to a k1 value 'land' (90)
%%%go_topo = par_max_D*go_mask;
go_k1 = par_min_k*go_mask;
go_k1(find(go_k1==0))=90;
[go_topo] = fun_conv_k1(go_de,go_k1);
disp([' (Nothing to re-grid -- set uniform ocean depth.)']);
end
% plot & save initial topo re-grid
if ( ~strcmp(str(1).gcm,'k1') || ~strcmp(str(1).gcm,'k2') )
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_topo),99999.0,'',[[str_dirout '/' str_nameout] '.topo_out.RAW'],'topo out -- RAW');
else
figure; imagesc(go_topo); colorbar; title('topo out -- RAW'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.topo_out.RAW'] '.' str_date '.' par_plotformat]);
end
end
%
% *** RE-GRID VERTICALLY ************************************************ %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. RE-GRIDING OCEAN BATHYMETRY ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
%
switch str(1).gcm
case {'k1','k2'}
disp([' (Nothing to re-grid as k1 file already loaded.)']);
otherwise
% convert depth into k levels (and create k1 grid)
[go_k1] = find_grid_k(par_min_Dk,go_dm,go_de,go_mask,go_topo);
fprintf(' - Bathymetry re-gridding complete.\n')
end
% filter min k value
go_k1(find(go_k1 < par_min_k)) = par_min_k;
% plot initial k1 re-grid
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_k1),89.0,'',[[str_dirout '/' str_nameout] '.k1_out.RAW'],'k1 out -- RAW re-gridded');
else
figure; imagesc(go_k1); colorbar; title('k1 out -- RAW re-gridded'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.k1_out.RAW'] '.' str_date '.' par_plotformat]);
end
%
% *** ADJUST TOPO -- AUTOMATIC BATHYMETRY FILTERING ********************* %
%
n_step = n_step+1;
if (opt_debug), input('Press return to CONTINUE ...'); end
%
% carry out basic automatic topo filtering
if (opt_filtertopo)
%
disp(['> ' num2str(n_step) '. FILTERING BATHYMETRY ...']);
%
[go_k1] = fun_grid_topo_filter(go_k1);
fprintf(' - Topography filtered.\n')
% plot adjusted k1 re-grid
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_k1),89.0,'',[[str_dirout '/' str_nameout] '.k1_out.FILTERED'],'k1 out -- auto filtered');
else
figure; imagesc(go_k1); colorbar; title('k1 out -- auto filtered'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.k1_out.FILTERED'] '.' str_date '.' par_plotformat]);
end
end
%
% *** ADJUST TOPO -- USER! ********************************************** %
%
if (opt_user)
n_step = n_step+1;
disp(['> ' num2str(n_step) '. USER EDITING OF TOPO ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
% filter for ocean but not depth info (k > kmax)
% search for ocean in the mask that has a 'land' value ...
% set to the shallowest k1 level and a nominal middepth of that level
% NOTE: shallowest *allowed* k1 level (by par_min_Dk)
loc_dry = intersect(find(go_mask == 1),find(go_k1 > par_max_k));
if ~isempty(loc_dry)
go_k1(loc_dry) = (par_max_k-(par_min_Dk-1));
go_topo(loc_dry) = -go_dm(par_max_k);
end
% user-editing! what can go wrong?
[go_k1] = fun_grid_edit_k1(go_k1,kmax);
% plot mask
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_k1),89.0,'',[str_dirout '/' str_nameout '.k1_out.USEREDITED'],'k1 out -- user edited version');
else
figure; imagesc(go_k1); colorbar; title('k1 out -- user edited version'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.k1_out.USEREDITED'] '.' str_date '.' par_plotformat]);
end
% convert k-levels back to depth
[go_topo] = fun_conv_k1(go_de,go_k1);
%
fprintf(' - User-editing complete.\n')
%
end
%
% *** REPORT FINAL TOPO ************************************************* %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. FINAL TOPO ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
%
% plot final topo
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_masknan.*go_topo),99999.0,'',[[str_dirout '/' str_nameout] '.topo_out.FINAL'],'topo out -- FINAL version');
else
figure; imagesc(go_masknan.*go_topo); colorbar; title('topo out -- FINAL version'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.topo_out.FINAL'] '.' str_date '.' par_plotformat]);
end
%
% *** REPORT FINAL K1 *************************************************** %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. FINAL K1 ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
%
% plot final k1
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_masknan.*go_k1),89.0,'',[str_dirout '/' str_nameout '.k1_out.ocean.FINAL'],'k1 out -- FINAL ocean version');
else
figure; imagesc(go_masknan.*go_k1); colorbar; title('k1 out -- FINAL ocean version'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.k1_out.ocean.FINAL'] '.' str_date '.' par_plotformat]);
end
%
% *** CALCULATE RUNOFF & COMPLETE k1 FILE ******************************* %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. CALCULATING RUN-OFF AND GENERATE .k1 FILE ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
%
% NOTE: ordering is a little illogical becasue
% make_grid_runoff_rnd requires the extended grid, while
% make_grid_runoff_roof is easier done without ...
%
% (A) create roofing runoff scheme
% NOTE: existing runoff information will be retained ...
% values of '90' will indicate run-off needs to be re-generated
if ( ~opt_makerndrunoff && (max(go_k1,[],"all") >= 90) )
[go_k1] = make_grid_runoff_roof(go_mask,go_k1,str);
% create simplified k1 grid value scale for plotting
loc_k1 = go_k1;
loc_k1(find(loc_k1 < 91)) = 95;
end
% extend k1 grid
% NOTE: mark first row: maxk+1, last as maxk+2
% (so, slightly different from standard/original GENIE format)
goex_k1 = go_k1;
goex_k1 = [goex_k1(1,:); goex_k1; goex_k1(end,:)];
goex_k1(1,:) = kmax+1;
goex_k1(end,:) = kmax+2;
% add buffer columns for E-W wall
goex_k1 = [goex_k1(:,end) goex_k1 goex_k1(:,1)];
%
% (B) create random runoff grid (if selected)
if ( opt_makerndrunoff && (max(go_k1,[],"all") >= 90) )
[goex_k1] = make_grid_runoff_rnd(goex_k1,str,opt_debug);
% create simplified k1 grid value scale for plotting
loc_k1 = goex_k1(2:end-1,2:end-1);
loc_k1(find(loc_k1 < 91)) = 95;
end
%
% PLOT & SAVE
% plot runoff
if (max(go_k1,[],"all") >= 90)
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(loc_k1),95.0,'',[str_dirout '/' str_nameout '.k1_out.RUNOFF'],'k1 out -- RUNOFF');
else
figure; imagesc(loc_k1); colorbar; title('k1 out -- RUNOFF'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.k1_out.RUNOFF'] '.' str_date '.' par_plotformat]);
end
end
% save final land k1
fprint_2DM(goex_k1(:,:),[],[[str_dirout '/' str_nameout] '.k1'],'%3i','%3i',true,false);
fprintf(' - .k1 file saved\n')
% plot final land k1
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_masknotnan.*go_k1),95.0,'',[str_dirout '/' str_nameout '.k1_out.land.FINAL'],'k1 out -- FINAL land version');
else
figure; imagesc(go_masknotnan.*go_k1); colorbar; title('k1 out -- FINAL land version'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.k1_out.land.FINAL'] '.' str_date '.' par_plotformat]);
end
%
% *** IDENTIFY ISLANDS ************************************************** %
%
if opt_makegold
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. IDENTIFY ISLANDS ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
% initial islands count
[go_islands,n_islands,i_islands] = find_grid_islands(go_mask);
% plot islands
if (isempty(par_plotformat))
%
elseif (strcmp(par_plotformat,'pdf'))
plot_2dgridded(flipud(go_islands),999,'',[[str_dirout '/' str_nameout] '.islnd_out.INIT'],'island out -- INITIAL');
else
figure; imagesc(go_islands); colorbar; title('island out -- INITIAL'); exportgraphics(gcf,[[[str_dirout '/' str_nameout] '.islnd_out.INIT'] '.' str_date '.' par_plotformat]);
end
%
end
%
% *** UPDATE ISLANDS AND ISLAND PATHS *********************************** %
%
if opt_makegold
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. UPDATING ISLANDS & PATHS ...']);
if (opt_debug), input('Press return to CONTINUE ...'); end
% (1) generate generic borders around all (initial) islands
% NOTE: co_borders is the cell array equivalent of go_borders
% but which is initially created as an array of empty matrices
% NOTE: generate all possible paths initially (and filter later)