%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% DCM Profile Figures %%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Create Sept. 26,2022
% Creates all non-triazus figures for DCM Paper

%% Load

% Add utility paths% add orther relevant paths
addpath(genpath('/Users/roh029/Desktop/Matlab/SOLACE'))
addpath(genpath('/Users/roh029/Desktop/Matlab/Utilities'))

% Determine indexes of CTD at each site:
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/CTD
load('CTD_MLD.mat')

cd /Users/roh029/Desktop/Data.nosync/SOLACE/CHL
load CHL cf_ctd CHL_ctd 


%% %%%%%%%%%% Discrete Sampled Data
%% CTD Nutrients
for Nuts =1
% Depth, NO3, PO4, Si, NO4, No2
for cast47=1
CTD47 = [5.6	NaN	NaN	NaN	NaN	NaN;
5.8	24.80382201	1.651586296	3.741530982	0.189194591	0.222765411;
9.7	24.8031893	1.636687153	3.65828193	0.178805646	0.22401069;
10.5	NaN	NaN	NaN	NaN	NaN;
20.4	NaN	NaN	NaN	NaN	NaN;
24.3	24.85720184	1.6488566	3.67016288	0.185492355	0.224853001;
25.4	NaN	NaN	NaN	NaN	NaN;
29.8	NaN	NaN	NaN	NaN	NaN;
40	NaN	NaN	NaN	NaN	NaN;
49.9	NaN	NaN	NaN	NaN	NaN;
50.1	24.86847032	1.643722406	3.692749103	0.201063975	0.223792497;
60.4	24.93743322	1.709443067	3.804735607	0.268912265	0.2223907;
70.1	25.37706198	1.737714959	5.235900224	0.392011355	0.2157018;
70.1	NaN	NaN	NaN	NaN	NaN;
80.5	26.02777687	2.254459545	8.153020239	0.752908779	0.209566667;
90.2	NaN	NaN	NaN	NaN	NaN;
90.2	26.77130852	1.904519477	11.66221042	0.563443653	0.194941233;
100.5	27.18851907	1.930331346	13.16978539	0.478422297	0.19402908;
109.8	27.32880699	1.930067308	13.36729557	0.476070774	0.188968389;
120.2	NaN	NaN	NaN	NaN	NaN;
124.7	27.90856231	1.942783179	14.74076973	0.27591739	0.182750262;
149.1	28.28805104	1.962952868	15.90563797	0.242553835	0.172270202;
149.2	NaN	NaN	NaN	NaN	NaN;
175.4	29.91816334	2.046304281	22.01790927	-0.000403114	0.047395961;
199.5	NaN	NaN	NaN	NaN	NaN;
199.6	30.91129043	2.110820189	26.58956656	-0.004938741	0.012018015;
225.2	31.66696472	2.166714636	30.46051389	-0.005867529	0.008434568;
251.1	32.32859573	2.211961863	33.8197125	-0.006972623	0.009400612;
300.7	33.35882248	2.285515247	39.98452394	-0.006725249	0.008655039;
350.2	34.22814891	2.346504342	46.09030638	-0.007186424	0.009984656;
400.4	34.79516967	2.379009581	50.69318083	-0.008695232	0.013078849;
500.4	35.41560725	2.424877951	59.0931471	-0.005931266	0.013053142;
600.5	35.5389855	2.434849389	66.10312636	-0.005960771	0.015333933;
750.3	34.95021961	2.404235315	72.47277148	-0.004156292	0.013683676;
800.6	34.66581809	2.380955362	73.62734351	-0.008214863	0.011294595;
999.8	33.58888025	2.307282056	77.33845236	-0.00614555	0.009565315];
end

for cast53=1
    CTD53 = [8.5	24.54027808	1.599093988	3.279247752	0.163751107	0.229809472;
8.7	NaN	NaN	NaN	NaN	NaN;
8.9	NaN	NaN	NaN	NaN	NaN;
40.3	24.56250923	1.612172626	3.329670429	0.17512745	0.224272484
40.4	NaN	NaN	NaN	NaN	NaN;
40.5	NaN	NaN	NaN	NaN	NaN;
70.4	NaN	NaN	NaN	NaN	NaN;
70.5	25.07435831	1.658209761	3.91693683	0.256385388	0.220624284;
70.5	NaN	NaN	NaN	NaN	NaN;
80.6	NaN	NaN	NaN	NaN	NaN;
80.7	25.40948946	1.713554182	5.23032533	0.366207015	0.217372865;
80.8	NaN	NaN	NaN	NaN	NaN;
110.7	NaN	NaN	NaN	NaN	NaN;
110.9	27.06607247	1.902891928	13.01875857	0.501211256	0.215951492;
110.9	NaN	NaN	NaN	NaN	NaN;
150.3	NaN	NaN	NaN	NaN	NaN;
150.4	NaN	NaN	NaN	NaN	NaN;
150.6	28.29405282	1.945349763	15.36076312	0.037395693	0.19671529;
250	31.83843499	2.164418538	31.77039533	-0.000500255	0.017498351;
250.3	NaN	NaN	NaN	NaN	NaN;
250.3	NaN	NaN	NaN	NaN	NaN;
500.4	35.26858504	2.410073579	59.36284085	-0.002905902	0.011159359;
500.7	NaN	NaN	NaN	NaN	NaN;
500.9	NaN	NaN	NaN	NaN	NaN;
750.4	34.78251218	2.385605971	72.03371529	0.003427876	0.009717474;
750.9	NaN	NaN	NaN	NaN	NaN;
751	NaN	NaN	NaN	NaN	NaN;
1000.6	NaN	NaN	NaN	NaN	NaN;
1000.7	NaN	NaN	NaN	NaN	NaN;
1000.9	33.39003945	2.289577823	77.10486172	-0.002030336	0.008750893;
1500.4	NaN	NaN	NaN	NaN	NaN;
1500.5	NaN	NaN	NaN	NaN	NaN;
1500.6	31.27678009	2.148753213	84.57638531	-0.001377975	0.00782617;
2001	NaN	NaN	NaN	NaN	NaN;
2001.1	31.35099609	2.157227367	97.16339103	-0.002933344	0.006646639;
2001.1	NaN	NaN	NaN	NaN	NaN];
       
end

for cast60=1
    CTD60 = [4.9	24.61195939	1.617261749	3.199200325	0.150158296	0.227877251;
5.3	NaN	NaN	NaN	NaN	NaN;
10.6	24.67237889	1.61454716	3.041366349	0.158404488	0.225184021;
19.2	NaN	NaN	NaN	NaN	NaN;
24.6	24.67004325	1.605061631	3.077488482	0.155576842	0.224379784;
29.9	NaN	NaN	NaN	NaN	NaN;
40	24.7253985	1.617028414	3.178874032	0.168198825	0.224022063;
50.1	24.70976444	1.62762719	3.2235099	0.178778126	0.221170126;
50.4	NaN	NaN	NaN	NaN	NaN;
59.9	24.85584875	1.641082657	3.41228824	0.198826741	0.218551996;
70.4	25.37546907	1.735641136	5.204104588	0.34742745	0.212636984;
75.3	25.81452824	1.798012215	6.968920517	0.472359367	0.208697499;
85.3	NaN	NaN	NaN	NaN	NaN;
85.8	26.1817026	1.849859654	9.201230078	0.638069434	0.211375423;
90.6	NaN	NaN	NaN	NaN	NaN;
99.4	26.47231261	1.87758453	10.67938491	0.726035651	0.206016672;
99.5	NaN	NaN	NaN	NaN	NaN;
110.2	NaN	NaN	NaN	NaN	NaN;
125.4	27.22010345	1.909454752	13.46724673	0.563312607	0.190391604;
125.5	NaN	NaN	NaN	NaN	NaN;
135.6	27.37896621	1.928603834	13.92384065	0.506575997	0.187652576;
150.3	NaN	NaN	NaN	NaN	NaN;
150.3	27.91992379	1.94341225	15.15656822	0.3135335	0.175462176;
175.3	29.45562846	2.013932565	20.52465879	-0.001361333	0.028629072;
200.8	30.31996981	2.069161019	24.49187962	-0.000240564	0.023852125;
225.8	31.27057399	2.126806851	28.96878981	-0.002497129	0.020456466;
250.6	31.98258829	2.175877822	32.61866974	-0.001437867	0.01675178;
300.3	33.10535319	2.254002121	38.97633712	-0.00486875	0.015104907;
350.8	33.98447273	2.314965503	45.21278414	-0.004811671	0.013369523;
400.7	34.69970777	2.365497156	50.64251713	-0.006556566	0.012762456;
500.5	35.45499898	2.423511545	60.1261418	-0.006229623	0.010875078;
500.6	NaN	NaN	NaN	NaN	NaN;
600.1	35.25465308	2.420911391	66.76239424	-0.006267914	0.010853982;
750.5	34.96472349	2.399907611	72.81079253	-0.004909354	0.010367613;
800.5	34.72808236	2.382401369	74.22900771	-0.003969305	0.011017444;
1000	33.41104422	2.291841945	77.15239495	-0.006745161	0.009152248];
end

for cast67=1
    CTD67= [4.6	24.63996004	1.622488761	1.492225518	0.116258238	0.241579272;
6	NaN	NaN	NaN	NaN	NaN;
10.6	24.565799	1.637815134	1.480117651	0.12088142	0.238807024;
20.8	NaN	NaN	NaN	NaN	NaN;
25.6	24.55897407	1.704065697	1.517450812	0.147673138	0.240347285;
26.1	NaN	NaN	NaN	NaN	NaN;
31	24.57026647	1.648457425	1.515561082	0.125621237	0.238855119;
39.7	NaN	NaN	NaN	NaN	NaN;
40.3	24.51872824	1.653799068	1.493545682	0.122548429	0.238863313;
50.5	24.50546265	1.653925202	1.396574272	0.134528391	0.235871122;
60.3	24.57863243	1.675407259	1.595931847	0.166569021	0.23956341;
70.2	24.97882627	1.738530812	2.840494442	0.429154095	0.238688212;
80.6	25.70344415	1.837936937	6.799841896	0.888221445	0.230719213;
80.7	NaN	NaN	NaN	NaN	NaN;
85.6	25.81936422	1.848768893	7.30601141	0.878581565	0.228375684;
90.6	25.86329868	1.865143396	7.446068367	0.880239072	0.225447224;
100.2	NaN	NaN	NaN	NaN	NaN;
100.6	26.08134108	1.873243575	8.380500406	0.892944103	0.222274185;
110.4	26.52407413	1.910492376	9.94139124	0.828364169	0.222635003;
125.2	27.039748	1.939252965	11.70341744	0.698426712	0.225721351;
135.3	27.16689756	1.945151086	12.26493359	0.627177836	0.227399823;
150.5	27.5412136	1.93446514	13.20816836	0.453887818	0.23977091;
150.6	NaN	NaN	NaN	NaN	NaN;
175	28.20664844	1.953596282	15.20115786	0.200825765	0.187557449;
200.6	NaN	NaN	NaN	NaN	NaN;
200.6	29.09866148	2.000819484	18.38724379	0.010869474	0.090855341;
225.9	30.21827829	2.073091392	23.32294859	-0.005847961	0.025150505;
250.5	30.63948253	2.127090782	25.52860216	0.000757207	0.02575937;
300.3	32.81378098	2.23953618	36.89486413	-0.008049636	0.016110379;
350.1	34.07980126	2.325144066	45.19507889	-0.006593296	0.013851014;
400.9	34.66804744	2.370029312	50.10811835	-0.009431596	0.011835213;
500.7	35.50815841	2.426621198	59.92203878	-0.009768741	0.013181676;
600.3	35.60748248	2.442488712	67.4763085	-0.008680056	0.009944835;
751.1	35.08310401	2.414354388	72.88624718	-0.009858448	0.010399682;
800.6	34.77366231	2.389465663	74.30309441	-0.009440433	0.010458441;
1000.8	33.55596748	2.308607081	77.77377605	-0.007185042	0.008327531];
end

for cast76=1
    CTD76 = [10.9	NaN	NaN	NaN	NaN	NaN;
11	NaN	NaN	NaN	NaN	NaN;
11.1	NaN	NaN	NaN	NaN	NaN;
11.2	24.99449295	1.601666195	0.750054844	0.130322488	0.238754537;
20.3	25.00664916	1.600768038	0.736797205	0.116935971	0.239882451;
25.3	NaN	NaN	NaN	NaN	NaN;
25.7	24.99005511	1.601106681	0.791272088	0.116347725	0.237489198;
32.8	NaN	NaN	NaN	NaN	NaN;
39.5	24.98900992	1.608754697	0.767795024	0.136922178	0.238757824;
49.8	25.00115686	1.604792027	0.75283355	0.122684685	0.237732954;
49.8	NaN	NaN	NaN	NaN	NaN;
60.6	24.95842068	1.615743082	0.782821078	0.177458793	0.237378604;
70.9	NaN	NaN	NaN	NaN	NaN;
75.6	25.24641672	1.666436276	1.823664836	0.380561108	0.236901904;
80.8	25.73024141	1.782535028	4.148884556	0.837686621	0.232600026;
81	NaN	NaN	NaN	NaN	NaN;
90.6	NaN	NaN	NaN	NaN	NaN;
101.3	NaN	NaN	NaN	NaN	NaN;
101.8	26.15651368	1.842999571	7.076190102	0.949603564	0.228696438;
120.6	NaN	NaN	NaN	NaN	NaN;
126.3	27.34497236	1.953564758	11.69306177	0.844612989	0.217587888;
149.8	27.78476302	1.950761392	14.39262414	0.673503104	0.209270395;
150.3	NaN	NaN	NaN	NaN	NaN;
174.8	28.40712089	1.960478516	15.43925756	0.436354395	0.216345759;
200	29.40257151	2.009404749	18.41691125	0.135441259	0.140493307;
200.6	NaN	NaN	NaN	NaN	NaN;
224.5	30.25163356	2.059730864	21.15746471	-0.000968029	0.030166491;
250.4	31.81937867	2.15934288	28.2057099	-0.002723819	0.010470761;
301.6	33.58876043	2.274376089	37.87338118	-0.003889577	0.006835396;
347.4	34.51558812	2.33484353	44.01669885	-0.004263562	0.005779885;
399.9	35.37844148	2.39564942	50.67825641	-0.005306892	0.005178501;
499.4	36.20262438	2.455737234	60.73827281	-0.004990218	0.003150975;
601	36.36564111	2.470306747	67.25605953	-0.004496936	0.002700032;
750.5	35.67682803	2.427996328	73.27900161	-0.00439485	0.002149;
800.8	35.33764266	2.412932339	74.24026241	-0.004140124	0.001106075;
1001.3	34.16809884	2.331017388	78.3270462	-0.00294133	0.001427635];
end
end

%% Dfe, PFe, PPhos Data
for DfeData =1

% Site 1 (56)
dFeDepths1= [15, 30, 50 70 90 110 130 160 200 250 300 500];
dFe1 = [0.16 0.16 0.17 nan 0.16 0.17 0.25 0.17 0.57 0.33 0.31 0.38];  % nmol/kg
dFeDepths2= [15 30  50 70 90 110 130 160 200 250 300 500];
dFe2 = [nan 0.16 0.10 0.16 0.11 0.13 0.16 0.07 0.19 0.18 0.17 0.32]; % nmol/kg
dFeDepths3 = [20 40 80 100 150 200 300 500 750 1000 1500];
dFe3 = [0.21 0.18 0.20 nan 0.43 0.11 0.35 0.34 0.74 0.73 0.64]; % nmol/kg
% Site 2 (58)
dFeDepths4= [20 40 80 100 150 200 300 750 1500];
dFe4 = [0.42 0.51 0.09 0.48 0.40 0.16 0.34 0.59 0.60];% nmol/kg
dFeDepths5= [20 40 60 80 100 125 150 200 250 300 400 500]; 
dFe5 = [0.19 0.15 0.23 0.19 0.15 0.20 0.14 0.16 0.21 0.38 0.43 0.43];  % nmol/kg
    
end

for PData =1

% Site 1 (56)
PFeDepths1 = [40 80 100 150 300];
PFe1       = [0.073087076 0.098925642 0.061827506 0.126527528 0.104796138]; % nmol/L
PP1        = [26.44407117 47.59177642 27.43658316 7.157861936 4.02370148]; %  nmol/L

PFeDepths3 = [40 80 100 150 300 500];
PFe3       = [0.048652695 0.110917861 0.059597258 0.165880758 0.093052745 0.090619814]; %nom/L
PP3        = [32.51031597 76.77771245 22.96329285 7.72498288  4.283957505 6.753906618 ]; %nom/L


PFeDepths4 = [30 40 100 150 300 500];
PFe4       = [0.086016461 0.052119323 0.095417154 0.029688485 0.058514771 0.039610284]; %nom/L
PP4        = [83.57772488 79.28600008 28.90336997 10.98356306 6.230406368 3.456816212]; %nom/L
PFeDepths5 = [40 80 100 150 300 500];
PFe5       = [0.116493908 0.4021683   0.068040239 nan 0.056917332 0.207007573 ]; %nom/L
PP5        = [122.1763667 86.55608306 36.53743081 nan 4.093968418 3.828622673]; %nom/L
end

%% Extracted Chl Data
for exChl =1
dchl47 = [5 10 25 50 70 90 110 150 200 400];
chl47  = [0.243 0.254 0.250 0.257 0.347 0.390 0.174 0.049 0.019 0.007];

dchl53 = [5 40 70 80 150 250 500];
chl53 = [0.215 0.280 0.485 0.759 0.040 0.016 0.018];

dchl60 = [5 10 25 50 70 85 100 150 200 500]; 
chl60 = [0.233 0.229 0.198 0.237 0.409 0.514 0.340 0.063 0.014 0.006];

dchl67=[5 10 25 40 80 85 100 150 200 400];
chl67=[0.706 0.595 0.613 0.670 0.310 0.204 0.150 0.038 0.022 0.009];

dchl76 =[10 25 50 80 90 100 150 200 500];
chl76 = [0.751 0.618 0.543 0.610 0.397 0.239 0.034 0.022 0.008];
end

%% Bsi Data
for exBsi=1
    
dbsi47 = [5 10 25 50 70 90 110 150 200 400];
bsi47 = [0.138 0.121 nan 0.108 0.169 0.155 0.063 0.040 0.049 0.038];

dbsi53 = [5 40 70 80 150 250 500];
bsi53 = [0.068 0.113 0.180 0.182 0.049 0.038 0.027];

dbsi60 = [5 10 25 50 70 85 100 150 200 400];
bsi60 = [0.102 0.104 0.122 0.154 0.235 0.167 0.113 0.069 0.037 0.016];

dbsi67 = [5 10 25 40 80 85 100 150 200 400];
bsi67 = [0.206 0.239 0.224 0.221 0.190 0.141 0.105 0.059 nan 0.056];

dbsi76 = [10 25 50 80 90 100 150 200 400]; 
bsi76 = [0.355 0.344 0.275 0.334 0.251 0.208 0.068 0.056 0.042];
end

%% FV/FM Sigma
for photosystems =1
dps47  = [5 10 25 50 70 90];
dps60  = [5 10 25 50 70 85] ;
dps67  = [5 10 25 40 80] ;

fvfm47 = [0.53 0.56 0.56 0.49 0.45 0.57];
fvfm60 = [0.33 0.21 0.54 0.54 0.52 0.52];
fvfm67 = [0.39 0.42 0.40 0.43 0.46];

sig47 = [1805 1717 1748 1152 1279 1553];
sig60 = [682 596 694 827 768 781];
sig67 = [895 904 940 1126 676];
end

%% C and Fe Uptake 
for uptake =1
% TMR 7 - (ctd indec 49)
depthS7 = [14.2 19.1 38.8 62.6 83.2 108.9]; % TMR 7
% Carbon µmol L-1 d-1
CtotS7 = [0.741 0.562 0.597 0.327 0.209 0.135];  
CsmS7  = [ 0.199 0.104 0.141 0.077 0.057 0.041]; % .2 -2
CmedS7   = [0.172 0.077 0.107 0.061 0.041 0.027]; % 2-20
ClgS7  = [ 0.370 0.381 0.348 0.188 0.110 0.066];  % >20

%Iron pmol L-1 d-1
FsmS7  = [ 4.8 13.3 12.3 1.2 1.0 1.1]; % .2 -2
FmedS7   = [3.6 3.4 2.7 0.4 0.3 0.2]; % 2-20
FlgS7  = [ 7.6 4.0 2.6 0.7 0.4 0.3];  % >20
Ftot7 = FsmS7+ FmedS7 +FlgS7;

% TMR 9 - (ctd indec 60)
% 29/12/20
depthS9 = [15.7 21.1 42.8 69.2 91.9 120.3]; 
% Carbon µmol L-1 d-1
CsmS9  = [0.067 0.089 0.092 0.071 0.066 0.034]; % .2 -2
CmedS9   = [0.054 0.079 0.106 0.044 0.038 0.024]; % 2-20
ClgS9 = [0.239 0.309 0.366 0.212 0.162 0.089];  % >20

%Iron pmol L-1 d-1
FsmS9  = [25.9 31.6 25.5 1.1 5.3 0.9 ]; % .2 -2
FmedS9  = [3.9 4.1 2.1 1.2 0.4 0.1]; % 2-20
FlgS9  = [9.6 3.2 2.8 0.7 0.4 0.2 ];  % >20
Ftot9 = FsmS9+ FmedS9 +FlgS9;

%%%% South 2

% TMR 11 - (ctd indec 68)
depthS11 = [10.6 14.3 29.0 46.9 62.3 81.5];  % TMR11
% Carbon µmol L-1 d-1
CtotS11 = [1.12 1.17 1.08 0.65 0.22 0.12];  
CsmS11  = [ 0.10 0.11 0.12 0.08 0.03 0.02]; % .2 -2
CmedS11   = [0.10 0.12 0.12 0.10 0.03 0.02]; % 2-2-
ClgS11  = [ 0.91 0.94 0.84 0.47 0.15 0.07];  % >2-

%Iron pmol L-1 d-1
FsmS11  = [14.9 9.8 5.6 0.8 0.8 0.3]; % .2 -2
FmedS11   = [4.4 2.6 1.2 0.4 0.1 0.1]; % 2-2-
FlgS11  = [ 8.9 2.4 1.2 0.7 0.3 0.1];  % >2-
Ftot11 = FsmS11+ FmedS11 +FlgS11;


% TMR 15 - (ctd index 84) No size Fractionation
% Day 10/1/21
depthS15 =[11.2 15.0 30.5 49.3 65.5 85.8];
Csum15 = [1.716 1.712 1.738 0.766 0.371 0.160];

end








%% %%%%%%%%%%%%%%%%%%%%%% Figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%% %%%%%%%%%%%%%%%%%%%%%% SOTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Site Profiles
for CTDPROFILES=1
% Create Figure
figure('Units','normalized','Position',[0 0 2 2])
clc
set(gcf,'color','w');
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
tmrcasti = [47,53,60,67,76];
 %load('CTD_MLD.mat', 'cast_isnight')

% SOTS 
 Stationi = 3:39;
 tx = 'SOTS';
 cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
 load poc_corrections_sots.mat
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles; load('MLD.mat', 'ctd_mld')
cmap = brewermap(180,'YlGnBU'); cmap=cmap(41:180,:);

% plotting
maxdepth = 300;
thickline =2;
thinline =.5;

% Mld
mlds  = ctd_mld(Stationi);
mldmean = mean(mlds);
mldstd  = std(mlds);


cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);


for i = Stationi
%subplot(2,3,1)
subplot(2,6,1)
xmin =8.5; xmax = 12;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).temp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).temp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');  
ylim([0,maxdepth]);
set(gca,'fontsize',15,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',18)
xlabel('Temp. (C)','interpreter','latex','fontsize',18)

%subplot(2,3,2)
subplot(2,6,2)
xmin =34.4; xmax = 35.2;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).sal,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).sal,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');
ylim([0,maxdepth]) 
set(gca,'fontsize',15,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',18)
xlabel('Sal. (psu)','interpreter','latex','fontsize',18)

%subplot(2,3,3)
subplot(2,6,3)
xmin =0.08; xmax = 1000;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).par,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).par,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev'); 
set(gca,'xscale','log')
xlim([xmin,xmax]);
ylim([0,maxdepth])
set(gca,'fontsize',15,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',18)
xlabel({'PAR'; '(uE/m2/s)'},'interpreter','latex','fontsize',18)

%subplot(2,3,4)
subplot(2,6,4)
xmin =0; xmax = 2.1;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');
ylim([0,maxdepth])
set(gca,'fontsize',15,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',18)
xlabel({'Chlorophyl';' Flo. (mg/m3)'},'interpreter','latex','fontsize',18)

%subplot(2,3,5)
subplot(2,6,5)
xmin =0; xmax = 14;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
ctd_trans = Profiles(i).trans;
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
if any(i==tmrcasti)
line(cf_cp_poc_0.*ctd_cp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(cf_cp_poc_0.*ctd_cp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev');
ylim([0,maxdepth]); 
xlim([xmin,xmax]);
set(gca,'fontsize',15,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',18)
xlabel({'Transmissometer';'POC (uM)'},'interpreter','latex','fontsize',18)

%subplot(2,3,6)
subplot(2,6,6)
xmin =0; xmax = 150;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
ctd_trans = Profiles(i).trans(1:500);
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
if any(i==tmrcasti)
line((12.*cf_cp_poc_0.*ctd_cp)./CHL_ctd(i,:),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line((12.*cf_cp_poc_0.*ctd_cp)./CHL_ctd(i,:),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',15,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',18)
xlabel('C:Chl (g:g)','interpreter','latex','fontsize',18)
end

colormap(cmap); caxis([0,8])
cloc = get(gca,'Position');
h= colorbar(gca,'position', [cloc(1)+cloc(3)+.02, cloc(2), .015, cloc(4) ], ...
    'orientation','vertical','TickLabelInterpreter','latex');
set(get(h,'ylabel'),'string', 'Days on station','interpreter','latex','fontsize',20)


% Title
ax(2) = axes; 
set(ax(2), 'Position',[.00   .00  .09  1]);
set(gca,'box','off','ycolor','w')
ht = text(.5,.53,tx,'Rotation',90,'interpreter','latex','FontSize',40,  'HorizontalAlignment', 'center');



end

%% %%%%%%%%%%%%%%%%%%%%%% Polar Site 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Site Profiles
clearvars ctd_dcm ctd_dbm
for CTDPROFILES=1
% Create Figure
figure('Units','normalized','Position',[0 2 1.8 2])
clc
set(gcf,'color','w');
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
tmrcasti = [47,53,60,67,76];
 %load('CTD_MLD.mat', 'cast_isnight')

% SOTS 
%  Stationi = 3:39;
%  tx = 'SOTS';
%  cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
%  load poc_corrections_sots.mat
% cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles; load('MLD.mat', 'ctd_mld')
% cmap = brewermap(160,'YlGnBU'); cmap=cmap(21:160,:);

% % SOUTH 1 
 South1_CTDi = 41:63; 
 Stationi = 41:63;
 %Stationi = Stationi(cast_isnight(Stationi))
 tx = 'SOUTH 1';
 load poc_corrections_south.mat
 cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles; load('MLD.mat', 'ctd_mld')
cmap = brewermap(100,'YlGnBU'); cmap=cmap(21:100,:);
%cmap = brewermap(100,'RdYlBu'); cmap=cmap(21:100,:);


% plotting
maxdepth = 300;
thickline =2;
thinline =.5;
lf= 23; tf =17;

% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);

% Check mld
% plot(ctd_mld(41:end),'linewidth',7); hold on;  
% plot(castmld_dg(41:end),'linewidth',7);hold on; 
% plot(castmld_dth(41:end),'linewidth',7); hold on
% plot((mean([castmld_dg(41:end);castmld_dth(41:end)])),'linewidth',7); hold on
% xline(63-40,'linewidth',7); hold on
% legend('eye test','grad=.0005','thresh = .03','mean','fontsize',30);


cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);

%%% find mean DCM
for i = 1:length(Stationi)
    
%%% find mean DCM
mCHL = (CHL_ctd(Stationi(i),:));
mCHL = (CHL_ctd(Stationi(i),:));
pres_dcm = Profiles(Stationi(i)).pres;
prof = mCHL;   

[max_m, max_i] = max(prof);
 % Assign metrics if theres a DCM
  if pres_dcm(squeeze(max_i))>mldmean && max_m> 1.1.*nanmean(prof(pres_dcm<mldmean)) %  % IS DCM BELOW MLD
     dcm_thr =  nanmean(prof(pres_dcm<mldmean)) + .5.* abs(max_m-nanmean(prof(pres_dcm<mldmean)));  % 50% of difference between MLD and max value 
     DCM = find(prof>dcm_thr) ; 
     DCM( pres_dcm(DCM) < (mldmean-30)) = [] ;  % Dont condsider values 30 m above MLD
        ctd_dcm(i,1) = squeeze(max_m); % Size of DCM
        ctd_dcm(i,2) = pres_dcm(squeeze(max_i)); % Depth of DCM
        ctd_dcm(i,3) = pres_dcm(DCM(1));         % Top of DCM
        ctd_dcm(i,4) = pres_dcm(DCM(end));       % Base of DCM
        ctd_dcm(i,5) = pres_dcm(DCM(end)) - pres_dcm(DCM(1));    % Width of DCM (m)
        ctd_dcm(i,6) = nanmean(prof(DCM)).*(pres_dcm(DCM(end)) - pres_dcm(DCM(1))); % integrate of DCM (mg/m2)
        ctd_dcm(i,7) = 100.*(max_m-nanmean(prof(pres_dcm<mldmean)))./nanmean(prof(pres_dcm<mldmean)); 
        ctd_dcm(i,8) = 100.*(nanmean(prof(DCM))-nanmean(prof(pres_dcm<mldmean)))./nanmean(prof(pres_dcm<mldmean)); 
   else
        ctd_dcm(i,1:8) = nan;
  end  
   

%%% find mean DBM
ctd_trans = Profiles(Stationi(i)).trans;
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
prof=cf_cp_poc_0.*ctd_cp;
pres_dcm = Profiles(Stationi(i)).pres;

[max_m, max_i] = max(prof);
 % Assign metrics if theres a DCM
  if pres_dcm(squeeze(max_i))>mldmean && max_m> 1.1.*nanmean(prof(pres_dcm<mldmean)) %  % IS DCM BELOW MLD
     dcm_thr =  nanmean(prof(pres_dcm<mldmean)) + .5.* abs(max_m-nanmean(prof(pres_dcm<mldmean)));  % 50% of difference between MLD and max value 
     DCM = find(prof>dcm_thr) ; 
     DCM( pres_dcm(DCM) < (mldmean-30)) = [] ;  % Dont condsider values 30 m above MLD
        ctd_dbm(i,1) = squeeze(max_m); % Size of DCM
        ctd_dbm(i,2) = pres_dcm(squeeze(max_i)); % Depth of DCM
        ctd_dbm(i,3) = pres_dcm(DCM(1));         % Top of DCM
        ctd_dbm(i,4) = pres_dcm(DCM(end));       % Base of DCM
        ctd_dbm(i,5) = pres_dcm(DCM(end)) - pres_dcm(DCM(1));    % Width of DCM (m)
        ctd_dbm(i,6) = nanmean(prof(DCM)).*(pres_dcm(DCM(end)) - pres_dcm(DCM(1))); % integrate of DCM (mg/m2)
        ctd_dbm(i,7) = 100.*(max_m-nanmean(prof(pres_dcm<mldmean)))./nanmean(prof(pres_dcm<mldmean)); 
        ctd_dbm(i,8) = 100.*(nanmean(prof(DCM))-nanmean(prof(pres_dcm<mldmean)))./nanmean(prof(pres_dcm<mldmean)); 
   else
        ctd_dbm(i,1:8) = nan;
   end  
end




for i = Stationi
    
   
    
    
%subplot(2,3,1)
subplot(2,4,1)
xmin =1.5; xmax = 4.5;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).temp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).temp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');  
ylim([0,maxdepth]);
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Temperature ($^\circ$C)','interpreter','latex','fontsize',lf)

%subplot(2,3,2)
subplot(2,4,2)
xmin =33.79; xmax = 34;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).sal,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).sal,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');
ylim([0,maxdepth]) 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Salinty ','interpreter','latex','fontsize',lf)

subplot(2,4,3)
xmin =0.1; xmax = 1000; 
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).par,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).par,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
%[a,b]=max(CHL_ctd(i,50:end));
%yline(b+50,':','Color',cmap(cday(i-Stationi(1)+1),:)); hold on 
end
set(gca,'ydir','rev'); 
xlim([xmin,xmax]); xticks([.1,1,10,100,1000])
set(gca,'xscale','log')
ylim([0,maxdepth]);
% For zoom in
% ylim([70,130]);
% xlim([0,10]);
set(gca,'fontsize',tf-1,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'PAR'; '(quanta)'},'interpreter','latex','fontsize',lf)



%subplot(2,3,4)
subplot(2,4,5)
xmin =0; xmax = .6;
if i == Stationi(1)
% MLD
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
% DCM
%fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(nanmean(ctd_dcm(:,2)),'m','linewidth',1); yline(nanmean(ctd_dcm(:,3)),'m:','linewidth',.5); yline(nanmean(ctd_dcm(:,4)),'m:','linewidth',.5)
end
if any(i==tmrcasti)
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');
ylim([0,maxdepth])
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Chlorophyl';'Fluorescence (mg m$^{-3}$)'},'interpreter','latex','fontsize',lf)

%subplot(2,3,5)
subplot(2,4,6)
xmin =0; xmax = 6;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
yline(nanmean(ctd_dbm(:,2)),'r','linewidth',1); yline(nanmean(ctd_dbm(:,3)),'r:','linewidth',.5); yline(nanmean(ctd_dbm(:,4)),'r:','linewidth',.5)
end
ctd_trans = Profiles(i).trans;
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
if any(i==tmrcasti)
line(cf_cp_poc_0.*ctd_cp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(cf_cp_poc_0.*ctd_cp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev');
ylim([0,maxdepth]); 
xlim([xmin,xmax]);
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Transmissometer';'POC ($\mu$M)'},'interpreter','latex','fontsize',lf)

% %subplot(2,3,6)
subplot(2,4,7)
xmin =0; xmax = 300;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
yline(nanmean(ctd_dcm(:,2)),'m','linewidth',1);% yline(nanmean(ctd_dcm(:,3)),'m:','linewidth',.5); yline(nanmean(ctd_dcm(:,4)),'m:','linewidth',.5)
yline(nanmean(ctd_dbm(:,2)),'r','linewidth',1);% yline(nanmean(ctd_dbm(:,3)),'r:','linewidth',.5); yline(nanmean(ctd_dbm(:,4)),'r:','linewidth',.5)

end
ctd_trans = Profiles(i).trans(1:500);
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
if any(i==tmrcasti)
line((12.*cf_cp_poc_0.*ctd_cp)./CHL_ctd(i,:),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line((12.*cf_cp_poc_0.*ctd_cp)./CHL_ctd(i,:),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('POC:Chl (g:g)','interpreter','latex','fontsize',lf)


subplot(2,4,8)
xmin =0; xmax = 300;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
yline(nanmean(ctd_dcm(:,2)),'m','linewidth',1); %yline(nanmean(ctd_dcm(:,3)),'m:','linewidth',.5); yline(nanmean(ctd_dcm(:,4)),'m:','linewidth',.5)
yline(nanmean(ctd_dbm(:,2)),'r','linewidth',1); %yline(nanmean(ctd_dbm(:,3)),'r:','linewidth',.5); yline(nanmean(ctd_dbm(:,4)),'r:','linewidth',.5)

end
%C2Chl =45+CHL_ctd(i,:).*0;  C2Chl(Profiles(i).pres>mldmean) = 45 - 2.*0.1578.*(Profiles(i).pres(Profiles(i).pres>mldmean) - mldmean) ;  
% C2Chl(Profiles(i).pres>100)=  45/2 ; C2Chl= C2Chl(1:500);
C2Chl =30+CHL_ctd(i,:).*0; 
ctd_trans = Profiles(i).trans(1:500);
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
if any(i==tmrcasti)
line((12.*cf_cp_poc_0.*ctd_cp(1:500)-C2Chl.*CHL_ctd(i,:))./(12.*cf_cp_poc_0.*ctd_cp(1:500)),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line((12.*cf_cp_poc_0.*ctd_cp(1:500)-C2Chl.*CHL_ctd(i,:))./(12.*cf_cp_poc_0.*ctd_cp(1:500)),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([0,1]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Detrital Fraction (g:g)','interpreter','latex','fontsize',lf)



end

subplot(2,4,3)
colormap(cmap); caxis([0,8])
cloc = get(gca,'Position');
h= colorbar(gca,'position', [cloc(1)+cloc(3)+.05, cloc(2)+.02, .04, cloc(4)-.02 ], ...
    'orientation','vertical','TickLabelInterpreter','latex','fontsize',tf);
set(get(h,'ylabel'),'string', 'Days on station','interpreter','latex','fontsize',25)


% Title
ax(2) = axes; 
set(ax(2), 'Position',[.00   .00  .09  1]);
set(gca,'box','off','ycolor','w')
ht = text(.5,.53,tx,'Rotation',90,'interpreter','latex','FontSize',40,  'HorizontalAlignment', 'center');



end

%% Just PAR
for PARPROFILES=1
% Create Figure
figure('Units','normalized','Position',[0 0 1.8 2])
clc
set(gcf,'color','w');
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
tmrcasti = [47,53,60,67,76];
 %load('CTD_MLD.mat', 'cast_isnight')

% SOTS 
%  Stationi = 3:39;
%  tx = 'SOTS';
%  cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
%  load poc_corrections_sots.mat
% cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles; load('MLD.mat', 'ctd_mld')
% cmap = brewermap(160,'YlGnBU'); cmap=cmap(21:160,:);

% % SOUTH 1 
 South1_CTDi = 41:63; 
 Stationi = 41:63;
 %Stationi = Stationi(cast_isnight(Stationi))
 tx = 'SOUTH 1';
 load poc_corrections_south.mat
 cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles; load('MLD.mat', 'ctd_mld')
cmap = brewermap(100,'YlGnBU'); cmap=cmap(21:100,:);

% plotting
maxdepth = 300;
thickline =2;
thinline =.5;
lf= 23; tf =17;

% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);

% Check mld
% plot(ctd_mld(41:end),'linewidth',7); hold on;  
% plot(castmld_dg(41:end),'linewidth',7);hold on; 
% plot(castmld_dth(41:end),'linewidth',7); hold on
% plot((mean([castmld_dg(41:end);castmld_dth(41:end)])),'linewidth',7); hold on
% xline(63-40,'linewidth',7); hold on
% legend('eye test','grad=.0005','thresh = .03','mean','fontsize',30);


cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);


for i = Stationi(cast_isday(Stationi)==1)
 [a,b]=max(CHL_ctd(i,50:end));
 DCM_max(i) = a;  DCM_depth(i) = b+49;
 PAR_dcm(i) = Profiles(i).par(b);
 PAR_mld(i) = Profiles(i).par(round(mldmean));
 
    subplot(1,2,1)
xmin =0.1; xmax = 1000; 
if i == 44;%Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).par,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',4); hold on
% [a,b]=max(CHL_ctd(i,50:end));
% yline(b+49,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',2); hold on 

else
line(Profiles(i).par,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',4); hold on
% [a,b]=max(CHL_ctd(i,50:end));
% yline(b+49,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',2); hold on 
end
set(gca,'ydir','rev'); 
%xlim([xmin,xmax]); xticks([.1,1,10,100,1000])
%set(gca,'xscale','log')
%ylim([0,maxdepth]);
% For zoom in
ylim([50,150]);
xlim([0,25]);
set(gca,'fontsize',tf-1,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'PAR'; '(uE/m2/s)'},'interpreter','latex','fontsize',lf)


subplot(1,2,2)
xmin =0; xmax = .6;
if i == 44;%Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',4); hold on
else
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',4); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');
ylim([50,150]);
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Chlorophyl';' Flo. (mg/m3)'},'interpreter','latex','fontsize',lf)


end


%%  DCM MAX
figure('Units','normalized','Position',[0 0 1.8 2])
clc
set(gcf,'color','w');

subplot(2,2,1)
scatter(PAR_dcm, DCM_max,200,'filled')
ylabel('DCM Magnitude (mg/m3)','interpreter','latex','fontsize',lf)
xlabel({'PAR @ DCM (uE/m2/s)'},'interpreter','latex','fontsize',lf)
ylim([.3,.6])
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')


subplot(2,2,2)
scatter(PAR_dcm, DCM_depth,200,'filled')
ylabel('DCM depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'PAR @ DCM (uE/m2/s)'},'interpreter','latex','fontsize',lf)
ylim([75,95])
set(gca,'ydir','rev');
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')


subplot(2,2,3)
scatter(PAR_mld, DCM_max,200,'filled')
ylabel('DCM Magnitude (mg/m3)','interpreter','latex','fontsize',lf)
xlabel({'PAR @ MLD (uE/m2/s)'},'interpreter','latex','fontsize',lf)
ylim([.3,.6])
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')


subplot(2,2,4)
scatter(PAR_mld, DCM_depth,200,'filled')
ylabel('DCM depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'PAR @ MLD (uE/m2/s)'},'interpreter','latex','fontsize',lf)
ylim([75,95])
set(gca,'ydir','rev');
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')


end
 
%% Discrete Samples
for DisProfiles =1
% SOUTH 1 
 South1_CTDi = 41:63; 
 Stationi = 41:63;
 tx = 'SOUTH 1';

% SOUTH 2
% South2_CTDi = 64:85;
% Stationi = 64:85;
% tx = 'SOUTH 2';
% load poc_corrections_south.mat

% plotting
maxdepth = 300;
thickline =4;
thinline =4;
ms =15;
lf= 23; tf =17;

% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);

cmap = brewermap(100,'YlGnBU'); cmap=cmap(21:100,:);
cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);


figure('Units','normalized','Position',[0 0 1.8 2])
clc
set(gcf,'color','w');
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
tmrcasti = [47,53,60,67,76];

% DFe
subplot(2,6,1)
xmin =0; xmax = .6;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(dFe1(~isnan(dFe1)),dFeDepths1(~isnan(dFe1)),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(dFe2(~isnan(dFe2)),dFeDepths2(~isnan(dFe2)),'-*','Color',cmap(cday(tmrcasti(2)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(dFe3(~isnan(dFe3)),dFeDepths3(~isnan(dFe3)),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$dFe$ (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)


% Nitrate
subplot(2,6,2) 
nuti =2;
xmin =24; xmax = 36;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD47(~isnan(CTD47(:,nuti)),nuti),CTD47(~isnan(CTD47(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD53(~isnan(CTD53(:,nuti)),nuti),CTD53(~isnan(CTD53(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(2)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD60(~isnan(CTD60(:,nuti)),nuti),CTD60(~isnan(CTD60(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$NO_3$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)

% Amonia 
subplot(2,6,3) 
nuti =5;
xmin =0; xmax = 0.8;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD47(~isnan(CTD47(:,nuti)),nuti),CTD47(~isnan(CTD47(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD53(~isnan(CTD53(:,nuti)),nuti),CTD53(~isnan(CTD53(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(2)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD60(~isnan(CTD60(:,nuti)),nuti),CTD60(~isnan(CTD60(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); xticks([0,.2,.4,.6,.8])
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$NH_4$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)

% Nitrite 
subplot(2,6,4) 
nuti =6;
xmin =0; xmax = 0.3;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD47(~isnan(CTD47(:,nuti)),nuti),CTD47(~isnan(CTD47(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD53(~isnan(CTD53(:,nuti)),nuti),CTD53(~isnan(CTD53(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(2)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD60(~isnan(CTD60(:,nuti)),nuti),CTD60(~isnan(CTD60(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$NO_2$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)


% Si 
subplot(2,6,5) 
nuti =4;
xmin =0; xmax = 33;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD47(~isnan(CTD47(:,nuti)),nuti),CTD47(~isnan(CTD47(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD53(~isnan(CTD53(:,nuti)),nuti),CTD53(~isnan(CTD53(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(2)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD60(~isnan(CTD60(:,nuti)),nuti),CTD60(~isnan(CTD60(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$Si$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)

subplot(2,6,6) 
nuti =3;
xmin =1.5; xmax = 2.5;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD47(~isnan(CTD47(:,nuti)),nuti),CTD47(~isnan(CTD47(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD53(~isnan(CTD53(:,nuti)),nuti),CTD53(~isnan(CTD53(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(2)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD60(~isnan(CTD60(:,nuti)),nuti),CTD60(~isnan(CTD60(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$PO_4$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)


% Extracted Chl 
subplot(2,6,7) 

xmin =0; xmax = 0.85;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(chl47(~isnan(chl47)),dchl47(~isnan(chl47)),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(chl53(~isnan(chl53)),dchl53(~isnan(chl53)),'-*','Color',cmap(cday(tmrcasti(2)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(chl60(~isnan(chl60)),dchl60(~isnan(chl60)),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

d=1:100
c47 = interp1(dchl47(~isnan(chl47)),chl47(~isnan(chl47)),d);
c53 = interp1(dchl53(~isnan(chl53)),chl53(~isnan(chl53)),d);
c60 = interp1(dchl60(~isnan(chl60)),chl60(~isnan(chl60)),d);
delchl = c60-c47;
meanchl = nanmean([c47;c53;c60]);
smlchl = nanmean(meanchl(d>14.2 & d<(mldmean)))
dcmchl = nanmean(meanchl(d>71.4 & d<86.7))
dbmchl = nanmean(meanchl(d>80.4 & d<103.3))

smlchl = nanmean(delchl(d>14.2 & d<(mldmean)))
dcmchl = nanmean(delchl(d>71.4 & d<86.7))
dbmchl = nanmean(delchl(d>80.4 & d<103.3))


set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Extracted'; 'Chlorophyl (mg m$^{-3}$)'},'interpreter','latex','fontsize',lf)

% Biogenic Si
subplot(2,6,8) 

xmin =0; xmax = .25;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(bsi47(~isnan(bsi47)),dbsi47(~isnan(bsi47)),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(bsi53(~isnan(bsi53)),dbsi53(~isnan(bsi53)),'-*','Color',cmap(cday(tmrcasti(2)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(bsi60(~isnan(bsi60)),dbsi60(~isnan(bsi60)),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

d=1:100
b47 = interp1(dbsi47(~isnan(bsi47)),bsi47(~isnan(bsi47)),d);
b53 = interp1(dbsi53(~isnan(bsi53)),bsi53(~isnan(bsi53)),d);
b60 = interp1(dbsi60(~isnan(bsi60)),bsi60(~isnan(bsi60)),d);
meanchl = nanmean([b47;b53;b60]);
smlchl = nanmean(meanchl(d>14.2 & d<(mldmean)))
dcmchl = nanmean(meanchl(d>71.4 & d<86.7))
dbmchl = nanmean(meanchl(d>80.4 & d<103.3))

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Biogenic $Si$';' ($\mu$mol L$^{-1}$)'},'interpreter','latex','fontsize',lf)


% Fv/Fm
subplot(2,6,9) 

xmin =0.15; xmax = .65;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(fvfm47(~isnan(fvfm47)),dps47(~isnan(fvfm47)),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(fvfm60(~isnan(fvfm60)),dps60(~isnan(fvfm60)),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
%plot(fvfm67(~isnan(fvfm67)),dps67(~isnan(fvfm67)),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$F_V/F_M$','interpreter','latex','fontsize',lf)


% Sigma 2
subplot(2,6,10) 

xmin =500; xmax = 2000;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(sig47(~isnan(sig47)),dps47(~isnan(sig47)),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(sig60(~isnan(sig60)),dps60(~isnan(sig60)),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
%plot(sig67(~isnan(sig67)),dps67(~isnan(sig67)),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'$\sigma _{PSII}$';' (nm$^{2}$ RC$^{-1}$)'},'interpreter','latex','fontsize',lf)


% Carbon Uptake
subplot(2,6,11) 

xmin =0; xmax = .8;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
%h(1)= plot(CsmS7,depthS7,':*','Color',cmap(cday(49-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%h(2)=plot(CsmS7+CmedS7,depthS7,'--*','Color',cmap(cday(49-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
h(3)=plot(CsmS7+CmedS7+ClgS7,depthS7,'-*','Color',cmap(cday(49-Stationi(1)+1),:),'linewidth',4,'markersize',ms); hold on
%plot(CsmS9,depthS9,':*','Color',cmap(cday(60-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%plot(CsmS9+CmedS9,depthS9,'--*','Color',cmap(cday(60-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
plot(CsmS9+CmedS9+ClgS9,depthS9,'-*','Color',cmap(cday(60-Stationi(1)+1),:),'linewidth',4,'markersize',ms); hold on


set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Community Carbon';'Uptake ($\mu$mol L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)
%legend(h(1:3),'$<$0.2 $\mu$m', '$<$20 $\mu$m','All Sizes','interpreter','latex','fontsize',14,'location','south') 
%legend(h(1:3),'$<$2 $\mu$m', '$<$20 $\mu$m','All Sizes','interpreter','latex','fontsize',20,'location','south') 


% Iron Uptake
subplot(2,6,12) 

xmin =0; xmax = 40;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
%h(1)= plot(FsmS7,depthS7,':*','Color',cmap(cday(49-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%h(2)=plot(FsmS7+FmedS7,depthS7,'--*','Color',cmap(cday(49-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
h(3)=plot(FsmS7+FmedS7+FlgS7,depthS7,'-*','Color',cmap(cday(49-Stationi(1)+1),:),'linewidth',4,'markersize',ms); hold on
%plot(FsmS9,depthS9,':*','Color',cmap(cday(60-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%plot(FsmS9+FmedS9,depthS9,'--*','Color',cmap(cday(60-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
plot(FsmS9+FmedS9+FlgS9,depthS9,'-*','Color',cmap(cday(60-Stationi(1)+1),:),'linewidth',4,'markersize',ms); hold on


set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Community $Fe$ ';'Uptake (pmol L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)
%legend(h(1:3),'$<$0.2 $\mu$m', '$<$20 $\mu$m','All Sizes','interpreter','latex','fontsize',14,'location','south') 

cloc = get(gca,'Position');
h= colorbar(gca,'position', [cloc(1)+cloc(3)+.02, cloc(2), .015, cloc(4) ], ...
    'orientation','vertical','TickLabelInterpreter','latex','fontsize',tf);
set(get(h,'ylabel'),'string', 'Days on station','interpreter','latex','fontsize',20)



end



%%%%%%%%%%%%%%%%%%%%%%%% Polar Site 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Site Profiles
for CTDProfiles=1
    clearvars ctd_dcm ctd_dbm
    
% Create Figure
figure('Units','normalized','Position',[0 2 1.8 2])
clc
set(gcf,'color','w');
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
tmrcasti = [47,53,60,67,76];
 %load('CTD_MLD.mat', 'cast_isnight')


% % SOUTH 2
South2_CTDi = 64:85;
Stationi = 64:85;
tx = 'SOUTH 2';
%load poc_corrections_south.mat
%cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles; load('MLD.mat', 'ctd_mld')

% plotting
maxdepth = 200;
maxdepth = 300;
thickline =2;
thinline =.5;
lf= 23; tf =17;


% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);

cmap = brewermap(120,'YlGnBU'); cmap=cmap(21:120,:);
cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);

for i = 1:length(Stationi)
%%% find mean DCM
mCHL = (CHL_ctd(Stationi(i),:));
mCHL = (CHL_ctd(Stationi(i),:));
pres_dcm = Profiles(Stationi(i)).pres;
prof = mCHL;   

[max_m, max_i] = max(prof);
 % Assign metrics if theres a DCM
  if pres_dcm(squeeze(max_i))>mldmean && max_m> 1.1.*nanmean(prof(pres_dcm<mldmean)) %  % IS DCM BELOW MLD
     dcm_thr =  nanmean(prof(pres_dcm<mldmean)) + .5.* abs(max_m-nanmean(prof(pres_dcm<mldmean)));  % 50% of difference between MLD and max value 
     DCM = find(prof>dcm_thr) ; 
     DCM( pres_dcm(DCM) < (mldmean-30)) = [] ;  % Dont condsider values 30 m above MLD
        ctd_dcm(i,1) = squeeze(max_m); % Size of DCM
        ctd_dcm(i,2) = pres_dcm(squeeze(max_i)); % Depth of DCM
        ctd_dcm(i,3) = pres_dcm(DCM(1));         % Top of DCM
        ctd_dcm(i,4) = pres_dcm(DCM(end));       % Base of DCM
        ctd_dcm(i,5) = pres_dcm(DCM(end)) - pres_dcm(DCM(1));    % Width of DCM (m)
        ctd_dcm(i,6) = nanmean(prof(DCM)).*(pres_dcm(DCM(end)) - pres_dcm(DCM(1))); % integrate of DCM (mg/m2)
        ctd_dcm(i,7) = 100.*(max_m-nanmean(prof(pres_dcm<mldmean)))./nanmean(prof(pres_dcm<mldmean)); 
        ctd_dcm(i,8) = 100.*(nanmean(prof(DCM))-nanmean(prof(pres_dcm<mldmean)))./nanmean(prof(pres_dcm<mldmean)); 
   else
        ctd_dcm(i,1:8) = nan;
  end  
   

%%% find mean DBM
ctd_trans = Profiles(Stationi(i)).trans;
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
prof=cf_cp_poc_0.*ctd_cp;
pres_dcm = Profiles(Stationi(i)).pres;

[max_m, max_i] = max(prof);
 % Assign metrics if theres a DCM
  if pres_dcm(squeeze(max_i))>mldmean && max_m> 1.1.*nanmean(prof(pres_dcm<mldmean)) %  % IS DCM BELOW MLD
     dcm_thr =  nanmean(prof(pres_dcm<mldmean)) + .5.* abs(max_m-nanmean(prof(pres_dcm<mldmean)));  % 50% of difference between MLD and max value 
     DCM = find(prof>dcm_thr) ; 
     DCM( pres_dcm(DCM) < (mldmean-30)) = [] ;  % Dont condsider values 30 m above MLD
        ctd_dbm(i,1) = squeeze(max_m); % Size of DCM
        ctd_dbm(i,2) = pres_dcm(squeeze(max_i)); % Depth of DCM
        ctd_dbm(i,3) = pres_dcm(DCM(1));         % Top of DCM
        ctd_dbm(i,4) = pres_dcm(DCM(end));       % Base of DCM
        ctd_dbm(i,5) = pres_dcm(DCM(end)) - pres_dcm(DCM(1));    % Width of DCM (m)
        ctd_dbm(i,6) = nanmean(prof(DCM)).*(pres_dcm(DCM(end)) - pres_dcm(DCM(1))); % integrate of DCM (mg/m2)
        ctd_dbm(i,7) = 100.*(max_m-nanmean(prof(pres_dcm<mldmean)))./nanmean(prof(pres_dcm<mldmean)); 
        ctd_dbm(i,8) = 100.*(nanmean(prof(DCM))-nanmean(prof(pres_dcm<mldmean)))./nanmean(prof(pres_dcm<mldmean)); 
   else
        ctd_dbm(i,1:8) = nan;
   end  
end




for i = Stationi

subplot(2,4,1)
xmin =1; xmax = 4;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).temp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).temp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');  
ylim([0,maxdepth]);
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Temp. ($^\circ$C)','interpreter','latex','fontsize',lf)

subplot(2,4,2)
xmin =33.79; xmax = 33.86;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).sal,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).sal,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');
ylim([0,maxdepth]) 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Salinity','interpreter','latex','fontsize',lf)

subplot(2,4,3)
xmin =0.1; xmax = 1000;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).par,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).par,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev'); 
set(gca,'xscale','log')
xlim([xmin,xmax]); xticks([.1,1,10,100,1000]);
ylim([0,maxdepth]);
set(gca,'fontsize',tf-2,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'PAR';'(quanta)'},'interpreter','latex','fontsize',lf)

subplot(2,4,5)
xmin =0; xmax = .9;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
%yline(nanmean(ctd_dcm(:,2)),'m','linewidth',1); yline(nanmean(ctd_dcm(:,3)),'m:','linewidth',.5); yline(nanmean(ctd_dcm(:,4)),'m:','linewidth',.5)

end
if any(i==tmrcasti)
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');
ylim([0,maxdepth])
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Chlorophyl'; 'Fluorescence (mg m$^{-3}$)'},'interpreter','latex','fontsize',lf)

subplot(2,4,6)
xmin =0; xmax = 9;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
%yline(nanmean(ctd_dbm(:,2)),'r','linewidth',1); yline(nanmean(ctd_dbm(:,3)),'r:','linewidth',.5); yline(nanmean(ctd_dbm(:,4)),'r:','linewidth',.5)

end
ctd_trans = Profiles(i).trans;
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
if any(i==tmrcasti)
line(cf_cp_poc_0.*ctd_cp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(cf_cp_poc_0.*ctd_cp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev');
ylim([0,maxdepth]); 
xlim([xmin,xmax]);
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Transmissometer';'POC ($\mu$M)'},'interpreter','latex','fontsize',lf)

subplot(2,4,7)
xmin =0; xmax = 300;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
%yline(nanmean(ctd_dcm(:,2)),'m','linewidth',1); yline(nanmean(ctd_dcm(:,3)),'m:','linewidth',.5); yline(nanmean(ctd_dcm(:,4)),'m:','linewidth',.5)
%yline(nanmean(ctd_dbm(:,2)),'r','linewidth',1); yline(nanmean(ctd_dbm(:,3)),'r:','linewidth',.5); yline(nanmean(ctd_dbm(:,4)),'r:','linewidth',.5)
end
ctd_trans = Profiles(i).trans(1:500);
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
if any(i==tmrcasti)
line((12.*cf_cp_poc_0.*ctd_cp)./CHL_ctd(i,:),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line((12.*cf_cp_poc_0.*ctd_cp)./CHL_ctd(i,:),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('POC:Chl (g:g)','interpreter','latex','fontsize',lf)


subplot(2,4,8)
xmin =0; xmax = 300;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
%yline(nanmean(ctd_dcm(:,2)),'m','linewidth',1); yline(nanmean(ctd_dcm(:,3)),'m:','linewidth',.5); yline(nanmean(ctd_dcm(:,4)),'m:','linewidth',.5)
%yline(nanmean(ctd_dbm(:,2)),'r','linewidth',1); yline(nanmean(ctd_dbm(:,3)),'r:','linewidth',.5); yline(nanmean(ctd_dbm(:,4)),'r:','linewidth',.5)
end
C2Chl =30; 
ctd_trans = Profiles(i).trans(1:500);
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
if any(i==tmrcasti)
line((12.*cf_cp_poc_0.*ctd_cp(1:500)-C2Chl.*CHL_ctd(i,:))./(12.*cf_cp_poc_0.*ctd_cp(1:500)),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line((12.*cf_cp_poc_0.*ctd_cp(1:500)-C2Chl.*CHL_ctd(i,:))./(12.*cf_cp_poc_0.*ctd_cp(1:500)),...
      Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([0,1]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Detrital Fraction (g:g)','interpreter','latex','fontsize',lf)

end

subplot(2,4,3)
colormap(cmap); caxis([0,10])
cloc = get(gca,'Position');
h= colorbar(gca,'position', [cloc(1)+cloc(3)+.05, cloc(2)+.02, .04, cloc(4)-.02 ], ...
    'orientation','vertical','TickLabelInterpreter','latex','fontsize',tf);
set(get(h,'ylabel'),'string', 'Days on station','interpreter','latex','fontsize',20)


% Title
ax(2) = axes; 
set(ax(2), 'Position',[.00   .00  .09  1]);
set(gca,'box','off','ycolor','w')
ht = text(.5,.53,tx,'Rotation',90,'interpreter','latex','FontSize',40,  'HorizontalAlignment', 'center');

end

%% Sup Fig on DCM DX
%%%%%%%%%%%%%%%%%%%%%%%% Polar Site 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for CTDProfiles=1
% Create Figure
figure('Units','normalized','Position',[0 2 1.8 2])
clc
set(gcf,'color','w');
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
tmrcasti = [47,53,60,67,76];
 %load('CTD_MLD.mat', 'cast_isnight')


% % SOUTH 2
South2_CTDi = 64:85;
Stationi = 64:85;
tx = 'SOUTH 2';
%load poc_corrections_south.mat
%cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles; load('MLD.mat', 'ctd_mld')

% plotting
maxdepth = 200;
maxdepth = 300;
thickline =2;
thinline =2;
lf= 25; tf =25;


% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);


cmap = brewermap(120,'YlGnBU'); cmap=cmap(21:120,:);
cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);


for i = Stationi
    ii=i-63;
     [a,b]=max(CHL_ctd(i,50:end));
 DCM_max(ii) = a;  DCM_depth(ii) = b+49;
 CHL_mld(ii) = mean(CHL_ctd(i,1:67));
 Chl_Deep_enh(ii) =     (DCM_max(ii)-CHL_mld(ii))/CHL_mld(ii);
 time(ii) = casttime_loc(i);
 
 ctd_trans = Profiles(i).trans;
 ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
 poc= movmean(cf_cp_poc_0.*ctd_cp,5);
 
 [a,b]=max(poc(50:end));
 DBM_max(ii) = a;  DCM_depth(ii) = b+49;
 C_mld(ii) = mean(poc(1:67));
 C_Deep_enh(ii) =     (DBM_max(ii)-C_mld(ii))/C_mld(ii);
 time(ii) = casttime_loc(i);
 
subplot(2,3,1)
xmin =0; xmax = .9;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(CHL_ctd(i,:),Profiles(i).pres(1:500),'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
ylim([0,100]);
xlim([.55,.85])
set(gca,'ydir','rev');
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Chlorophyl'; 'Fluorescence (mg m$^{-3}$)'},'interpreter','latex','fontsize',lf)


subplot(2,3,4)
xmin =0; xmax = 9;
if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
ctd_trans = Profiles(i).trans;
ctd_cp = -(1/.25) .* log(ctd_trans ./100) - c_sw_ctd;
if any(i==tmrcasti)
line(cf_cp_poc_0.*ctd_cp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(poc,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
set(gca,'ydir','rev');
ylim([0,100]); 
xlim([5.5,8.5]);
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Transmissometer';'POC ($\mu$M)'},'interpreter','latex','fontsize',lf)


end

timec=time-datenum('01-Jan-2021','dd-mmm-yyyy');

subplot(2,3,2)
scatter(time, DCM_max,300,cmap(cday(Stationi-Stationi(1)+1),:),'filled')
xlabel('Time','interpreter','latex','fontsize',lf)
ylabel({' DCM Size (mg m$^{-3}$)'},'interpreter','latex','fontsize',lf)
%ylim([.3,.6])
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
datetick(gca,'x','keeplimits')

subplot(2,3,5)
% mdl = fitlm(timec, DBM_max);
% plot(mdl); hold on
scatter(time, DBM_max,300,cmap(cday(Stationi-Stationi(1)+1),:),'filled')
ylabel('DBM Size ($\mu$M)','interpreter','latex','fontsize',lf)
xlabel({'Date'},'interpreter','latex','fontsize',lf)
ylim([6,9])
%set(gca,'ydir','rev');
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
datetick(gca,'x','keeplimits')

% time v dcm enhancement
% subplot(2,3,3)
% scatter(time, Chl_Deep_enh.*100,300,cmap(cday(Stationi-Stationi(1)+1),:),'filled')
% ylabel('DCM Enhancement ($\%$)','interpreter','latex','fontsize',lf)
% xlabel({'Time'},'interpreter','latex','fontsize',lf)
% %%set(gca,'ydir','rev');
% ylim([-5,15])
% set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
% datetick(gca,'x','keeplimits')

% time v mld
subplot(2,3,3)
scatter(time, mlds,300,cmap(cday(Stationi-Stationi(1)+1),:),'filled')
ylabel('DCM Enhancement ($\%$)','interpreter','latex','fontsize',lf)
xlabel({'Time'},'interpreter','latex','fontsize',lf)
%%set(gca,'ydir','rev');
ylim([50,100])
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
datetick(gca,'x','keeplimits')


subplot(2,3,6)
% mdl = fitlm(timec, C_Deep_enh.*100);
% plot(mdl); hold on
scatter(time, C_Deep_enh.*100,300,cmap(cday(Stationi-Stationi(1)+1),:),'filled')
ylabel('DBM  Enhancement ($\%$)','interpreter','latex','fontsize',lf)
xlabel({'Date'},'interpreter','latex','fontsize',lf)
%%set(gca,'ydir','rev');
ylim([0,30])
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
datetick(gca,'x','keeplimits')


subplot(2,3,6)
colormap(cmap); caxis([0,8])
cloc = get(gca,'Position');
h= colorbar(gca,'position', [cloc(1)+cloc(3)+.02, cloc(2), .02, .82 ], ...
    'orientation','vertical','TickLabelInterpreter','latex','fontsize',tf);
set(get(h,'ylabel'),'string', 'Days on station','interpreter','latex','fontsize',35)

end

%% Discrete Samples
for DisProfiles =1

% SOUTH 2
South2_CTDi = 64:85;
Stationi = 64:85;
tx = 'SOUTH 2';

% plotting
maxdepth = 300;
thickline =4;
thinline =5;
lf= 23; tf =17;
ms =15;

% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);


cmap = brewermap(120,'YlGnBU'); cmap=cmap(21:120,:);
%cmap = brewermap(120,'RdYlBU'); cmap=cmap(21:120,:);
cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);

figure('Units','normalized','Position',[0 2 1.8 2])
clc
set(gcf,'color','w');
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
tmrcasti = [47,53,60,67,76];

% DFe
subplot(2,6,1)
xmin =0; xmax = .6;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(dFe4(~isnan(dFe4)),dFeDepths4(~isnan(dFe4)),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(dFe5(~isnan(dFe5)),dFeDepths5(~isnan(dFe5)),'-*','Color',cmap(cday(tmrcasti(5)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

d=1:100
f4 = interp1(dFeDepths4(~isnan(dFe4)),dFe4(~isnan(dFe4)),d);
f5 = interp1(dFeDepths5(~isnan(dFe5)),dFe5(~isnan(dFe5)),d);
meanbsi = nanmean([f4;f5]);
fsml4 = nanmean(f4(d>10.6 & d<67.7))
fsml5 = nanmean(f5(d>10.6 & d<67.7))

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$dFe$ (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)


% Nitrate
subplot(2,6,2) 
nuti =2;
xmin =23; xmax = 36;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD67(~isnan(CTD67(:,nuti)),nuti),CTD67(~isnan(CTD67(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD76(~isnan(CTD76(:,nuti)),nuti),CTD76(~isnan(CTD76(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(5)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$NO_3$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)

% Amonia 
subplot(2,6,3) 
nuti =5;
xmin =0; xmax = 1;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD67(~isnan(CTD67(:,nuti)),nuti),CTD67(~isnan(CTD67(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD76(~isnan(CTD76(:,nuti)),nuti),CTD76(~isnan(CTD76(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(5)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$NH_4$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)

% Nitrite 
subplot(2,6,4) 
nuti =6;
xmin =0; xmax = 0.3;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD67(~isnan(CTD67(:,nuti)),nuti),CTD67(~isnan(CTD67(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD76(~isnan(CTD76(:,nuti)),nuti),CTD76(~isnan(CTD76(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(5)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$NO_2$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)


% Si 
subplot(2,6,5) 
nuti =4;
xmin =0; xmax = 33;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD67(~isnan(CTD67(:,nuti)),nuti),CTD67(~isnan(CTD67(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD76(~isnan(CTD76(:,nuti)),nuti),CTD76(~isnan(CTD76(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(5)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

s67 = interp1(CTD67(~isnan(CTD67(:,nuti)),1),CTD67(~isnan(CTD67(:,nuti)),nuti),d);
s76 = interp1(CTD76(~isnan(CTD76(:,nuti)),1),CTD76(~isnan(CTD76(:,nuti)),nuti),d);
meanbsi = nanmean([s67;s76]);
Ssml67 = nanmean(s67(d>10.6 & d<67.7))
Ssml76 = nanmean(s76(d>10.6 & d<67.7))

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$Si$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)

subplot(2,6,6) 
nuti =3;
xmin =1.5; xmax = 2.5;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(CTD67(~isnan(CTD67(:,nuti)),nuti),CTD67(~isnan(CTD67(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD76(~isnan(CTD76(:,nuti)),nuti),CTD76(~isnan(CTD76(:,nuti)),1),'-*','Color',cmap(cday(tmrcasti(5)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$PO_4$ ($\mu$mol L$^{-1}$)','interpreter','latex','fontsize',lf)

% Extracted Chl 
subplot(2,6,7) 

xmin =0; xmax = 0.85;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(chl67(~isnan(chl67)),dchl67(~isnan(chl67)),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(chl76(~isnan(chl76)),dchl76(~isnan(chl76)),'-*','Color',cmap(cday(tmrcasti(5)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on


d=1:100
c67 = interp1(dchl67(~isnan(chl67)),chl67(~isnan(chl67)),d);
c76 = interp1(dchl76(~isnan(chl76)),chl76(~isnan(chl76)),d);
meanchl = nanmean([c67;c76]);
delchl = c76-c67;
smlchl = nanmean(meanchl(d>10.6 & d<67.7))
dcmchl = nanmean(meanchl(d>67.7 & d<91.8))

dsmlchl = nanmean(delchl(d>10.6 & d<67.7))
ddcmchl = nanmean(delchl(d>67.7 & d<91.8))


set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Extracted'; 'Chlorophyl (mg m$^{-3}$)'},'interpreter','latex','fontsize',lf)

% Biogenic Si
subplot(2,6,8) 

xmin =0; xmax = .4;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(bsi67(~isnan(bsi67)),dbsi67(~isnan(bsi67)),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(bsi76(~isnan(bsi76)),dbsi76(~isnan(bsi76)),'-*','Color',cmap(cday(tmrcasti(5)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on


d=1:100
b67 = interp1(dbsi67(~isnan(bsi67)),bsi67(~isnan(bsi67)),d);
b76 = interp1(dbsi76(~isnan(bsi76)),bsi76(~isnan(bsi76)),d);
meanbsi = nanmean([b67;b76]);
smlchl = nanmean(meanbsi(d>10.6 & d<67.7))
dcmchl = nanmean(meanbsi(d>67.7 & d<91.8))


set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Biogenic $Si$';' ($\mu$mol L$^{-1}$)'},'interpreter','latex','fontsize',lf)

% Fv/Fm
subplot(2,6,9) 

xmin =0.35; xmax = .55;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(fvfm67(~isnan(fvfm67)),dps67(~isnan(fvfm67)),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$F_V/F_M$','interpreter','latex','fontsize',lf)


% Sigma 2
subplot(2,6,10) 

xmin =500; xmax = 1300;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
plot(sig67(~isnan(sig67)),dps67(~isnan(sig67)),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'$\sigma _{PSII}$';' (nm$^{2}$ RC$^{-1}$)'},'interpreter','latex','fontsize',lf)


% Carbon Uptake
subplot(2,6,11) 

xmin =0; xmax = 2;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
%h(1)= plot(CsmS11,depthS11,':*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%h(2)=plot(CsmS11+CmedS11,depthS11,'--*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
h(3)=plot(CsmS11+CmedS11+ClgS11,depthS11,'-*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
%h(1)= plot(CsmS11,depthS11,':*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%h(2)=plot(CmedS11,depthS11,'--*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%h(3)=plot(CmedS11,depthS11,'-.*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',2,'markersize',ms); hold on
h(34)=plot(CsmS11+CmedS11+ClgS11,depthS11,'-*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on

% h(1)= plot(CsmS11,depthS11,':*','Color','k','linewidth',1,'markersize',ms/2); hold on
% h(2)=plot(CsmS11+CmedS11,depthS11,'--*','Color','k','linewidth',1,'markersize',ms/2); hold on
% h(3)=plot(CsmS11+CmedS11+ClgS11,depthS11,'-*','Color','k','linewidth',2,'markersize',ms); hold on
plot(Csum15,depthS15,'-*','Color',cmap(cday(85-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on


set(gca,'ydir','rev');  
ylim([0,300])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Community Carbon';'Uptake ($\mu$mol L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)
%legend(h(1:3),'$<$0.2-2.0 $\mu$m', '$<$0.2-20 $\mu$m','All $>$0.2$\mu$m','interpreter','latex','fontsize',14,'location','south') 


% Iron Uptake
subplot(2,6,12) 

xmin =0; xmax = 30;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
%h(1)= plot(FsmS11,depthS11,':*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%h(2)=plot(FsmS11+FmedS11,depthS11,'--*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
h(3)=plot(FsmS11+FmedS11+FlgS11,depthS11,'-*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
%h(1)= plot(FsmS11,depthS11,':*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%h(2)=plot(FmedS11,depthS11,'--*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%h(3)=plot(FlgS11,depthS11,'-.*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',1,'markersize',ms/2); hold on
%h(4)=plot(FsmS11+FmedS11+FlgS11,depthS11,'-*','Color',cmap(cday(68-Stationi(1)+1),:),'linewidth',2,'markersize',ms); hold on


set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Community $Fe$';'Uptake (pmol L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)
%legend(h(1:3),'$<$0.2 $\mu$m', '$<$20 $\mu$m','All Sizes','interpreter','latex','fontsize',14,'location','south') 

cloc = get(gca,'Position');
colormap(cmap); caxis([0,8])
h= colorbar(gca,'position', [cloc(1)+cloc(3)+.02, cloc(2), .015, cloc(4) ], ...
    'orientation','vertical','TickLabelInterpreter','latex','fontsize',tf);
set(get(h,'ylabel'),'string', 'Days on station','interpreter','latex','fontsize',20)




end




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Size Fracitonate Uptake -- Both Sites %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for sizeFrac=1
% Create Figure
figure('Units','normalized','Position',[0 0 1.8 2])
clc
set(gcf,'color','w');
cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles/Trixaus
tmrcasti = [47,53,60,67,76];
 %load('CTD_MLD.mat', 'cast_isnight')


% % SOUTH 1 
 South1_CTDi = 41:63; 
 Stationi = 41:63;
 %Stationi = Stationi(cast_isnight(Stationi))
 tx = 'SOUTH 1';
 load poc_corrections_south.mat
 cd /Users/roh029/Desktop/Data.nosync/SOLACE/Profiles; load('MLD.mat', 'ctd_mld')
cmap = brewermap(100,'YlGnBU'); cmap=cmap(21:100,:);

% plotting
maxdepth = 130;
thickline =2;
thinline =.5;
lf= 35; tf =25;
ms =10;

% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);


cmap = brewermap(100,'YlGnBU'); cmap=cmap(21:100,:);
cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);


% Carbon Uptake
subplot(2,2,1) 
NPP_9 = interp1(depthS9,CsmS9+CmedS9+ClgS9, 1:100)
NPP_7 = interp1(depthS7,CsmS7+CmedS7+ClgS7, 1:100)
NPP_mean = nanmean([NPP_9;NPP_7]);

xmin =0; xmax = .8;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
h(1)= plot(CsmS7,depthS7,'-*','Color','r','linewidth',3,'markersize',ms); hold on
h(2)=plot(CmedS7,depthS7,'-*','Color','g','linewidth',3,'markersize',ms); hold on
h(3)=plot(ClgS7,depthS7,'-*','Color','b','linewidth',3,'markersize',ms); hold on
h(4)=plot(CsmS7+CmedS7+ClgS7,depthS7,'-*','Color','k','linewidth',3,'markersize',ms); hold on
plot(CsmS9,depthS9,'--*','Color','r','linewidth',3,'markersize',ms); hold on
plot(CmedS9,depthS9,'--*','Color','g','linewidth',3,'markersize',ms); hold on
plot(ClgS9,depthS9,'--*','Color','b','linewidth',3,'markersize',ms); hold on
plot(CsmS9+CmedS9+ClgS9,depthS9,'--*','Color','k','linewidth',3,'markersize',ms); hold on
%plot(NPP_mean,1:100,'-','Color','k','linewidth',3,'markersize',ms); hold on

% mean 


set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Carbon Uptake ($\mu$mol L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)



% Iron Uptake
h= subplot(2,2,2) ;
 pos = get(h, 'Position') 
 posnew = pos; posnew(1) = posnew(1) - 0.04; set(h, 'Position', posnew)


xmin =0; xmax = 40;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
h(1)= plot(FsmS7,depthS7,'-*','Color','r','linewidth',3,'markersize',ms); hold on
h(2)=plot(FmedS7,depthS7,'-*','Color','g','linewidth',3,'markersize',ms); hold on
h(3)=plot(FlgS7,depthS7,'-*','Color','b','linewidth',3,'markersize',ms); hold on
h(4)=plot(FsmS7+FmedS7+FlgS7,depthS7,'-*','Color','k','linewidth',3,'markersize',ms); hold on
plot(FsmS9,depthS9,'--*','Color','r','linewidth',3,'markersize',ms); hold on
plot(FmedS9,depthS9,'--*','Color','g','linewidth',3,'markersize',ms); hold on
plot(FlgS9,depthS9,'--*','Color','b','linewidth',3,'markersize',ms); hold on
plot(FsmS9+FmedS9+FlgS9,depthS9,'--*','Color','k','linewidth',3,'markersize',ms); hold on



set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'$Fe$ Uptake (pmol L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)

cloc = get(gca,'Position');
h= colorbar(gca,'position', [cloc(1)+cloc(3)+.02, cloc(2), .015, cloc(4) ], ...
    'orientation','vertical','TickLabelInterpreter','latex','fontsize',tf);
set(get(h,'ylabel'),'string', 'Days on station','interpreter','latex','fontsize',20)



set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'$Fe$ to $C$ Uptake (pmol:$\mu$mol  L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)

cloc = get(gca,'Position');
h= colorbar(gca,'position', [cloc(1)+cloc(3)+.02, cloc(2), .015, cloc(4) ], ...
    'orientation','vertical','TickLabelInterpreter','latex','fontsize',tf);
set(get(h,'ylabel'),'string', 'Days on station','interpreter','latex','fontsize',20)




% SOUTH 2
South2_CTDi = 64:85;
Stationi = 64:85;
tx = 'SOUTH 2';


% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);


cmap = brewermap(130,'YlGnBU'); cmap=cmap(21:120,:);
cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);


% Carbon Uptake
subplot(2,2,3) 
NPP_11 = interp1(depthS11,CsmS11+CmedS11+ClgS11, 1:100);
NPP_15 = interp1(depthS15,Csum15, 1:100);
NPP_mean = nanmean([NPP_11;NPP_15]);

xmin =0; xmax = 2;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)

h(1)= plot(CsmS11,depthS11,'-*','Color','r','linewidth',3,'markersize',ms); hold on
h(2)=plot(CmedS11,depthS11,'-*','Color','g','linewidth',3,'markersize',ms); hold on
h(3)=plot(ClgS11,depthS11,'-*','Color','b','linewidth',3,'markersize',ms); hold on
h(4)=plot(CsmS11+CmedS11+ClgS11,depthS11,'-*','Color','k','linewidth',3,'markersize',ms); hold on
plot(Csum15,depthS15,'--*','Color','k','linewidth',3,'markersize',ms); hold on
plot(NPP_mean,1:100,'-','Color','k','linewidth',3,'markersize',ms); hold on




set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'Carbon Uptake ($\mu$mol L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)
%legend(h(1:3),'$<$0.2-2.0 $\mu$m', '$<$0.2-20 $\mu$m','All $>$0.2$\mu$m','interpreter','latex','fontsize',14,'location','south') 


% Iron Uptake
h =subplot(2,2,4)  
pos = get(h, 'Position') 
 posnew = pos; posnew(1) = posnew(1) - 0.04; set(h, 'Position', posnew)

xmin =0; xmax = 30;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
h(1)= plot(FsmS11,depthS11,'-*','Color','r','linewidth',3,'markersize',ms); hold on
h(2)=plot(FmedS11,depthS11,'-*','Color','g','linewidth',3,'markersize',ms); hold on
h(3)=plot(FlgS11,depthS11,'-*','Color','b','linewidth',3,'markersize',ms); hold on
h(4)=plot(FsmS11+FmedS7+FlgS11,depthS11,'-*','Color','k','linewidth',3,'markersize',ms); hold on


set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'$Fe$ Uptake (pmol L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)
%legend(h(1:3),'$<$0.2 $\mu$m', '$<$20 $\mu$m','All Sizes','interpreter','latex','fontsize',14,'location','south') 



end




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Supplemental Figs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Disolved and Particulate Iron %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for IronSPlot =1

figure('Units','normalized','Position',[2 2 .8 1])
clc
set(gcf,'color','w');

cmap = brewermap(100,'YlGnBU'); cmap=cmap(21:100,:);
cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);
maxdepth = 600;

subplot(2,2,1)
xmin =0; xmax = .6;
plot(dFe1(~isnan(dFe1)),dFeDepths1(~isnan(dFe1)),'-*','Color','r','linewidth',thickline,'markersize',ms); hold on
plot(PFe1(~isnan(PFe1)),PFeDepths1(~isnan(PFe1)),'-*','Color','k','linewidth',thickline,'markersize',ms); hold on
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$Fe$ (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
legend('dFe','pFe','interpreter','latex','fontsize',lf,'box','off','location','southeast')



subplot(2,2,3)
xmin =0; xmax = .6;
plot(dFe3(~isnan(dFe3)),dFeDepths3(~isnan(dFe3)),'-*','Color','r','linewidth',thickline,'markersize',ms); hold on
plot(PFe3(~isnan(PFe3)),PFeDepths3(~isnan(PFe3)),'-*','Color','k','linewidth',thickline,'markersize',ms); hold on
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$Fe$ (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
legend('dFe','pFe','interpreter','latex','fontsize',lf,'box','off','location','southeast')



subplot(2,2,2)
xmin =0; xmax = .6;
plot(dFe4(~isnan(dFe4)),dFeDepths4(~isnan(dFe4)),'-*','Color','r','linewidth',thickline,'markersize',ms); hold on
plot(PFe4(~isnan(PFe4)),PFeDepths4(~isnan(PFe4)),'-*','Color','k','linewidth',thickline,'markersize',ms); hold on
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$dFe$ (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
legend('Fe','pFe','interpreter','latex','fontsize',lf,'box','off','location','southeast')


subplot(2,2,4)
xmin =0; xmax = .6;
plot(dFe5(~isnan(dFe5)),dFeDepths5(~isnan(dFe5)),'-*','Color','r','linewidth',thickline,'markersize',ms); hold on
plot(PFe5(~isnan(PFe5)),PFeDepths5(~isnan(PFe5)),'-*','Color','k','linewidth',thickline,'markersize',ms); hold on

fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('$dFe$ (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
legend('Fe','pFe','interpreter','latex','fontsize',lf,'box','off','location','southeast')


end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Particulate Phosphate and Particulate Iron %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for IronSPlot =1

figure('Units','normalized','Position',[2 2 2 2])
clc
set(gcf,'color','w');

% Plotting
maxdepth = 600;
thickline =2;
thinline =.5;
lf= 35; tf =25;
ms =10;
xmaxPfe = .5;
xmaxPP  = 120;

% SOUTH 1 
 South1_CTDi = 41:63; 
 Stationi = 41:63;

% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);

ax1 = axes;        % lef   bot  wid  h
set(ax1, 'Position',[.15   .55  .2  .3]);

%ax1 = axes;
plot(PP1(~isnan(PP1)),PFeDepths1(~isnan(PP1)),'-*','Color','r','linewidth',thickline,'markersize',ms); hold on
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1.Box = 'off';
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmaxPP]); 
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Particulate Phosphate (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')

ax2 = axes;        % lef   bot  wid  h
set(ax2, 'Position',[.15   .55  .2 .3]);

plot(PFe1(~isnan(PFe1)),PFeDepths1(~isnan(PFe1)),'-*','Color','k','linewidth',thickline,'markersize',ms); hold on
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmaxPfe]); 
ax2.Box = 'off';
xlabel('Particulate Fe (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')



ax1 = axes;        % lef   bot  wid  h
set(ax1, 'Position',[.15   .1  .2  .3]);

%ax1 = axes;
plot(PP3(~isnan(PP3)),PFeDepths3(~isnan(PP3)),'-*','Color','r','linewidth',thickline,'markersize',ms); hold on
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1.Box = 'off';
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmaxPP]); 
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Particulate Phosphate (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')


ax2 = axes;        % lef   bot  wid  h
set(ax2, 'Position',[.15   .1  .2 .3]);

plot(PFe3(~isnan(PFe3)),PFeDepths3(~isnan(PFe3)),'-*','Color','k','linewidth',thickline,'markersize',ms); hold on
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmaxPfe]); 
ax2.Box = 'off';
xlabel('Particulate Fe (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')



% SOUTH 2
South2_CTDi = 64:85;
Stationi = 64:85;
tx = 'SOUTH 2';


% Mld
mlds_eye  = ctd_mld(Stationi);
mlds_gr  = castmld_dg(Stationi);
mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]);
mldmean = mean(mlds);
mldstd  = std(mlds);




ax1 = axes;        % lef   bot  wid  h
set(ax1, 'Position',[.45   .55  .2  .3]);

plot(PP4(~isnan(PP4)),PFeDepths4(~isnan(PP4)),'-*','Color','r','linewidth',thickline,'markersize',ms); hold on
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1.Box = 'off';
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmaxPP]); 
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Particulate Phosphate (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')


ax2 = axes;        % lef   bot  wid  h
set(ax2, 'Position',[.45   .55  .2  .3]);

plot(PFe4(~isnan(PFe4)),PFeDepths4(~isnan(PFe4)),'-*','Color','k','linewidth',thickline,'markersize',ms); hold on
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmaxPfe]); 
ax2.Box = 'off';
xlabel('Particulate Fe (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')



ax1 = axes;        % lef   bot  wid  h
set(ax1, 'Position',[.45   .1  .2  .3]);

plot(PP5(~isnan(PP5)),PFeDepths5(~isnan(PP5)),'-*','Color','r','linewidth',thickline,'markersize',ms); hold on
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1.Box = 'off';
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmaxPP]); 
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Particulate Phosphate (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')


ax2 = axes;        % lef   bot  wid  h
set(ax2, 'Position',[.45   .1  .2  .3]);

plot(PFe5(~isnan(PFe5)),PFeDepths5(~isnan(PFe5)),'-*','Color','k','linewidth',thickline,'markersize',ms); hold on
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmaxPfe]); 
ax2.Box = 'off';
xlabel('Particulate Fe (nmol kg$^{-1}$)','interpreter','latex','fontsize',lf)
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')

end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Iron to Carbon uptake Ratios %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for Fe2CSPlot =1

figure('Units','normalized','Position',[0 0 1.8 2])
clc
set(gcf,'color','w');

% South 1

h= subplot(1,2,1) ;
 pos = get(h, 'Position') 
 posnew = pos; posnew(1) = posnew(1) - 0.04; set(h, 'Position', posnew)

xmin =0; xmax = 150;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
h(1)= plot(FsmS7./CsmS7,depthS7,'-*','Color','r','linewidth',3,'markersize',ms); hold on
h(2)=plot(FmedS7./CmedS7,depthS7,'-*','Color','g','linewidth',3,'markersize',ms); hold on
h(3)=plot(FlgS7./ClgS7,depthS7,'-*','Color','b','linewidth',3,'markersize',ms); hold on
h(4)=plot((FsmS7+FmedS7+FlgS7)./(CsmS7+CmedS7+ClgS7),depthS7,'-*','Color','k','linewidth',3,'markersize',ms); hold on
plot(FsmS9./CsmS9,depthS9,'--*','Color','r','linewidth',3,'markersize',ms); hold on
plot(FmedS9./CmedS9,depthS9,'--*','Color','g','linewidth',3,'markersize',ms); hold on
plot(FlgS9./ClgS9,depthS9,'--*','Color','b','linewidth',3,'markersize',ms); hold on
plot((FsmS9+FmedS9+FlgS9)./(CsmS9+CmedS9+ClgS9),depthS9,'--*','Color','k','linewidth',3,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'$Fe$ to $C$ Uptake (pmol:$\mu$mol  L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)


% South 2
h =subplot(1,2,2)  
pos = get(h, 'Position') 
 posnew = pos; posnew(1) = posnew(1) - 0.04; set(h, 'Position', posnew)

xmin =0; xmax = 150;
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
h(1)= plot(FsmS11./CsmS11,depthS11,'-*','Color','r','linewidth',3,'markersize',ms); hold on
h(2)=plot(FmedS11./CmedS11,depthS11,'-*','Color','g','linewidth',3,'markersize',ms); hold on
h(3)=plot(FlgS11./ClgS11,depthS11,'-*','Color','b','linewidth',3,'markersize',ms); hold on
h(4)=plot((FsmS11+FmedS7+FlgS11)./(CsmS11+CmedS7+ClgS11),depthS11,'-*','Color','k','linewidth',3,'markersize',ms); hold on

set(gca,'ydir','rev');  
ylim([0,maxdepth])
xlim([xmin,xmax]); 
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel({'$Fe$ to $C$ Uptake (pmol:$\mu$mol  L$^{-1}$ d$^{-1}$)'},'interpreter','latex','fontsize',lf)

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Deep Temperature Profiles %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for DeepTProf =1

figure('Units','normalized','Position',[0 0 1.8 2])
clc
set(gcf,'color','w');

for DeepTempPlots=1
for j = 1:2
subplot(1,2,j)

% plotting
maxdepth = 800;
xmin =.5; xmax = 4.5;
thickline =2;
thinline =.5;
lf= 23; tf =17;

if j==1
 South1_CTDi = 41:63; 
 Stationi = 41:63;
 %Stationi = Stationi(cast_isnight(Stationi))
 tx = '56 $^\circ$ S';
 cmap = brewermap(100,'YlGnBU'); cmap=cmap(21:100,:);
 cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);

elseif j==2
    % % SOUTH 2
South2_CTDi = 64:85;
Stationi = 64:85;
tx = '58 $^\circ$ S';
cmap = brewermap(120,'YlGnBU'); cmap=cmap(21:120,:);
cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);

end

for i = Stationi

% MLD
mlds_eye  = ctd_mld(Stationi); mlds_gr  = castmld_dg(Stationi); mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]); mldmean = mean(mlds); mldstd  = std(mlds);

if i == Stationi(1)
fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)
end
if any(i==tmrcasti)
line(Profiles(i).temp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thickline); hold on
else
line(Profiles(i).temp,Profiles(i).pres,'Color',cmap(cday(i-Stationi(1)+1),:),'linewidth',thinline); hold on
end
xlim([xmin,xmax]);
set(gca,'ydir','rev');  
ylim([0,maxdepth]);
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Temperature ($^\circ$C)','interpreter','latex','fontsize',lf)
title(tx,'interpreter','latex','fontsize',lf) 
end
end


end

end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Silicate Star Plots  %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for SiStar =1
figure('Units','normalized','Position',[2 2 1 1])
clc
set(gcf,'color','w');

for SiStarPlots=1
for j = 1:2
subplot(1,2,j)

% plotting
maxdepth = 300;
xmin =-25; xmax = 10;
thickline =2;
thinline =.5;
lf= 23; tf =17;

if j==1
 South1_CTDi = 41:63; 
 Stationi = 41:63;
 tmrcasti = [47,53,60,67,76];
 %Stationi = Stationi(cast_isnight(Stationi))
 tx = '56 $^\circ$ S';
 cmap = brewermap(100,'YlGnBU'); cmap=cmap(21:100,:);
 cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);

elseif j==2
    % % SOUTH 2
South2_CTDi = 64:85;
Stationi = 64:85;
tmrcasti = [47,53,60,67,76];
tx = '58 $^\circ$ S';
cmap = brewermap(120,'YlGnBU'); cmap=cmap(21:120,:);
cday = casttime_loc(Stationi); cday = cday-cday(1); cday = 1+round(cday*10);

end

for i = Stationi

% MLD
mlds_eye  = ctd_mld(Stationi); mlds_gr  = castmld_dg(Stationi); mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]); mldmean = mean(mlds); mldstd  = std(mlds);


%fill([xmin,xmax,xmax,xmin], [mldmean-mldstd,mldmean-mldstd,mldmean+mldstd,mldmean+mldstd],'k','facealpha',.1,'edgealph',0); hold on
%yline(mldmean,'k','linewidth',1); yline(mldmean-mldstd,'k:','linewidth',.5); yline(mldmean+mldstd,'k:','linewidth',.5)

if j==1
plot(CTD47(~isnan(CTD47(:,4)),4)-CTD47(~isnan(CTD47(:,2)),2),CTD47(~isnan(CTD47(:,4)),1),'-*','Color',cmap(cday(tmrcasti(1)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD53(~isnan(CTD53(:,4)),4)-CTD53(~isnan(CTD53(:,2)),2),CTD53(~isnan(CTD53(:,4)),1),'-*','Color',cmap(cday(tmrcasti(2)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD60(~isnan(CTD60(:,4)),4)-CTD60(~isnan(CTD60(:,2)),2),CTD60(~isnan(CTD60(:,4)),1),'-*','Color',cmap(cday(tmrcasti(3)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
elseif j==2
plot(CTD67(~isnan(CTD67(:,4)),4)-CTD67(~isnan(CTD67(:,2)),2),CTD67(~isnan(CTD67(:,4)),1),'-*','Color',cmap(cday(tmrcasti(4)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
plot(CTD76(~isnan(CTD76(:,4)),4)-CTD76(~isnan(CTD76(:,2)),2),CTD76(~isnan(CTD76(:,4)),1),'-*','Color',cmap(cday(tmrcasti(5)-Stationi(1)+1),:),'linewidth',thickline,'markersize',ms); hold on
end

xline(0, 'linewidth', 2)
xlim([xmin,xmax]);
set(gca,'ydir','rev');  
ylim([0,maxdepth]);
set(gca,'fontsize',tf,'TickLabelInterpreter','latex')
ylabel('Depth (dbar)','interpreter','latex','fontsize',lf)
xlabel('Si$^\star$ ($\mu$mol  L$^{-1}$)','interpreter','latex','fontsize',lf)
title(tx,'interpreter','latex','fontsize',lf) 

end
end


end

end

%%%%%%%%%%%%%%%%%%%%%%%%
%% Grazing Rate Table %%
%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%% 56 S 
% MLD
Stationi = 41:63;
mlds_eye  = ctd_mld(Stationi); mlds_gr  = castmld_dg(Stationi); mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]); mldmean = mean(mlds); mldstd  = std(mlds);

% Discrete Chl
c47 = interp1(dchl47(~isnan(chl47)),chl47(~isnan(chl47)),d);
c53 = interp1(dchl53(~isnan(chl53)),chl53(~isnan(chl53)),d);
c60 = interp1(dchl60(~isnan(chl60)),chl60(~isnan(chl60)),d);
delchl_56 = (c60-c47)./(casttime_loc(tmrcasti(3))-casttime_loc(tmrcasti(1))); %dChl/d
meanchl_56 = nanmean([c47;c53;c60]);

% Discrete NPP
NPP_9 = interp1(depthS9,CsmS9+CmedS9+ClgS9, 1:100)
NPP_7 = interp1(depthS7,CsmS7+CmedS7+ClgS7, 1:100)
NPP_mean = nanmean([NPP_9;NPP_7]);

% Depth Diagnostics
smlchl_56 = nanmean(meanchl_56(d>14.2 & d<(mldmean)));
dcmchl_56 = nanmean(meanchl_56(d>71.4 & d<86.7));
dbmchl_56 = nanmean(meanchl_56(d>80.4 & d<103.3));

d_smlchl_56 = nanmean(delchl_56(d>14.2 & d<(mldmean)));
d_dcmchl_56 = nanmean(delchl_56(d>71.4 & d<86.7));
d_dbmchl_56 = nanmean(delchl_56(d>80.4 & d<103.3));

smlnpp_56 = nanmean(NPP_mean(d>14.2 & d<(mldmean)));
dcmnpp_56 = nanmean(NPP_mean(d>71.4 & d<86.7));
dbmnpp_56 = nanmean(NPP_mean(d>80.4 & d<103.3));

%%%%%%%%%%%%%% 58 S
% MLD
South2_CTDi = 64:85;
mlds_eye  = ctd_mld(Stationi); mlds_gr  = castmld_dg(Stationi); mlds_th  = castmld_dth(Stationi);
mlds = mean([mlds_th;mlds_gr]); mldmean = mean(mlds); mldstd  = std(mlds);

% Discrete Chl
c67 = interp1(dchl67(~isnan(chl67)),chl67(~isnan(chl67)),d);
c76 = interp1(dchl76(~isnan(chl76)),chl76(~isnan(chl76)),d);
meanchl_58 = nanmean([c67;c76]);

% Discrete NPP
NPP_11 = interp1(depthS11,CsmS11+CmedS11+ClgS11, 1:100);
NPP_15 = interp1(depthS15,Csum15, 1:100);
NPP_mean_58 = nanmean([NPP_11;NPP_15]);

% Diagnostics
delchl_58 = (c76-c67)./(casttime_loc(tmrcasti(5))-casttime_loc(tmrcasti(4))); %dChl/d
smlchl_58 = nanmean(meanchl_58(d>10.6 & d<67.7));
dcmchl_58 = nanmean(meanchl_58(d>67.7 & d<82.7));

d_smlchl_58 = nanmean(delchl_58(d>10.6 & d<67.7));
d_dcmchl_58 = nanmean(delchl_58(d>67.7 & d<82.7));

smlnpp_58 = nanmean(NPP_mean_58(d>10.6 & d<67.7));
dcmnpp_58 = nanmean(NPP_mean_58(d>67.7 & d<82.7));

%%%%%%%%%%%%%%%% Rate Calculation %%%%%%%%%%%%%%%%%%%
% Assuptions
%C2Chl   = 30;  % No Photoadaptation (g:g)
C2Chl   = 15;  % Photoadaptation (g:g)
LinLoss = .05;   % Linear loss rate (1/d)
aggLoss = .005;  % Quad loss rate (1/d/mmolm3)

% all samples
npp_all = [smlnpp_56,dcmnpp_56, dbmnpp_56, smlnpp_58, dcmnpp_58];
chl_all = [smlchl_56,dcmchl_56, dbmchl_56, smlchl_58, dcmchl_58];
dchl_dt_all= [d_smlchl_56,d_dcmchl_56, d_dbmchl_56, d_smlchl_58, d_dcmchl_58];
c_all   = chl_all .* C2Chl ./12; % Convert for mg Chl to mmol C
dc_dt_all = dchl_dt_all.* C2Chl ./12; 
u_all = npp_all./c_all;
r_all = dc_dt_all./c_all;
l_all=u_all-r_all;
g_all = l_all - LinLoss.*c_all - aggLoss.*c_all.^2;



%%%%%%%%%%%%%%%%% Statisitical testing %%%%%%%%%%%%%
%%


% data 1
Mean1 = -25; std1 = .2; n1 = 3;
Mean2 = -20; std2 = .3; n2 = 3;

% 2 paired t test
Delta_mean      = abs(Mean1-Mean2); 
df              = n1+n2-2;
pooled_variance = (((n1-1)*std1^2) +((n2-1)*std2^2)) ./ (df);
pooled_std      = sqrt(pooled_variance);
test_stat       = Delta_mean/(pooled_std .* sqrt(1/n1 +1/n2));  % equal variance
p               = 1 - tcdf(test_stat,df)

% use tcdf to test hyptotheis the test statistic 
% https://au.mathworks.com/help/stats/tcdf.html