-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplot_fields_biogem_2d.m
More file actions
2235 lines (2216 loc) · 91.6 KB
/
plot_fields_biogem_2d.m
File metadata and controls
2235 lines (2216 loc) · 91.6 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_2d(PEXP1,PEXP2,PVAR1,PVAR2,PT1,PT2,PIK,PMASK,PCSCALE,PCMIN,PCMAX,PCN,PDATA,POPT,PNAME)
% plot_fields_biogem_2d
%
% ******************************************************************* %
% *** biogem 2-D (LON-LAT) DATA PLOTTING **************************** %
% ******************************************************************* %
%
% plot_fields_biogem_2d(PEXP1,PEXP2,PVAR1,PVAR2,PT1,PT2,PIK,PMASK,PCSCALE,PCMIN,PCMAX,PCN,PDATA,POPT,PNAME)
% plots the BIOGEM 2-D netCDF data file 'fields_biogem_2d.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] [OPTIONAL] (e.g. 15)
% --> the MAXIMUM (k) level in the ocean model to be plotted
% (defining whether and how many, shallow levels are excluded)
% --> passing a PIK value equal to the number of ocean levels will result in the full grid being plotted
% PMASK [STRING] (e.g. 'mask_worjh2_Indian.dat')
% --> NOT USED IN 2D POTTING
% 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:
% lon, lat, value, label
% or, of the option (below) data_ij = 'y', then as:
% i, j, value, label
% --> 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_2d('experiment_1','','ocn_sur_PO4','',1994.5,-1,14,'',1e-6,0.0,2.0,20,'','','')
% will plot the time-slice cenetered on a time of 1994.5,
% of bottom-water [PO4] in units of umol kg-1,
% between 0 and 2 umol kg-1 with 20 contour intervals
% and omitting levels greater than 14 (i.e., 15 and 16 for a
% 16-level ocean model configuration)
%
% ******************************************************************* %
% *********************************************************************** %
% ***** HISTORY ********************************************************* %
% *********************************************************************** %
%
% 10/07/05: added taylor diagram plotting
% 10/07/06: adjustments to use calc_find_ij_v100706 (in place of find_ij)
% sorted out confusion between (lon,lat) of the data and (j,i) of the model grid ...
% added stats save
% 10/07/16: added option for inputting (i,j) data
% 11/05/15: bug-fixed experiment differencing
% added date stamp
% 11/05/31: cosmetic changes
% 11/07/31: added additional contour option
% changed (default) colorbar plotting
% changed log10 plotting behavior
% changed differencing calculation for log10(data)
% 12/01/21: altered 'help' text
% changed subroutine name: calc_find_ij_v100706 -> calc_find_ij
% added algorithm to average data per cell (if requested)
% 12/01/23: minor bug-fix to internal gridding
% 12/01/24: reorganized sequence of lon axis vs overlay data processing
% rationalized 'user settings'
% 12/02/09: added in options for: anomoly plotting; data-only
% 12/08/05: added path-free direct netCDF file location/opening option
% (by leaving the experiment name field blank)
% 12/09/06: added saving (ASCII) of re-gridded data
% 12/10/16: updated HELP text
% 12/10/18: reordered parameter list
% 12/11/13: added data Site labelling
% 12/11/13: removed scale bar when data Site labelling selected
% 12/11/14: added windstress overlay
% 12/12/10: added additional option for labelling sites
% 12/12/14: revised filename string
% 12/12/27: bug-fix in non re-gridded obs data (wrong vector length)
% 13/06/24: added netCDF file #2 close
% 13/07/18: adjusted confusing help on PIK
% added optional 2D ASCII data replacement
% 13/08/09: rationalized filename
% 13/08/12: updated stats calculation and output
% changed data format
% 13/10/06: created alt anomoly colormap and adjusted anomoly plotting
% added invert color bar option
% 13/10/17: corrected missing parameter + missing variable assignment ...
% changed site labelling
% added more stats output
% 13/11/12: REORGANIZED USER SETTINGS [AND PASSED PARAMETER LIST]
% 13/12/15: bug-fixes and potted changes to start to bring consistent
% with the other function revisions
% 13/12/18: MUTLAB bug-fix(?) for nmax<10 not displaying scatter colors
% 13/12/19: disabled target diagram for now to simplify things
% 13/12/23: added file format selection for 'new' plotting
% 14/04/07: added zonal mean calculation + plotting
% added option for not plotting the main figure
% added zonal mean data return in function call
% 14/04/14: rather trivial data point line width adjustment ...
% 14/04/15: added alt filename
% 14/04/17: fixed data point n adjustment
% altered (fixed?) criteria for not ploting the color scale
% 14/04/19: removed old colorbar option
% 14/06/18: corrected help example
% 14/08/20: added '%'s to ASCII data output headers
% 14/09/11: added option for uniform lat grid
% 14/09/17: renamed plot_lon_min -> plot_lon_origin
% added options for plotting sub-regions
% 14/09/29: added selection between the 2 lat grid styles for zonal plot
% 14/09/30: minor bug-fix of data location reported lat values
% 14/11/09: auto plot format
% 14/12/03: incorporated new make_cmap5 function
% 14/12/07: fixed dim error in flipping color scale
% 14/12/30: added cross-plotting
% fixed missing nmax value for dual 3D data input
% 15/01/07: bug-fixed grid shifting of depth arrays
% 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,
% (whilst noting that there is no capability yet to read in the
% required additional data columns)
% 15/01/13: bug-fix of recent changes
% added data point shape/color import
% 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/10/14: adjusted contor line widths
% adjusted data text label positioning
% added option for 2nd highlight contour
% 16/03/01: added documentation marker ('%%') (who knew!)
% 16/03/02: revised stats output
% 16/11/15: fixed (missing n loop) bug in data overlay plotting
% 17/01/13: minor edits to allow for 2 (2D) fields plus data locations
% 17/03/28: added overlay for barotropic streamfunction
% 17/03/31: clarified the lack of wind speed (instead: stress) overlay
% 17/04/19: add backwards compatability (for psi parameter)
% 17/08/04: added, not very successfully, PSI only plot ...
% *** 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: improved PSI plotting
% 17/11/02: adjusted paths ... again again ...
% *** VERSION 1.03 ********************************************
% 17/12/29: fixed some minor bugs with overlay (lon,lat) data processing
% *** VERSION 1.04 ********************************************
% 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 test for kplot value < 1
% 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)
% *** VERSION 1.13 ********************************************
% 18/10/25: [minor reformatting]
% 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
% plus minor site location plotting plotting adjustments
% *** 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/18: bug fix for non equal area grids
% *** VERSION 1.21 ********************************************
% 19/03/25: made stats plot optional (selected as secondary plot)
% *** VERSION 1.22 ********************************************
% 19/03/31: removed generation of empty STATM array
% *** VERSION 1.24 ********************************************
% 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: [minor]
% *** VERSION 1.37 ********************************************
% 19/10/03: revised data format checking
% *** VERSION 1.38 ********************************************
% 20/01/07: minor adjustment to data point plotting
% *** VERSION 1.41 ********************************************
% 20/03/20: added data scaling parameter backwards-compatability
% *** VERSION 1.42 ********************************************
% 20/03/24: fixed error in 8-column data format
% *** VERSION 1.43 ********************************************
% 20/07/25: added stats output to align with other plotting functions
% *** VERSION 1.44 ********************************************
% 20/08/19: enabled parameter: contour_dashneg
% *** VERSION 1.45 ********************************************
% 20/08/26: (various) + align version numbers!
% *** VERSION 1.46 ********************************************
% 20/09/04: changed 3-column format from:
% lon, lat, label -> lon, lat, data
% aligned data stats calculation with sedgem_2d
% tested for zero SD in data
% *** VERSION 1.47 ********************************************
% 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)
% *** VERSION 1.53 ********************************************
% 21/02/25: switched model1 vs. model2 order in cross-plot
% 21/04/02: added basic stats to the function return
% *** VERSION 1.54 ********************************************
% 21/04/20: adjusted function return stats
% *** VERSION 1.55 ********************************************
% 21/04/27: revised data read-in allowable formats
% *** VERSION 1.56 ********************************************
% 21/07/05: added (back?) default vector_1
% *** VERSION 1.57 ********************************************
% 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 ********************************************
% 25/08/25: removed plot_format_old plot option
% *** VERSION 1.67 ********************************************
% 25/10/31: upgraded gridding function
% added nearest neighbor (ocean cell) option
% *** VERSION 1.68 ********************************************
%
% *********************************************************************** %
%%
% *********************************************************************** %
% *** INITIALIZE PARAMETERS & VARIABLES ********************************* %
% *********************************************************************** %
%
% *** initialize ******************************************************** %
%
% set version!
par_ver = 1.68;
% 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
if ~exist('data_ijk_near','var'), data_ijk_near = '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_histc_SETTINGS','var'), plot_histc_SETTINGS = 'plot_histc_SETTINGS'; end % histc plotting settings
%
% *** initialize parameters ********************************************* %
%
% set axes
lat_min = -090;
lat_max = +090;
lon_min = plot_lon_origin;
lon_max = lon_min+360;
lon_offset = 0;
% null data value
par_data_null = 9.9E19;
%
% *** copy passed parameters ******************************************** %
%
% set passed parameters
exp_1 = PEXP1;
exp_2 = PEXP2;
timesliceid_1 = PT1;
timesliceid_2 = PT2;
dataid_1 = PVAR1;
dataid_2 = PVAR2;
kplotmax = 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_lon_min == plot_lon_max)),
plot_global = true;
plot_xy_scaling = 1.0;
else
plot_global = false;
if (plot_lat_min == plot_lat_max),
plot_lat_min = lat_min;
plot_lat_max = lat_max;
end
if (plot_lon_min == plot_lon_max),
plot_lon_min = lon_min;
plot_lon_max = lon_max;
end
plot_xy_scaling = ((plot_lat_max - plot_lat_min)/(lat_max - lat_min)) / ((plot_lon_max - plot_lon_min)/(lon_max - lon_min));
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_1=[];
data_2=[];
%
% *********************************************************************** %
% *********************************************************************** %
% *** OPEN netCDF DATA 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_2d.nc'],'nowrite');
end
% read netCDf information
[ndims,nvars,ngatts,unlimdimid] = netcdf.inq(ncid_1);
%
% *********************************************************************** %
% *********************************************************************** %
% *** 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';
% load and calculate remaining grid information
% calculate grid dimensions
varid = netcdf.inqDimID(ncid_1,'lat');
[dimname, dimlen] = netcdf.inqDim(ncid_1,varid);
jmax = dimlen;
varid = netcdf.inqDimID(ncid_1,'lon');
[dimname, dimlen] = netcdf.inqDim(ncid_1,varid);
imax = dimlen;
% load 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) + lon_offset;
[lonm latm] = meshgrid(grid_lon,grid_lat);
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) + lon_offset;
[lonw lats] = meshgrid(grid_lon_edges(1:imax),grid_lat_edges(1:jmax));
[lone latn] = meshgrid(grid_lon_edges(2:imax+1),grid_lat_edges(2:jmax+1));
% PSI
if (plot_psi == 'y'),
varid = netcdf.inqVarID(ncid_1,'lat_psi');
grid_lat_psi = netcdf.getVar(ncid_1,varid);
varid = netcdf.inqVarID(ncid_1,'lon_psi');
grid_lon_psi = netcdf.getVar(ncid_1,varid);
[lonpsi latpsi] = meshgrid(grid_lon_psi(1:imax),grid_lat_psi(1:jmax+1));
else
lonpsi = [];
latpsi = [];
end
% Non-uniform lat grid
if (plot_equallat == 'n'),
lat_max = sin(pi*lat_max/180.0);
lat_min = sin(pi*lat_min/180.0);
latn = sin(pi*latn/180.0);
lats = sin(pi*lats/180.0);
plot_lat_max = sin(pi*plot_lat_max/180.0);
plot_lat_min = sin(pi*plot_lat_min/180.0);
end
%initialize dummy topography
topo = zeros(jmax,imax);
layb = zeros(jmax,imax);
%i=1 longitude grid origin
grid_lon_origin = grid_lon_edges(1);
% filter maximum k-level variable fo missing value or < 1
if isempty(kplotmax)
kplotmax = 99;
elseif (kplotmax < 1)
kplotmax = 99;
end
%
% *********************************************************************** %
% *********************************************************************** %
% *** SET PRIMARY GRIDDED DATASET *************************************** %
% *********************************************************************** %
%
% *** SET TIME-SLICE **************************************************** %
%
% check that the year exists
varid = netcdf.inqVarID(ncid_1,'time');
timeslices = netcdf.getVar(ncid_1,varid);
[dimname, dimlen] = netcdf.inqDim(ncid_1,varid);
clear time;
while exist('time','var') == 0
for n = 1:dimlen,
if double(int32(100*timeslices(n)))/100 == timesliceid_1
time = timesliceid_1;
tid = 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
%
% *** SET DATA FIELD **************************************************** %
%
% check that the variable name exists
varid = [];
while isempty(varid)
for n = 0:nvars-1,
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_1,n);
if strcmp(varname,dataid_1)
varid = n;
end
end
if isempty(varid)
disp(' > WARNING: Variable 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 ********************************************************* %
%
% NOTE: flip array around diagonal to give (j,i) array orientation
data_1(:,:) = zeros(jmax,imax);
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_1,varid);
netcdfdata = netcdf.getVar(ncid_1,varid);
if length(dimids) == 3
rawdata(1:imax,1:jmax) = netcdfdata(1:imax,1:jmax,tid);
switch data_minmax,
case {'min'}
for j = 1:jmax,
for i = 1:imax,
rawdata(i,j) = min(netcdfdata(i,j,tid:tid+data_nseas-1));
end
end
case {'max','minmax'}
for j = 1:jmax,
for i = 1:imax,
rawdata(i,j) = max(netcdfdata(i,j,tid:tid+data_nseas-1));
end
end
end
data_1(1:jmax,1:imax) = rawdata(1:imax,1:jmax)';
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*data_1;
end
if ~isempty(plot_dataid_alt1)
data_1 = load([plot_dataid_alt1],'-ascii');
data_1 = flipud(data_1);
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_2d.nc'],'nowrite');
end
% read netCDf information
[ndims,nvars,ngatts,unlimdimid] = netcdf.inq(ncid_2);
else
ncid_2 = ncid_1;
end
%
% *** SET 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 = 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
end
%
% *** SET ALT DATA FIELD ************************************************ %
%
if ~isempty(dataid_2)
% check that the variable name exists
varid = [];
while isempty(varid)
for n = 0:nvars-1,
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_2,n);
if strcmp(varname,dataid_2)
varid = n;
end
end
if isempty(varid)
disp(' > WARNING: Variable name must be one of the following;');
for n = 0:nvars-1,
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_2,n);
varname
end
dataid = input(' > Variable name: ','s');
end
end
else
for n = 0:nvars-1,
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_1,n);
if strcmp(varname,dataid_1)
varid = n;
end
end
end
%
% *** LOAD ALT DATA ***************************************************** %
%
data_2(:,:) = zeros(jmax,imax);
if (~isempty(exp_2) || (timesliceid_2 >= 0.0) || ~isempty(dataid_2)),
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_2,varid);
netcdfdata = netcdf.getVar(ncid_2,varid);
if length(dimids) == 3
rawdata(1:imax,1:jmax) = netcdfdata(1:imax,1:jmax,tid);
switch data_minmax,
case {'min','minmax'}
for j = 1:jmax,
for i = 1:imax,
rawdata(i,j) = min(netcdfdata(i,j,tid:tid+data_nseas-1));
end
end
case 'max'
for j = 1:jmax,
for i = 1:imax,
rawdata(i,j) = max(netcdfdata(i,j,tid:tid+data_nseas-1));
end
end
end
data_2(1:jmax,1:imax) = rawdata(1:imax,1:jmax)';
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*data_2;
end
data_anomoly = 'y';
end
if ~isempty(plot_dataid_alt2)
data_2 = load([plot_dataid_alt2],'-ascii');
data_2 = flipud(data_2);
end
%
% *********************************************************************** %
% *********************************************************************** %
% *** OPTIONAL (u,v) VELOCITY DATA OVERLAY ****************************** %
% *********************************************************************** %
%
if (data_uv == 'y'),
varid = netcdf.inqVarID(ncid_1,'phys_tau_u');
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_1,varid);
rawdata = netcdf.getVar(ncid_1,varid);
if length(dimids) == 3
rawdata(1:imax,1:jmax) = rawdata(1:imax,1:jmax,tid);
data_u(1:jmax,1:imax) = rawdata(1:imax,1:jmax)';
elseif length(dimids) == 2
rawdata(1:imax,1:jmax) = rawdata(1:imax,1:jmax);
data_u(1:jmax,1:imax) = rawdata(1:imax,1:jmax)';
data_u(:,:) = NaN;
end
varid = netcdf.inqVarID(ncid_1,'phys_tau_v');
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_1,varid);
rawdata = netcdf.getVar(ncid_1,varid);
if length(dimids) == 3
rawdata(1:imax,1:jmax) = rawdata(1:imax,1:jmax,tid);
data_v(1:jmax,1:imax) = rawdata(1:imax,1:jmax)';
elseif length(dimids) == 2
rawdata(1:imax,1:jmax) = rawdata(1:imax,1:jmax);
data_v(1:jmax,1:imax) = rawdata(1:imax,1:jmax)';
else
data_v(:,:) = NaN;
end
else
data_u(:,:,:) = zeros(size(data_1));
data_v(:,:,:) = zeros(size(data_1));
end
%
% *********************************************************************** %
% *********************************************************************** %
% *** OPTIONAL psi DATA OVERLAY ***************************************** %
% *********************************************************************** %
%
if exist('plot_psi','var')
if (plot_psi == 'y'),
varid = netcdf.inqVarID(ncid_1,'phys_psi');
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid_1,varid);
rawdata = netcdf.getVar(ncid_1,varid);
if length(dimids) == 3
rawdata(1:imax,1:jmax+1) = rawdata(1:imax,1:jmax+1,tid);
data_psi(1:jmax+1,1:imax) = rawdata(1:imax,1:jmax+1)';
elseif length(dimids) == 2
rawdata(1:imax,1:jmax+1) = rawdata(1:imax,1:jmax+1);
data_psi(1:jmax+1,1:imax) = rawdata(1:imax,1:jmax+1)';
data_psi(:,:) = NaN;
end
end
end
%
% *********************************************************************** %
% *********************************************************************** %
% *** SET OUTPUT FILESTRING ********************************************* %
% *********************************************************************** %
%
% create an output filestring for data and plot saving
%
if (~isempty(exp_2)) || (timesliceid_2 >= 0.0) || (~isempty(dataid_2))
filename = [exp_1, '.', 'y', num2str(timesliceid_1), '.', dataid_1, '_MINUS_', exp_2, '.', 'y', num2str(timesliceid_2), '.', dataid_2];
else
filename = [exp_1, '.', 'y', num2str(timesliceid_1), '.', dataid_1];
end
% NOTE: mask single location coordinate is (i,j)
% but written to the array as (j,i)
if ~isempty(maskid)
if isnumeric(maskid)
maskid = ['i', num2str(maskid(1)), 'j', num2str(maskid(2))];
elseif ischar(maskid)
% (OK)
else
disp([' ']);
error('*WARNING*: Unknown mask parameter type (must be character array or vector location) ... ')
end
filename = [filename, '.', maskid];
end
if ~isempty(overlaydataid),
filename = [filename, '_VS_', overlaydataid];
if (data_anomoly == 'y'),
filename = [filename, '.ANOM'];
end
if (data_only == 'y'),
filename = [filename, '.DO'];
end
end
if (~isempty(altfilename)), filename = altfilename; end
%
% *********************************************************************** %
% *********************************************************************** %
% *** FILTER & PROCESS RAW DATA ***************************************** %
% *********************************************************************** %
%
% set ocean grid value to give white when plotted
if strcmp(dataid_1,'grid_mask')
data_1 = NaN;
end
if strcmp(dataid_2,'grid_mask')
data_2 = NaN;
end
%
xm = lonm;
ym = latm;
z_u(:,:) = data_u(:,:);
z_v(:,:) = data_v(:,:);
if exist('plot_psi','var')
if (plot_psi == 'y'),
z_psi(:,:) = data_psi(:,:);
end
end
%
% *** PROCESS MAIN DATASET ********************************************** %
%
for i = 1:imax,
for j = 1:jmax,
if grid_k1(j,i) > 90
if plot_landvalues == 'n'
data_1(j,i) = NaN;
data_2(j,i) = NaN;
z_u(j,i) = NaN;
z_v(j,i) = NaN;
xm(j,i) = NaN;
ym(j,i) = NaN;
elseif ((data_1(j,i) < -1.0E6) || (data_1(j,i) > 1.0E30) || isnan(data_1(j,i)) || (data_2(j,i) < -1.0E6) || (data_2(j,i) > 1.0E30)) || isnan(data_2(j,i))
data_1(j,i) = NaN;
data_2(j,i) = NaN;
end
topo(j,i) = +1.0;
layb(j,i) = -1.0;
elseif grid_k1(j,i) > kplotmax
data_1(j,i) = NaN;
data_2(j,i) = NaN;
z_u(j,i) = NaN;
z_v(j,i) = NaN;
topo(j,i) = +1.0;
layb(j,i) = -1.0;
elseif ((data_1(j,i) < -1.0E6) || (data_1(j,i) > 1.0E30) || isnan(data_1(j,i)) || (data_2(j,i) < -1.0E6) || (data_2(j,i) > 1.0E30)) || isnan(data_2(j,i))
data_1(j,i) = NaN;
data_2(j,i) = NaN;
z_u(j,i) = NaN;
z_v(j,i) = NaN;
topo(j,i) = +1.0;
layb(j,i) = -1.0;
else
% NOTE: check for exp2 existing
% (so <data_2> does not become NaN, contaminate <data>)
if (data_log10 == 'y')
if (data_1(j,i) > 0.0)
data_1(j,i) = log10(data_1(j,i))/data_scale;
else
data_1(j,i) = NaN;
end
if (data_2(j,i) > 0.0)
data_2(j,i) = log10(data_2(j,i))/data_scale;
else
if (~isempty(exp_2)), data_2(j,i) = NaN; end
end
else
data_1(j,i) = data_1(j,i)/data_scale;
data_2(j,i) = data_2(j,i)/data_scale;
end
topo(j,i) = -1.0;
layb(j,i) = +1.0;
if (contour_noneg == 'y')
if ((data_1(j,i) - data_2(j,i) - data_offset) < 0.0)
data_1(j,i) = 0.0;
data_2(j,i) = 0.0;
end
end
if (data_uv == 'y'), speed(j,i) = data_scale*(z_u(j,i)^2.0 + z_v(j,i)^2.0)^0.5; end
if ((data_only == 'y') && (plot_psi == 'y')), data_1(j,i) = NaN; end
end
end
end
data = data_1 - data_2;
data = data - data_offset;
zm = data;
% copy zm before it gets transformed ...
overlaydata_zm(:,:) = zm(:,:);
%
% *** CREATE ZONAL AVERAGE ********************************************** %
%
% define initial array sizes
zz = zeros(jmax,1);
zz_A = zz;
%
% NOTE: unit area grid => no need for explicit scaling factor
for j = 1:jmax,
n = 0;
for i = 1:imax,
if ~isnan(data(j,i)),
zz(j) = zz(j) + 1.0*data(j,i);
zz_A(j) = zz_A(j) + 1.0;
n = n + 1;
end
end
if (zz_A(j) > 0.0),
zz(j) = zz(j)/zz_A(j);
else
zz_A(j) = NaN;
end
end
%
% *********************************************************************** %