-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplot_fields_biogem_3d_i.m
More file actions
2466 lines (2449 loc) · 100 KB
/
plot_fields_biogem_3d_i.m
File metadata and controls
2466 lines (2449 loc) · 100 KB
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 [OUTPUT] = plot_fields_biogem_3d_i(PEXP1,PEXP2,PVAR1,PVAR2,PT1,PT2,PIK,PMASK,PCSCALE,PCMIN,PCMAX,PCN,PDATA,POPT,PNAME)
% plot_fields_biogem_3d_i
%
% ******************************************************************* %
% *** biogem i-SECTION (LAT-LAY) + INTEGRATED PLOTTING ************* %
% ******************************************************************* %
%
% plot_fields_biogem_3d_i(PEXP1,PEXP2,PVAR1,PVAR2,PT1,PT2,PIK,PMASK,PCSCALE,PCMIN,PCMAX,PCN,PDATA,POPT,PNAME)
% plots slices and zonally averaged vertical sections from the BIOGEM 3-D
% netCDF data file 'fields_biogem_3d.nc' and takes 15 arguments:
%
% PEXP1 [STRING] (e.g. 'preindustrial_spinup')
% --> the (first) experiment name
% PEXP2 [STRING] [OPTIONAL] (e.g. 'enhanced_export')
% --> the experiment name of 2nd, optional, netCDF file
% --> leave EXP2 blank, i.e., '', for no second netCDF file
% PVAR1 [STRING] (e.g. 'ocn_PO4')
% --> id the name of 1st variable to be plotted
% --> all valid valiable names will be listed if an invalid name is given
% PVAR2 [STRING] [OPTIONAL] (e.g. 'ocn_NO3')
% --> id the name of 2nd, optional, variable
% PT1 [REAL] (e.g. 1999.5)
% --> the (first) time-slice year
% --> all valid years will be listed if an invalid year is given
% PT2 [REAL] [OPTIONAL] (e.g. 0.5)
% --> the year of the 2nd, optional, time-slice
% --> set PT2 to -1 for no second time-slice
% PIK [INTEGER] (e.g. 32)
% --> the meridional section to be plotted (the 'i' slice)
% (in the absence of a mask being specified)
% --> a zero will result in a global zonak mean being calculated
% but with model-data carried out on the grid as a whole
% --> a -1 will result in only surface and benthic surface data
% PMASK [STRING] (e.g. 'mask_worjh2_Indian.dat')
% --> the filename containing the meridional mask to construct the zonal average
% --> the full filename must be give, including any extensions
% --> leave MASK blank, i.e., '', for no mask
% PCSCALE [REAL] (e.g. 1.0)
% --> the scale factor for the plot
% e.g., to plot in units of micro molar (umol kg-1), enter: 1e-6
% to plot in units of PgC, enter: 1e15
% to plot negative values, enter: -1
% --> the plot is auto-scaled if a value of zero (0.0) is entered
% PCMIN [REAL] (e.g. 0.0)
% --> the minimum scale value
% PCMAX [REAL] (e.g. 100.0)
% --> the maxumum scale value
% PCN [INTEGER] (e.g. 20)
% --> the number of (contor) intervals between minimum and maximum
% scale values
% PDATA [STRING] (e.g. 'obs_d13C.dat')
% --> the filename containing any overlay data set,
% which must be formatted as (space) seperated columns of:
% lat, depth, value
% --> the full filename must be give, including any extensions
% --> leave PDATA blank, i.e., '', for no overlay data
% POPT [STRING] (e.g., 'plotting_config_2')
% --> the string for an alternative plotting parameter set
% --> if an empty (i.e., '') value is passed to this parameter
% then the default parameter set is used
% PNAME [STRING] (e.g., 'my_plot')
% --> the string for an alternative filename
% --> if an empty (i.e., '') value is passed to this parameter
% then a filename is automatically generated
%
% Example
% plot_fields_biogem_3d_i('experiment_1','','ocn_PO4','',1994.5,-1,1,'mask_worjh2_Pacific.dat',1e-6,0.0,2.0,20,'','','')
% will plot the time-slice cenetered on a time of 1994.5,
% of PO4 concentrations zonally averaged according to
% the mask file 'mask_worjh2_Pacific.dat',
% between 0 and 2 umol kg-1 in 20 contour intervals
% experiment is 'experiment_1'
%
% ******************************************************************* %
% *********************************************************************** %
% ***** HISTORY ********************************************************* %
% *********************************************************************** %
%
% 11/05/30: Added time-stamping
% 12/02/10: added in options for: anomoly plotting; data-only plotting
% some code reorganisation / rationalization
% added overturning streamfubnction contour plotting
% 12/06/28: moved streamfunction contour plotting code so that netCDF
% parameters needed for primary data plotting not over-written
% 12/10/16: updated HELP text
% 12/10/18: reordered parameter list
% 12/12/10: updated color bar drawing
% 12/12/13: minor update to streamfunction plotting
% added data simple overlay addition
% also added option to create means
% 12/12/14: adjusted plotting of single contour overlay
% got full (3D netCDF data) anomoly plotting going
% revised filename string
% 12/12/27: bug-fix in non re-gridded obs data (wrong levtor length)
% 12/12/27: added in Taylor diagram and data anomoly plotting
% (adapted from plot_fields_biogem_3d_k.m)
% 13/01/02: bug-fix to highlight contour
% added dashed negative contour option
% fixed small buglette in gridded data plotting
% 13/04/26: added ability to plot MOC only
% => MOC overlay + data only options (but no data)
% 13/08/12: updated stats calculation and output
% 13/08/29: fixed OPSI plotting (vertical axis orientation issue)
% 13/09/09: fixes/improvements to difference plotting
% 13/09/19: adjusted anomoly plotting and added 'no stats' option
% adjusted filename
% added scatter plot
% 13/10/06: created alt anomoly colormap and adjusted anomoly plotting
% added invert color bar option
% 13/11/12: REORGANIZED USER SETTINGS [AND PASSED PARAMETER LIST]
% 13/11/15: bug-fixes and potted changes to start to bring consistent
% with the other function revisions
% 13/11/18: MUTLAB bug-fix(?) for nmax<10 not displaying scatter colors
% 13/11/23: bug-fix on variable name change
% 13/12/04: minor bug fix
% 13/12/09: added topography masking to streamfunction
% 13/12/10: bug-fix for calculating stats between 2 fields with a mask
% 13/12/19: disabled target diagram for now to simplify things
% 13/12/23: added file format selection for 'new' plotting
% fixed bug in model vs. model plotting for an i-slice
% fixed axis lables in cross-plot and added regression line
% 13/12/24: added depth coloring of cross plot and depth range filtering
% 13/12/25: added R2 calc for cross-plot
% fixed up model-data capabilities (e.g. correct masking)
% 14/01/02: fixed 2nd-order poly equation in cross-plot; also 'n' count
% 14/04/07: adjusted cross-plot depth color limits
% 14/04/11: added cross-plot data output
% corrected bug in calculating 'n' (cross-plotting)
% 14/04/09: cross-plot depth scale bug fix
% 14/04/14: more minor bug-fixing ...
% 14/04/15: added alt filename
% added options of not plotting main or secondary figures
% 14/04/17: altered (fixed?) criteria for not ploting the color scale
% 14/06/18: corrected help example
% removel old color-bar plotting option
% 14/08/20: added '%'s to ASCII data output headers
% 14/09/15: set data input consistent with 3D 'k' section plotting
% adjusted global mean plotting setting (now: iplot == 0)
% added alternative (external) plotting scale option
% 14/09/28: developed k-interval restriction on data plotting and stats
% (parameters plot_kmin and plot_kmax)
% 14/09/29: minor bug-fix to the above
% 14/11/09: auto plot format
% 14/12/01: incorporated cbrewer.m colormap schemes (& removed anom map)
% 14/12/03: removed cbrewer.m ... :o)
% 14/12/03: incorporated new make_cmap5 function
% 14/12/07: fixed dim error in flipping color scale
% 14/12/16: adjusted MOC (only) plotting
% 14/12/30: removed cross-plotting and
% instead now call a stand-alone function
% 14/12/30: added nmax to stats output for dual 3D data input
% 15/01/07: adjusted parameter names for restricting k space data
% (now: data_kmin, data_kmax)
% 15/01/09: revised to use new make_cmap5.m (adjusted number of colors)
% 15/01/11: replaced make_cmap5 -> make_cmap
% 15/01/12: adjusted orientation of data_vector_2
% added capability for fine-tuning data shapes and colors
% 15/01/13: bug-fix of recent changes
% 15/02/25: corrected netCDF dim inq (netcdf.inqDimID) command
% (was netcdf.inqvarID! and everything worked by luck ...)
% 15/02/26: added additional NaN data filtering
% added flexibility to load netCDF files from home directory
% 15/03/03: adjusted setting of restricted k interval
% 15/09/04: corrected opsi grid
% added option for calculating opsi from velocity field
% 15/10/14: adjusted contor line widths
% 16/03/01: added documentation marker ('%%') (who knew!)
% added stats function return
% 16/03/02: revised stats output
% 16/05/16: added a new option for 'i' (-1) that resuts in benthic-
% planktic pairs to be masked in (surface + benthic data)
% 16/08/25: fixed output bug in reporting data i index
% added saving of mask of data locations
% 16/09/06: corrected reference to make_cmap5 (and cmap array dim)
% 17/01/20: added option for seperating scaling of model and data data
% [data_scalepoints]
% 17/05/02: added parameter backwards-compatability [data_scalepoints]
% 17/08/01: added return of global mean and inventory
% 17/08/03: adjusted filtering of calculated (and data) OPSI
% 17/08/04: minor edits
% 17/08/28: changed sign of how data_offset is aplied to <data>
% edited model-data output format
% for i==0; model points corresponding to data locations
% NOW equivalent points from 3D field
% NOT zonal mean values
% *** GIT UPLOAD **********************************************
% 17/10/26: rationalized directories and paths (inc. path input params.)
% *** VERSION 1.00 ********************************************
% 17/10/31: adjusted main plot window size
% *** VERSION 1.01 ********************************************
% 17/11/01: adjusted paths ... again ...
% *** VERSION 1.02 ********************************************
% 17/11/02: adjusted paths ... again again ...
% *** VERSION 1.03 ********************************************
% 18/02/19: removed prescribed directory in loading mask file
% *** VERSION 1.06 ********************************************
% 18/02/19: removed NOT data_only requirement for plotting cross-plot
% *** VERSION 1.07 ********************************************
% 18/03/20: some fixes
% (a lesson to be learned here about noting them down ...)
% *** VERSION 1.08 ********************************************
% 18/04/05: added M-score stats output
% *** VERSION 1.09 ********************************************
% 18/07/20: changed initial name of 'raw' netCDF data
% to help avoid potenital issues
% added parameters and code to extract min and max from
% seasonal data
% added code to save all points, and also in an explicit format
% *** VERSION 1.10 ********************************************
% 18/08/21: rename current_path string
% adjusted mask path search
% *** VERSION 1.12 ********************************************
% 18/10/25: added automatic identification of number of data columns
% (and of selection of explicit shapes and colors)
% plus checking of rows in data file (+ simple lon-lat check)
% 18/10/25: shape parameter bug-fix
% *** VERSION 1.15 ********************************************
% 18/11/07: added ps rendering fix ... hopefuly ...
% for MUTLAB version shenanigans
% *** VERSION 1.16 ********************************************
% 18/11/16: further developed model-data (ASCII data) output
% *** VERSION 1.17 ********************************************
% 19/01/07: added data save option
% *** VERSION 1.18 ********************************************
% 19/01/10: added csv format overlay data detection
% added site label character filter
% added alternative mask of (i,j) vector (single) location
% *** VERSION 1.19 ********************************************
% 19/02/27: removed zero contour line, fixed up the 2 alternatives
% *** VERSION 1.20 ********************************************
% 19/03/25: made stats plot optional (selected as secondary plot)
% added alternative structure return from function
% added MOC diagnostics
% *** VERSION 1.22 ********************************************
% 19/03/27: bug fix of STATM -> OUTPUT
% *** VERSION 1.23 ********************************************
% 19/03/31: removed generation of empty STATM array
% *** VERSION 1.24 ********************************************
% 19/05/20: another bug fix of STATM -> OUTPUT
% *** VERSION 1.25 ********************************************
% 19/05/20: adjusted data filtering
% *** VERSION 1.26 ********************************************
% 19/05/20: added stats saving under data_save option
% *** VERSION 1.27 ********************************************
% 19/06/18: added additional profile data plotting
% added additional profile data output
% *** VERSION 1.28 ********************************************
% 19/06/25: fixes for non-standard grid levels
% *** VERSION 1.29 ********************************************
% 19/07/04: added histogram secondary figure plotting
% + minor bug-fix
% *** VERSION 1.30 ********************************************
% 19/07/08: extended cross-plotting and histogram functionality
% *** VERSION 1.31 ********************************************
% 19/07/08: additional data output
% *** VERSION 1.32 ********************************************
% 19/07/12: added plotting limit cut-off to scatter plot data
% *** VERSION 1.33 ********************************************
% 19/07/14: adjusted plotting limit cut-off
% + a little clean-up
% *** VERSION 1.34 ********************************************
% 19/07/16: added selected model data saving with
% data_save = 'y' (only) set
% *** VERSION 1.35 ********************************************
% 19/08/28: in reading data files, accounted for headers (specified by %)
% in counting total number of (data) lines
% *** VERSION 1.36 ********************************************
% 19/10/03: bug-fix of recent changes ...
% *** VERSION 1.37 ********************************************
% 19/10/03: revised data format checking
% *** VERSION 1.38 ********************************************
% 19/10/15: removed k min,max data parameters from input file
% as in practice, they were always re-calculated & over-written
% *** VERSION 1.39 ********************************************
% 20/01/07: minor adjustment to data point plotting
% + BUG fix
% *** VERSION 1.41 ********************************************
% 20/07/30: minor bug fix in array copy operation
% *** VERSION 1.42 ********************************************
% 20/08/18: (various)
% *** VERSION 1.43 ********************************************
% 20/08/18: bug-fix of recent changes ... :o)
% *** VERSION 1.44 ********************************************
% 20/08/26: align version numbers!
% *** VERSION 1.46 ********************************************
% 20/08/30: (minor? ... cannot remember ... keep version number ...)
% *** VERSION 1.46 ********************************************
% 20/09/04: aligned backwards compatability across functions
% *** VERSION 1.48 ********************************************
% 20/09/25: adjusted data saving
% *** VERSION 1.49 ********************************************
% 20/11/24: ensured stats are always saved, if calculated
% but only if the 'old' data output format is selected
% (parameter: data_output_old)
% Otherwise, the stats are returned by the function and
% can be captured and saved from there.
% *** VERSION 1.50 ********************************************
% 20/12/29: replaced data file load and primary processing code
% *** VERSION 1.51 ********************************************
% 20/12/30: added checks on discrete data (for stats, cross-plotting)
% revised/corrected equivalent model points/values
% *** VERSION 1.52 ********************************************
% 21/01/04: fix to vectorization of model values for mean vs. raw data
% *** VERSION 1.53 ********************************************
% 21/02/25: switched model1 vs. model2 order in cross-plot
% added ASCII data-dump of model1 and model2 3D data
% 21/04/02: added basic stats to the function return
% *** VERSION 1.54 ********************************************
% 21/04/20: adjusted function return stats
% *** VERSION 1.55 ********************************************
% 21/08/27: added detection of archive files (+ unpacking then cleaning)
% *** VERSION 1.58 ********************************************
% 21/08/31: added sum to returned structure, renoved NaNs from vector
% *** VERSION 1.59 ********************************************
% 22/01/19: added loc_flag_unpack = false for data (not GENIE) netCDF
% *** VERSION 1.60 ********************************************
% 22/08/22: made disabling of stats version-independent [removed range]
% *** VERSION 1.62 ********************************************
% 23/01/17: mostly some adjustments to returned data
% *** VERSION 1.63 ********************************************
% 23/05/01: various minor + check for curve fitting toolbox
% and reduce stats output if necessary
% *** VERSION 1.64 ********************************************
% 24/06/11: updated graphics export to pdf option for:
% plot_format_old = 'n'
% *** VERSION 1.66 ********************************************
% n/a not all of the changes have been documented ... :(
% *** VERSION 1.70 ********************************************
%
% *********************************************************************** %
%%
% *********************************************************************** %
% *** INITIALIZE PARAMETERS & VARIABLES ********************************* %
% *********************************************************************** %
%
% *** initialize ******************************************************** %
%
% set version!
par_ver = 1.66;
% set function name
str_function = mfilename;
% close open windows
close all;
% load plotting options
if isempty(POPT), POPT='plot_fields_SETTINGS'; end
eval(POPT);
% set date
str_date = [datestr(date,11), datestr(date,5), datestr(date,7)];
% determine whcih stupid version of MUTLAB we are using
tmp_mutlab = version('-release');
str_mutlab = tmp_mutlab(1:4);
par_mutlab = str2num(str_mutlab);
%
% *** backwards compatability ******************************************* %
%
% data point scaling
if ~exist('data_scalepoints','var'), data_scalepoints = 'n'; end
% data saving
if ~exist('data_save','var'), data_save = 'y'; end % save (mode) data?
if ~exist('data_saveall','var'), data_saveall = 'n'; end
if ~exist('data_saveallinfo','var'), data_saveallinfo = 'n'; end
if ~exist('data_output_old','var'), data_output_old = 'y'; end % return STATM
% extracting min / max / range from seasonal data
if ~exist('data_minmax','var'), data_minmax = ''; end
if ~exist('data_nseas','var'), data_nseas = 0; end
% model-data
if ~exist('data_seafloor','var'), data_seafloor = 'n'; end
% plotting
if ~exist('contour_hlt2','var'), contour_hlt2 = contour_hlt; end
if ~exist('contour_hltval2','var'), contour_hltval2 = contour_hltval; end
if ~exist('plot_psi','var'), plot_psi = 'n'; end
% paths
if ~exist('par_pathin','var'), par_pathin = 'cgenie_output'; end
if ~exist('par_pathlib','var'), par_pathlib = 'source'; end
if ~exist('par_pathout','var'), par_pathout = 'PLOTS'; end
if ~exist('par_pathdata','var'), par_pathdata = 'DATA'; end
if ~exist('par_pathmask','var'), par_pathmask = 'MASKS'; end
if ~exist('par_pathexam','var'), par_pathexam = 'EXAMPLES'; end
% plotting panel options
if ~exist('plot_profile','var'), plot_profile = 'y'; end % PLOT PROFILE
if ~exist('plot_zonal','var'), plot_zonal = 'y'; end % PLOT ZONAL
if ~exist('plot_hist','var'), plot_hist = 'n'; end % PLOT HISTOGRAM
if ~exist('plot_histc_SETTINGS','var'), plot_histc_SETTINGS = 'plot_histc_SETTINGS'; end % histc plotting settings
% misc
if ~exist('data_dataweight','var'), data_dataweight = 'n'; end
%
% *** initialize parameters ********************************************* %
%
% set axes
lat_min = -090;
lat_max = +090;
D_min = 0000;
D_max = 5000;
% null data value
par_data_null = 9.9E19;
%
par_rEarth = 6371000.0;
%
% *** copy passed parameters ******************************************** %
%
% set passed parameters
exp_1 = PEXP1;
exp_2 = PEXP2;
timesliceid_1 = PT1;
timesliceid_2 = PT2;
dataid_1 = PVAR1;
dataid_2 = PVAR2; %%%
iplot = PIK;
data_scale = PCSCALE;
con_min = PCMIN;
con_max = PCMAX;
con_n = PCN;
maskid = PMASK;
overlaydataid = PDATA;
altfilename = PNAME;
%
% *** DEFINE COLORS ***************************************************** %
%
% define contonental color
color_g = [0.75 0.75 0.75];
% define no-data color
color_b = [0.00 0.00 0.00];
%
% *** SCALING *********************************************************** %
%
% set default data scaling
if data_scale == 0.0
data_scale = 1.0;
clear con_min;
clear con_max;
con_n = 10;
end
if strcmp(data_scalepoints,'n')
datapoint_scale = 1.0;
else
datapoint_scale = data_scale;
end
% set global flag if no alt plotting scale is set
% NOTE: catch possibility of one axis being set, but the other @ default
% (min and max with indetical values)
if ((plot_lat_min == plot_lat_max) && (plot_D_min == plot_D_max))
plot_global = true;
plot_xy_scaling = 1.0;
plot_lat_min = lat_min;
plot_lat_max = lat_max;
plot_D_min = D_min;
plot_D_max = D_max;
else
plot_global = false;
if (plot_lat_min == plot_lat_max)
plot_lat_min = lat_min;
plot_lat_max = lat_max;
end
if (plot_D_min == plot_D_max)
plot_D_min = D_min;
plot_D_max = D_max;
end
plot_xy_scaling = ((plot_D_max - plot_D_min)/(D_max - D_min)) / ((plot_lat_max - plot_lat_min)/(lat_max - lat_min));
end
%
% *** OPTIONAL PLOTTING SCALE ******************************************* %
%
if ~isempty(contour_file)
% load data
contour_data = load(contour_file,'-ascii');
% adjust if necessary so that contour_data(1) is the lowest value
if (contour_data(1) > contour_data(end)), contour_data = flipud(contour_data); end
% adjust number of contours
% NOTE: remember that con_n is the number of intervals, not the number of contours (which is con_n+1)
con_n = length(contour_data) - 1;
% set max,min limits
con_min = contour_data(1);
con_max = contour_data(end);
end
%
% *** SET PATHS & DIRECTORIES ******************************************* %
%
% find current path
str_current_path = pwd;
% find where str_function lives ...
% remove its name (+ '.m' extension) from the returned path ...
str_function_path = which(str_function);
str_function_path = str_function_path(1:end-length(str_function)-3);
% check source code directory and add search path
if ~(exist([str_function_path '/' par_pathlib],'dir') == 7)
disp([' * ERROR: Cannot find source directory']);
disp([' ']);
return;
else
addpath([str_function_path '/' par_pathlib]);
end
% check masks directory and add search path
if (exist([str_current_path '/' par_pathmask],'dir') == 7)
addpath([str_current_path '/' par_pathmask]);
elseif (exist([str_function_path '/' par_pathmask],'dir') == 7)
addpath([str_function_path '/' par_pathmask]);
else
disp([' * ERROR: Cannot find MASKS directory -- was it moved ... ?']);
disp([' ']);
return;
end
% set input path
par_pathin = [str_current_path '/' par_pathin];
if ~(exist(par_pathin,'dir') == 7)
disp([' * ERROR: Cannot find experiment results directory']);
disp([' ']);
return;
end
% set output path
par_pathout = [str_current_path '/' par_pathout];
if ~(exist(par_pathout,'dir') == 7), mkdir(par_pathout); end
% check/add data path
if ~(exist([str_current_path '/' par_pathdata],'dir') == 7),
mkdir([str_current_path '/' par_pathdata]);
end
addpath([str_current_path '/' par_pathdata]);
% check plot format setting
if ~isempty(plot_format), plot_format_old='n'; end
% now make make str_function text-friendly
str_function = strrep(str_function,'_','-');
%
% *** FILTER OPTIONS **************************************************** %
%
% there will be no site labels if data is averaged ...
if (data_ijk_mean == 'y'), data_sitelabel = 'n'; end
%
% *********************************************************************** %
% *********************************************************************** %
% *** INITIALIZE ARRAYS ************************************************* %
% *********************************************************************** %
%
xm = [];
ym = [];
zm = [];
lonm = [];
lone = [];
lonw = [];
latm = [];
latn = [];
lats = [];
laym = [];
layt = [];
layb = [];
rawdata=[];
data_0=[];
data_1=[];
data_2=[];
%
% *********************************************************************** %
% *********************************************************************** %
% *** OPEN netCDF DATA & LOAD (OPTIONAL) MASK FILE ********************** %
% *********************************************************************** %
%
% open netCDF file -- test for 'experiment format' or not
% NOTE: other format is indicated by '.nc' extension as experiment ID
if strcmp(exp_1(end-2:end),'.nc')
ncid_1=netcdf.open(exp_1,'nowrite');
loc_flag_unpack = false;
else
% test for experiment
data_dir = [par_pathin '/' exp_1];
if (exist(data_dir, 'dir') == 0)
disp(['ERROR: Experiment cannot be found.']);
if (exist(par_pathin, 'dir') == 0)
disp(['INFO: Path: ' par_pathin ' cannot be found.']);
else
disp(['INFO: Path: ' par_pathin ' exists.']);
disp(['INFO: Experiment name: ' exp_1 ' cannot be found.']);
end
if (exist([data_dir '.tar.gz'],'file'))
disp(['INFO: Archive: ' [data_dir '.tar.gz'] ' exists.']);
disp([' * UN-PACKING ...']);
untar([data_dir '.tar.gz'],par_pathin);
loc_flag_unpack = true;
else
return;
end
else
loc_flag_unpack = false;
end
ncid_1=netcdf.open([par_pathin '/' exp_1 '/biogem/fields_biogem_3d.nc'],'nowrite');
end
% read netCDf information
[~,nvars,~,~] = netcdf.inq(ncid_1); % [ndims,nvars,ngatts,unlimdimid]
%
% *********************************************************************** %
% *********************************************************************** %
% *** SET UP GRID ******************************************************* %
% *********************************************************************** %
%
% load grid data
varid = netcdf.inqVarID(ncid_1,'grid_level');
grid_k1 = netcdf.getVar(ncid_1,varid);
% flip array around diagonal to give (j,i) array orientation
grid_k1 = grid_k1';
% calculate grid dimensions
varid = netcdf.inqDimID(ncid_1,'lat');
[~, dimlen] = netcdf.inqDim(ncid_1,varid); % [dimname, dimlen]
jmax = dimlen;
varid = netcdf.inqDimID(ncid_1,'lon');
[~, dimlen] = netcdf.inqDim(ncid_1,varid); % [dimname, dimlen]
imax = dimlen;
varid = netcdf.inqDimID(ncid_1,'zt');
[~, dimlen] = netcdf.inqDim(ncid_1,varid); % [dimname, dimlen]
kmax = dimlen;
% load remaining grid information
varid = netcdf.inqVarID(ncid_1,'zt');
grid_zt = netcdf.getVar(ncid_1,varid);
grid_zt = flipud(grid_zt);
varid = netcdf.inqVarID(ncid_1,'zt_edges');
grid_zt_edges = netcdf.getVar(ncid_1,varid);
grid_zt_edges = flipud(grid_zt_edges);
% determine grid limits
zt_min = min(grid_zt_edges);
zt_max = max(grid_zt_edges);
% set data limts in k space (based on plotting depth limits)
loc_k = find(grid_zt > plot_D_min);
data_kmax = max(loc_k);
loc_k = find(grid_zt < plot_D_max);
data_kmin = min(loc_k);
% calculate topography
for i = 1:imax,
for j = 1:jmax,
if grid_k1(j,i) <= kmax
topo(j,i) = -grid_zt_edges(grid_k1(j,i));
else
topo(j,i) = 0.0;
end
end
end
% load and calculate remaining grid information
varid = netcdf.inqVarID(ncid_1,'lat');
grid_lat = netcdf.getVar(ncid_1,varid);
varid = netcdf.inqVarID(ncid_1,'lon');
grid_lon = netcdf.getVar(ncid_1,varid);
[latm laym] = meshgrid(grid_lat,-grid_zt);
varid = netcdf.inqVarID(ncid_1,'lat_edges');
grid_lat_edges = netcdf.getVar(ncid_1,varid);
varid = netcdf.inqVarID(ncid_1,'lon_edges');
grid_lon_edges = netcdf.getVar(ncid_1,varid);
[lats layb] = meshgrid(grid_lat_edges(1:jmax),-grid_zt_edges(1:kmax));
[latn layt] = meshgrid(grid_lat_edges(2:jmax+1),-grid_zt_edges(2:kmax+1));
% create area grid
% NOTE: based on:
% gi_area(:,:) = 2.0*pi*(par_rEarth^2)*(sin((pi/180.0)*gi_latn) - sin((pi/180.0)*gi_lats)).*((gi_lone-gi_lonw)/360.0);
grid_area = NaN(jmax,imax);
for i = 1:imax,
for j = 1:jmax,
if grid_k1(j,i) > kmax
grid_area(j,i) = 0.0;
else
grid_area(j,i) = 2.0*pi*(par_rEarth^2)*(sin((pi/180.0)*grid_lat_edges(j+1)) - sin((pi/180.0)*grid_lat_edges(j))).*((grid_lon_edges(i+1)-grid_lon_edges(i))/360.0);
end
end
end
% create cell volume array; also depth
% NOTE: assume equal area grid, normaalized area
% NOTE: multiple by 1.0 becasue ... (?) (to ensure correct format?)
data_V = zeros(kmax,jmax,imax);
data_D = zeros(kmax,jmax,imax);
for k = 1:kmax,
data_V(k,:,:) = grid_area(:,:)*(grid_zt_edges(k) - grid_zt_edges(k+1));
data_D(k,:,:) = grid_zt(k);
end
%
grid_lon_origin = grid_lon_edges(1);
% test for mask 'type'
% load mask data or create mask
% NOTE: mask single location coordinate is (i,j)
% but written to the array as (j,i)
% NOTE: when loading from file,
% flip in j-direction to make consistent with netCDF grid
if ~isempty(maskid)
if isnumeric(maskid)
mask = zeros(jmax,imax);
mask(maskid(2),maskid(1)) = 1.0;
maskid = ['i', num2str(maskid(1)), 'j', num2str(maskid(2))];
elseif ischar(maskid)
maskfile = maskid;
mask = load([maskfile],'-ascii');
mask = flipdim(mask,1);
else
disp([' ']);
error('*WARNING*: Unknown mask parameter type (must be character array or vector location) ... ')
end
end
% apply mask to topography
if ~isempty(maskid)
topo = mask.*topo;
elseif ((iplot == 0) || (iplot == -1))
mask = zeros(jmax,imax);
mask(:,:) = 1.0;
topo = mask.*topo;
else
if ((iplot > imax) || (iplot < -1))
disp([' ']);
error('*WARNING*: Value of iplot out-of-range (-1 to imax): ENDING ... ');
end
mask = zeros(jmax,imax);
mask(:,iplot) = 1.0;
topo = mask.*topo;
end
% load optional data field and create mask for weighting profile averages
% NOTE: the default is a copy of the mask
% (which should leave the calculation unchanged)
% NOTE: also check it exists!
if ((data_dataweight == 'y') && ~isempty(maskid))
if (exist([maskfile '.wght'],'file'))
mask_dataweight = load([maskfile '.wght'],'-ascii');
mask_dataweight = flipdim(mask_dataweight,1);
else
mask_dataweight = mask;
end
else
mask_dataweight = mask;
end
%
% *********************************************************************** %
% *********************************************************************** %
% *** SET PRIMARY GRIDDED DATASET *************************************** %
% *********************************************************************** %
%
% check that the year exists
varid = netcdf.inqVarID(ncid_1,'time');
timeslices = netcdf.getVar(ncid_1,varid);
[~, dimlen] = netcdf.inqDim(ncid_1,varid); % [dimname, dimlen]
clear time;
while exist('time','var') == 0
for n = 1:dimlen,
if double(int32(100*timeslices(n)))/100 == timesliceid_1
time = timesliceid_1;
tid_1 = n;
end
end
if exist('time','var') == 0
disp(' > WARNING: Year #1 must be one of the following;');
format long g;
double(int32(100*timeslices(:)))/100
format;
timesliceid_1 = input(' > Time-slice year: ');
end
end
% check that the variable name exists
varid_1 = [];
while isempty(varid_1)
for n = 0:nvars-1,
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_1,n);
if strcmp(varname,dataid_1)
varid_1 = n;
end
end
if isempty(varid_1)
disp(' > WARNING: Variable #1 name must be one of the following;');
for n = 0:nvars-1,
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_1,n);
varname
end
dataid_1 = input(' > Variable name: ','s');
end
end
% load data
% flip array around diagonal to give (j,i) array orientation
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_1,varid_1);
netcdfdata = netcdf.getVar(ncid_1,varid_1);
if length(dimids) == 4
rawdata(1:imax,1:jmax,1:kmax) = netcdfdata(1:imax,1:jmax,1:kmax,tid_1);
switch data_minmax,
case {'min'}
for j = 1:jmax,
for i = 1:imax,
for k = 1:kmax,
rawdata(i,j,k) = min(netcdfdata(i,j,k,tid:tid+data_nseas-1));
end
end
end
case {'max','minmax'}
for j = 1:jmax,
for i = 1:imax,
for k = 1:kmax,
rawdata(i,j,k) = max(netcdfdata(i,j,k,tid:tid+data_nseas-1));
end
end
end
end
for n = 1:kmax,
data_1(kmax - n + 1,1:jmax,1:imax) = rawdata(1:imax,1:jmax,n)';
end
elseif length(dimids) == 3
rawdata(1:imax,1:jmax,1:kmax) = netcdfdata(1:imax,1:jmax,1:kmax);
for n = 1:kmax,
data_1(kmax - n + 1,1:jmax,1:imax) = rawdata(1:imax,1:jmax,n)';
end
elseif length(dimids) == 2
rawdata(1:imax,1:jmax) = netcdfdata(1:imax,1:jmax);
data_1(1:jmax,1:imax) = rawdata(1:imax,1:jmax)';
else
data_1(:,:,:) = NaN;
end
%
% *********************************************************************** %
% *********************************************************************** %
% *** SET ALTERNATIVE GRIDDED DATASET *********************************** %
% *********************************************************************** %
%
% *** ALT EXPERIMENT **************************************************** %
%
% open new netCDF file if necessary, else reuse 1st netCDF dataset
if ~isempty(exp_2)
% open netCDF file -- test for 'experiment format' or not
% NOTE: other format is indicated by '.nc' extension as experiment ID
if strcmp(exp_2(end-2:end),'.nc'),
ncid_2=netcdf.open(exp_2,'nowrite');
else
ncid_2=netcdf.open([par_pathin '/' exp_2 '/biogem/fields_biogem_3d.nc'],'nowrite');
end
% read netCDf information
[ndims,nvars,ngatts,unlimdimid] = netcdf.inq(ncid_2);
% load data
varid_2 = netcdf.inqVarID(ncid_2,dataid_2);
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_2,varid);
rawdata = netcdf.getVar(ncid_2,varid_2);
else
ncid_2 = ncid_1;
end
%
% *** ALT TIME-SLICE **************************************************** %
%
if timesliceid_2 >= 0.0
% check that the year exists
varid = netcdf.inqVarID(ncid_2,'time');
timeslices = netcdf.getVar(ncid_2,varid);
[dimname, dimlen] = netcdf.inqDim(ncid_2,varid);
clear time;
while exist('time','var') == 0
for n = 1:dimlen,
if double(int32(100*timeslices(n)))/100 == timesliceid_2
time = timesliceid_2;
tid_2 = n;
end
end
if exist('time','var') == 0
disp(' > WARNING: Year #2 must be one of the following;');
format long g;
double(int32(100*timeslices(:)))/100
format;
timesliceid_2 = input(' > Time-slice year: ');
end
end
else
tid_2 = tid_1;
end
%
% *** ALT DATA FIELD **************************************************** %
%
if ~isempty(dataid_2)
% check that the variable name exists
varid_2 = [];
while isempty(varid_2)
for n = 0:nvars-1,
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_2,n);
if strcmp(varname,dataid_2)
varid_2 = n;
end
end
if isempty(varid_2)
disp(' > WARNING: Variable #2 name must be one of the following;');
for n = 0:nvars-1,
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_2,n);
varname
end
dataid_2 = input(' > Variable name: ','s');
end
end
else
varid_2 = varid_1;
end
%
% *** SET DATA ********************************************************** %
%
if (~isempty(exp_2)) || (timesliceid_2 >= 0.0) || (~isempty(dataid_2)),
% load data
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_2,varid_2);
netcdfdata = netcdf.getVar(ncid_2,varid_2);
if length(dimids) == 4
rawdata(1:imax,1:jmax,1:kmax) = netcdfdata(1:imax,1:jmax,1:kmax,tid_2);
switch data_minmax,
case {'min','minmax'}
for j = 1:jmax,
for i = 1:imax,
for k = 1:kmax,
rawdata(i,j,k) = min(netcdfdata(i,j,k,tid_2:tid_2+data_nseas-1));
end
end
end
case 'max'
for j = 1:jmax,
for i = 1:imax,
for k = 1:kmax,
rawdata(i,j,k) = max(netcdfdata(i,j,k,tid_2:tid_2+data_nseas-1));
end
end
end
end
for n = 1:kmax,
data_2(kmax - n + 1,1:jmax,1:imax) = rawdata(1:imax,1:jmax,n)';
end
elseif length(dimids) == 3
rawdata(1:imax,1:jmax,1:kmax) = netcdfdata(1:imax,1:jmax,1:kmax);
for n = 1:kmax,
data_2(kmax - n + 1,1:jmax,1:imax) = rawdata(1:imax,1:jmax,n)';
end
elseif length(dimids) == 2
rawdata(1:imax,1:jmax) = netcdfdata(1:imax,1:jmax);
data_2(1:jmax,1:imax) = rawdata(1:imax,1:jmax)';
else
data_2(:,:,:) = NaN;
end
data_anomoly = 'y';
else
data_2(:,:,:) = 0.0;
end
%
% *********************************************************************** %
% *********************************************************************** %
% *** STREAMFUNCTION **************************************************** %
% *********************************************************************** %
%
% open streamfunction data (if selected)
%
if ~isempty(plot_opsi)
%
if (plot_opsi_calc == 'n')
%
% *** USE PRE-SAVED 2D DATA ********************************************* %
%
% open netCDF file
ncid_0=netcdf.open([par_pathin '/' exp_1 '/biogem/fields_biogem_2d.nc'],'nowrite');
% read netCDf information
[ndims,nvars,ngatts,unlimdimid] = netcdf.inq(ncid_0);
% load grid information
varid = netcdf.inqVarID(ncid_0,'zt');
[dimname, dimlen] = netcdf.inqDim(ncid_0,varid);
zmax = dimlen;
[latm ztm] = meshgrid(grid_lat,-grid_zt);
varid = netcdf.inqVarID(ncid_0,'zt_edges');
opsigrid_zt_edges = flipud(netcdf.getVar(ncid_0,varid));
varid = netcdf.inqVarID(ncid_0,'lat_edges');
opsigrid_lat_edges = netcdf.getVar(ncid_0,varid);
[opsigrid_lat opsigrid_zt] = meshgrid(opsigrid_lat_edges(1:jmax+1),-opsigrid_zt_edges(1:zmax+1));
% set variable name
switch plot_opsi
case {'g'}
varid = netcdf.inqVarID(ncid_0,'phys_opsi');
case 'a'
varid = netcdf.inqVarID(ncid_0,'phys_opsia');
case 'p'
varid = netcdf.inqVarID(ncid_0,'phys_opsip');
otherwise
disp('Unknown opsi definition.')
end
% open data
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_0,varid);
rawdata = netcdf.getVar(ncid_0,varid);
if length(dimids) == 3
rawdata = rawdata(1:jmax+1,1:zmax+1,tid_1);
data_0 = rawdata(1:jmax+1,1:zmax+1)';
elseif length(dimids) == 2
rawdata = rawdata(1:jmax+1,1:zmax+1);
data_0 = rawdata(1:jmax+1,1:zmax+1)';
else
data_0 = NaN*data_0;
end
% invert data to match grid
data_0=flipud(data_0);
else
%
% *** CALCULATE OVERTURNING ********************************************* %
%
% (1a) setup basic grid
zmax = kmax;
[latm ztm] = meshgrid(grid_lat,-grid_zt);
opsigrid_zt_edges = grid_zt_edges;
opsigrid_lat_edges = grid_lat_edges;
[opsigrid_lat opsigrid_zt] = meshgrid(opsigrid_lat_edges(1:jmax+1),-opsigrid_zt_edges(1:zmax+1));
% (1b) create additional grid details
loc_cv = zeros(jmax);
%%%[loc_sv, loc_s, loc_dz, loc_dza] = get_grid_genie_full(imax,jmax,kmax);
[loc_sv, loc_s, loc_dz, loc_dza] = make_genie_grid(imax,jmax,kmax,zt_max,0.0,plot_equallat,0.0);
for j = 1:jmax,
loc_cv(j) = sqrt(1 - loc_sv(j)*loc_sv(j));
end
% (2) load velocity data