-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmuffingen.m
1807 lines (1803 loc) · 84.7 KB
/
muffingen.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 [] = muffingen(POPT)
% muffingen
%
% ***********************************************************************
% *** muffingen [MAKE MUFFIN CONFIG] ************************************
% ***********************************************************************
%
% muffingen(POPT)
% takes 1 argument:
% POPT [STRING] (e.g., 'muffingen_settings_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 (muffingen_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 ***********************************************************
% ***********************************************************************
%
% 14/01/04: renamed and generalized yoolarate_hadcm3
% 14/02/09: changed to new re-gridding routine
% also updated plotting
% set opengl rendering to 'neverselect' to fix plotting bug
% 15/04/30: moved experiment name into parameter file
% 16/03/10: time to sort sh*t out ...
% added new parameter file parameters
% (sub-gridding)
% 16/08/23: no really ... this time ...
% (and complete re-build and simplification of the function)
% 16/09/09: a little mroe getting-it-together ...
% 17/02/??: lots of work ...
% 17/02/23: removed most input parameters (now in option file)
% & renamed function
% 17/02/24: added paths
% added user-selectable output dir for output
% 17/02/26: edits to results path
% alt option for 'GCM' ('k1')
% improved code formatting and messaging
% updated island ordering (largest now occurring first as #1)
% & creation of .psiles grid
% 17/02/27: fixed paths calculation
% 17/02/28: added visual output of paths
% 17/03/05: worked on winds ...
% 17/03/10: more winds ...
% 17/03/13: added SEDGEM component
% removed unused first passed parameter
% 17/03/18: added user modification of mask
% added used modification of k1 (topography)
% *** VERSION 0.1 *********************************************
% 17/03/20: adjusted a few parameter option names
% fixed user-editing of mask and k1
% added user-editing of borders
% 17/03/22: developed text file (k1 or mask) input
% 17/03/23: fixed paths output
% revised & added EXAMPLES (but need cleaning up)
% 17/03/24: further path revision
% 17/03/24: path generation fixing ... finished(!)
% 17/03/26: added logging
% added saving of config file parameter lines
% fixed bug in path cleanup
% added checking for tripple junctions in paths
% *** VERSION 0.2 *********************************************
% 17/03/31: added FOAM option code
% split apart functions for HadCM3 vs. FOAM
% renamed GCM option hadcm3l -> hadcm3
% 17/04/02: completed FOAM GCM option (wind product re-gridding)
% *** VERSION 0.3 *********************************************
% 17/04/18: sorted out blank option
% added (non GCM) albedo profile generation
% revised messaging
% *** VERSION 0.31 ********************************************
% 17/04/19: revised config file output (added SEDGEM and ROKGEM lines)
% added calculation of solar constant and salinity (from age)
% *** VERSION 0.32 ********************************************
% 17/06/05: fixed missing albedo parameter output ...
% *** VERSION 0.33 ********************************************
% 17/06/07: adjusted mask filtering option behavior
% *** VERSION 0.34 ********************************************
% 17/07/21: added orbital parameters
% added options for prescribing specific netCDF filenames
% 17/07/22: revised file path and name passing and usage
% *** VERSION 0.35 ********************************************
% 17/07/23: added BIOGEM parameters to base config output
% *** VERSION 0.36 ********************************************
% 17/07/27: added simple ('roof') runoff generator
% *** VERSION 0.37 ********************************************
% 17/07/28: small modifications to grid filtering [fun_grid_topo_filter]
% removal fo flagging of border topology issues in border #1
% (becasue it is not used ot generate a path from)
% [find_grid_borders_check]
% *** VERSION 0.4 *********************************************
% 17/07/30: added plot to random runoff generation
% *** VERSION 0.41 ********************************************
% 17/07/31: fixed bug in roofing runoff scheme
% *** VERSION 0.42 ********************************************
% 17/08/04: added air-sea gas exchange parameter re-scaling (HadCM3 FOAM)
% *** VERSION 0.43 ********************************************
% 17/08/15: edited output format for 2D albedo
% 17/08/16: added minimum ocean k value parameter
% (e.g. for flat-bottom ocean)
% *** VERSION 0.5 *********************************************
% 17/08/22: added paleo Ca/Mg
% *** VERSION 0.51 ********************************************
% 17/08/24: added max age (100 Ma) for paleo Ca/Mg
% *** VERSION 0.52 ********************************************
% 17/08/25: fixed bug in written-out file input paths
% *** VERSION 0.53 ********************************************
% 17/10/13: added data path
% *** VERSION 0.54 ********************************************
% 17/10/16: changed '\' -> '/'
% ('/' valid under windows MATLAB (as well as normal Win '\')
% fixed parsing of which return (to avoid occurrence of '//')
% *** VERSION 0.55 ********************************************
% NOW MacOSX FRIENDLY!!!
% 17/10/19: added zip-file extraction for HadCM3L 'sed' netCDF file
% *** VERSION 0.56 ********************************************
% 17/10/20: added par_wor_name (world name) length check
% revised wind velocity component naming (now x and y)
% (consistent with tau components)
% *** VERSION 0.57 ********************************************
% 17/10/22: added option to control assignment of zonal wind stress
% added calibrated air-sea gas exchange scaling parameter
% for zonal wind stress
% *** VERSION 0.58 ********************************************
% 17/11/29: fixed erroreous default longitude of perihelion
% *** VERSION 0.59 ********************************************
% 17/12/27: minor comment edits, plus corrected default parameter set
% 18/02/13: changed log file name
% moved order of <RE-GRID TOPO> (later in sequence)
% *** VERSION 0.60 ********************************************
% 18/04/19: fixes for pole-to-pole continents
% *** VERSION 0.61 ********************************************
% 18/04/19: added check and warning when trying to turn land cell to ocn,
% but when there is no ocean depth value available
% *** VERSION 0.62 ********************************************
% 18/09/19: added minimum wind stress value [make_grid_winds_zonal.m]
% *** VERSION 0.63 ********************************************
% 18/10/17: minor messaging changes
% *** VERSION 0.64 ********************************************
% 19/01/29: added a parameter to enable n ocean layers to be selected,
% but with maximum depth scaled such that surface ocean layer
% is the same (this is the parameter -- par_sur_D)
% *** VERSION 0.65 ********************************************
% 19/02/21: fixed missing pass of par_sur_D in 2nd make_genie_grid call
% *** VERSION 0.66 ********************************************
% 19/02/25: made distinction between HadCM3 and HadCM3L
% (including moving sed grid generation earlier)
% added option not to create and show plots [MUCH FASTER!!]
% rationalized stage numbering
% *** VERSION 0.67 ********************************************
% 19/02/28: added option for zonal rather than GCM winds for GCM configs
% fixed issues with hadcm3/hadcm3l distinction
% name more consistent wind product file naming convention
% (replacing '_' with '.')
% *** VERSION 0.68 ********************************************
% 19/03/03: changed detault of surface layer depth scaling [par_sur_D]
% to zero (to disable non conventional grid creation)
% NOTE: scale depth for a 5000 m 16-level ocean, is 80.840706 m
% *** VERSION 0.69 ********************************************
% 19/03/11: added option for CESM input
% also tidied up the HadCM3/HadCM3l options a little
% *** VERSION 0.70 ********************************************
% 19/03/11: fixed FOAM nc name bug
% *** VERSION 0.71 ********************************************
% 19/03/12: further back-compatability
% added new option for specifying how wind speed is
% averaged/calculated
% *** VERSION 0.72 ********************************************
% 19/03/13: added new mask option for modifying FINAL mask
% *** VERSION 0.73 ********************************************
% 19/03/17: finalized CESM air-sea gas transfer coefficient settings
% *** VERSION 0.74 ********************************************
% 19/05/15: fix for incorrect (sign, NaN) SEDGEM topo
% and shitty SEDGEM mask output
% *** VERSION 0.75 ********************************************
% 19/06/10: added (crude) functionality for ROCKE-3D GCM input
% NOTE: no air-sea gas exchange calibration yet
% (or any testing ...)
% *** VERSION 0.76 ********************************************
% 19/06/19: generalized out grid in make_regrid_2d
% *** VERSION 0.77 ********************************************
% 19/07/04: initialization bug-fix
% *** VERSION 0.78 ********************************************
% 19/07/08: added an alt 'k1' format -- 'k2'
% (as per k1, but without the 'borders' / data buffer)
% *** VERSION 0.79 ********************************************
% 19/08/14: minor netCDF name bug-fixes
% *** VERSION 0.80 ********************************************
% 19/10/23: change to how missing and empty parameter options are handled
% for GCM netCDF file names
% *** VERSION 0.81 ********************************************
% 19/11/08: added mask editing modifications
% added new default of not forcing tripple junctions to be
% corrected manually ... (may ... not always be safe?)
% *** VERSION 0.82 ********************************************
% 19/11/17: cosmetic changes ...
% *** VERSION 0.83 ********************************************
% 19/11/19: adjusted sed depth saving and SEDGEM mask generation
% *** VERSION 0.84 ********************************************
% 19/11/22: tempoary fixes and addiitons ...
% *** VERSION 0.00 ********************************************
% 19/12/03: enabled minimal plotting for 'no plotting' option ... :o)
% *** VERSION 0.85 ********************************************
% 20/02/25: enabled high res topo input
% 20/02/26: rationalized how standard-compatable deeper oceans are made
% *** VERSION 0.86 ********************************************
% 20/03/09: removed return of an updated maxim depth in calls to
% make_genie_grid
% *** VERSION 0.87 ********************************************
% 20/04/08: bug-fix of .mat input path
% bug-fix of conversion of MASK option mask to k1
% *** VERSION 0.88 ********************************************
% 20/04/22: bux-fix to find_grid_borders_check
% fix for 5 vs. 6-character UM code length
% removed creation of raw path for the 1st border
% in find_grid_paths
% (it is never made into a complete path anyway)
% *** VERSION 0.89 ********************************************
% 21/01/22: added explicit limits for SEDGEM take topography
% also updated the hypsographic curve used (little difference)
% *** VERSION 0.90 ********************************************
% 21/03/17: version numbering now aligned with cgenie.muffin
% *** v0.9.20 *************************************************
% 21/06/28: edit to HadCM3/l 'a.pdclann' string .nc filename
% *** v0.9.21 *************************************************
% 22/04/25: changed paleo [Ca], [Mg] to: Zeebe and Tyrrell [2019]
% (and added [SO4])
% *** v0.9.22 *************************************************
% 22/05/19: fix bug in output for paleo [Ca], [Mg], [SO4]
% *** v0.9.23 *************************************************
% 22/10/26: altered the roofing runoff scheme to retain existing
% directions (e.g. when using a k1 file as input)
% also, to improve the user experience, if there are no
% path problems, user input is now automatically disabled
% also also ... hopefully fixed topo editing color scale issues
% (and corrected an accidental k=3 depth truncation in the
% EXAMPLE_K1_permian example)
% *** v0.9.24 *************************************************
% 23/04/05: interim extension for generating ENTS config files
% (from HadCM3(L))
% *** v0.9.25 *************************************************
% 24/02/20: fixes for high res SEDGEM grids by Alexandre Pohl
% *** v0.9.26 *************************************************
%
% ***********************************************************************
%%
% *********************************************************************** %
% *** INITIALIZE MUFFINGEN ********************************************** %
% *********************************************************************** %
%
% *** initialize muffingen ********************************************** %
%
disp([' ']);
disp(['>>> INITIALIZING ...']);
% set function name
str_function = 'muffingen';
% set version!
str_muffingen_ver = 'v0.9.26';
% set date
str_date = [datestr(date,11), datestr(date,5), datestr(date,7)];
% close existing plot windows
% end any active journaling
% NOTE: don't clear variable space here ...
close all;
ans = get(0,'Diary');
if strcmp(ans,'on'), diary off; end
% load options file
if isempty(POPT), POPT='muffingen_settings_BLANK'; end
eval(POPT);
%
% *** backwards compatability ******************************************* %
%
% zonal wind-stress generaton parameter
if ~exist('par_tauopt','var'), par_tauopt = 0; end
% ENTS-enabled output??
if ~exist('opt_makeents','var'), opt_makeents = true; end
% surface layer reference thickness (m)
if ~exist('par_sur_D','var'), par_sur_D = 0.0; end
% minimum k level
if ~exist('par_min_k','var'), par_min_k = 1; end
% create plots?
if ~exist('opt_plots','var'), opt_plots = true; end
% debug?
if ~exist('opt_debug','var'), opt_debug = false; end
% make zonal winds (rather than re-grid GCM)?
if ~exist('opt_makezonalwind','var'), opt_makezonalwind = false; end
% set dummy mask nc name
% NOTE: backwards compatability provided by
% subsequent default variable name setting
%if ~exist('par_nc_mask_name','var'), par_nc_mask_name = ''; end
% mask mask!
if ~exist('par_mask_mask_name','var'), par_mask_mask_name = ''; end
% number of additional ocean levels to assign
if ~exist('par_add_Dk','var'), par_add_Dk = 0; end
% sediment depth bounds
% NOTE: these implict defaults do not quite preserve the orignal ones
% (the minimum, surface depth differs from go_de(kmax-(par_min_Dk-1))
% whose value is not know at this point)
if ~exist('par_sed_Dmin','var'), par_sed_Dmin = 0.0; end
if ~exist('par_sed_Dmax','var'), par_sed_Dmax = par_max_D; end
%
% *** 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,'.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
%
% deal with meta selections
if opt_makeall
opt_makemask=true; %
opt_maketopo=true; %
opt_makeocean=true; %
opt_makerunoff=true; %
opt_makewind=true; %
opt_makealbedo=true; %
opt_makeents=true; %
opt_makeseds=true; %
opt_filtermask=true; %
opt_filtertopo=true; %
end
if opt_makeseds
opt_maketopo=true;
end
% adjust options according to input (GCM) type
switch par_gcm
case {'hadcm3','hadcm3l','foam','cesm','rockee'}
case {'k1','mask','k2','mat'}
otherwise
opt_makeall=false;
opt_user=true;
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
%
% *** initialize I/O **************************************************** %
%
% add library path to muffingen functions
% NOTE: find where muffin 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 '/' par_dpath_source]);
addpath([tmp_path '/' 'DATA']);
% 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_mask_name);
%
% *** initialize reporting ********************************************** %
%
% initialize muffingen step number
n_step = 0;
% create copy of .m file options
copyfile([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 muffingen ',str_muffingen_ver]);
disp([' We are going to make a GREAT model configuration!']);
disp(['------------------------------------------------------------']);
disp([' ']);
%
% *********************************************************************** %
% *********************************************************************** %
% *** 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 muffingen settings
switch str(1).gcm
case {'hadcm3','hadcm3l','foam'}
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 muffingen']);
disp(['--------------------------------------------------------']);
case {'k1','mask','k2','mat'}
otherwise
opt_makeall=false;
opt_user=true;
end
%
% *** SET UP OUTPUT GRID ************************************************ %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. CREATING GENIE GRID ...']);
% 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 ...']);
%
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 error.']);
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 ...']);
%
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 (opt_plots), plot_2dgridded(flipud(gi_mask),2.0,'',[[str_dirout '/' str_nameout] '.mask_in'],['mask in']); end
if (opt_plots), plot_2dgridded(flipud(gi_topo),6000.0,'',[[str_dirout '/' str_nameout] '.topo_in'],['topo in']); 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 (opt_plots), plot_2dgridded(flipud(gi_mask),2.0,'',[[str_dirout '/' str_nameout] '.mask_in'],['mask in']); end
if (opt_plots), plot_2dgridded(flipud(gi_topo),6000.0,'',[[str_dirout '/' str_nameout] '.topo_in'],['topo in']); 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 ****************************************************** %
%
n_step = n_step+1;
disp(['> ' num2str(n_step) '. RE-GRIDING MASK ...']);
%
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 (opt_plots), plot_2dgridded(flipud(go_mask),2.0,'',[[str_dirout '/' str_nameout] '.omask_out.RAW'],['ocean mask out -- RAW re-gridded']); end
%
% *** FILTER MASK ******************************************************* %
%
n_step = n_step+1;
% 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_makemask && (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 (opt_plots), plot_2dgridded(flipud(go_mask),2.0,'',[[str_dirout '/' str_nameout] '.omask_out.v' str_ver],['ocean mask out -- version ' str_ver]); 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 (opt_plots), plot_2dgridded(flipud(go_mask),2.0,'',[[str_dirout '/' str_nameout] '.omask_out.v' str_ver],['ocean mask out -- version ' str_ver]); 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 (opt_plots), plot_2dgridded(flipud(go_oceans),999,'',[[str_dirout '/' str_nameout] '.ocean_out.INIT'],['oceans out -- INITIAL']); 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 (opt_plots), plot_2dgridded(flipud(go_mask),2.0,'',[[str_dirout '/' str_nameout] '.omask_out.v' str_ver],['ocean mask out -- version ' str_ver]); 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 -- USER! ********************************************** %
%
n_step = n_step+1;
%
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 (opt_plots), plot_2dgridded(flipud(go_mask),2,'',[[str_dirout '/' str_nameout] '.omask_out.v' str_ver],['ocean mask out -- version ' str_ver]); 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 ...']);
%
% load and apply mask mask to ocean mask!
if ~isempty(str(1).mask)
loc_mask = fun_read_mask(str);
go_mask(find(loc_mask == 1)) = 1;
go_mask(find(loc_mask == -1)) = 0;
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 (opt_plots), plot_2dgridded(flipud(go_mask),99999.0,'',[[str_dirout '/' str_nameout] '.omask_out.FINAL'],['ocean mask out -- FINAL version']); end
%
% save mask
fprint_2DM(go_mask(:,:),[],[[str_dirout '/' str_nameout] '.omask_out.FINAL.dat'],'%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;
%
if opt_maketopo
%
disp(['> ' num2str(n_step) '. RE-GRIDING TOPOGRAPHY ...']);
%
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 (opt_plots), plot_2dgridded(flipud(go_topo),99999.0,'',[[str_dirout '/' str_nameout] '.topo_out.RAW'],['topo out -- RAW']); end
end
%
end
%
% *** RE-GRID VERTICALLY ************************************************ %
%
n_step = n_step+1;
%
if opt_maketopo
%
disp(['> ' num2str(n_step) '. RE-GRIDING OCEAN BATHYMETRY ...']);
%
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 (opt_plots), plot_2dgridded(flipud(go_k1),89.0,'',[[str_dirout '/' str_nameout] '.k1_out.RAW'],['k1 out -- RAW re-gridded']); end
%
end
%
% *** ADJUST TOPO -- AUTOMATIC BATHYMETRY FILTERING ********************* %
%
n_step = n_step+1;
%
% carry out basic automatic topo filtering
if opt_maketopo && 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 (opt_plots), plot_2dgridded(flipud(go_k1),89.0,'',[[str_dirout '/' str_nameout] '.k1_out.FILTERED'],['k1 out -- auto filtered']); end
end
%
% *** ADJUST TOPO -- USER! ********************************************** %
%
n_step = n_step+1;
%
if (opt_maketopo && opt_user)
% 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
%
disp(['> ' num2str(n_step) '. USER EDITING OF TOPO ...']);
% user-editing! what can go wrong?
[go_k1] = fun_grid_edit_k1(go_k1,kmax);
% plot mask
if (opt_plots), plot_2dgridded(flipud(go_k1),89.0,'',[str_dirout '/' str_nameout '.k1_out.USEREDITED'],['k1 out -- user edited version']); end
% convert k-levels back to depth
[go_topo] = fun_conv_k1(go_de,go_k1);
%
fprintf(' - User-editing complete.\n')
%
end
%
if (opt_maketopo)
% plot final topo
if (opt_plots), plot_2dgridded(flipud(go_masknan.*go_topo),99999.0,'',[[str_dirout '/' str_nameout] '.topo_out.FINAL'],['topo out -- FINAL version']); end
% plot final k1
if (opt_plots), plot_2dgridded(flipud(go_masknan.*go_k1),89.0,'',[str_dirout '/' str_nameout '.k1_out.ocean.FINAL'],['k1 out -- FINAL ocean version']); end
end
%
% *** CALCULATE RUNOFF & COMPLETE k1 FILE ******************************* %
%
n_step = n_step+1;
%
% NOTE: ordering is a little illogical becasue
% make_grid_runoff_rnd requires the extended grid, while
% make_grid_runoff_roof is easier done without ...
if opt_makeocean
%
disp(['> ' num2str(n_step) '. CALCULATING RUN-OFF AND GENERATE .k1 FILE ...']);
% (i) first, check for all ocean
if (max(max(go_k1)) < 90), opt_makerunoff = false; end
% (ii) create roof scheme (if selected)
if (opt_makerunoff && par_runoffopt == 0)
[go_k1] = make_grid_runoff_roof(go_mask,go_k1,str);
loc_k1 = go_k1;
loc_k1(find(loc_k1 < 91)) = 95;
if (opt_plots), plot_2dgridded(flipud(loc_k1),95.0,'',[str_dirout '/' str_nameout '.k1_out.RUNOFF'],['k1 out -- RUNOFF']); end
end
% (iii) extend k1 grid
% NOTE: mark first row: maxk+1, last as maxk+2
% (so, slightly different from standard/original GENIE format)