-
Notifications
You must be signed in to change notification settings - Fork 10
/
pyroxene_fe3_HP.m
890 lines (748 loc) · 29.2 KB
/
pyroxene_fe3_HP.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
%Clinopyroxene structural formula with Fe3+ estimation
%site assignment and endmember calculation after Harlow (1999)
function [StrctFrm, APFU]=pyroxene_fe3_HP(data,headers,wantstrctfrm)
[m,n]=size(data); %finds the x and y size of the input data matrix
%finds the column position oxide headers in any order to assign data to the correct array
%positions
I(1,1)=find(strcmp(headers,'SiO2'));
%Makes TiO2 optional
if strcmp(headers,'TiO2')==zeros(1,length(headers))
I(1,2)=0;
else
I(1,2)=find(strcmp(headers,'TiO2'));
end
I(1,3)=find(strcmp(headers,'Al2O3'));
%Makes Cr2O3 optional
if strcmp(headers,'Cr2O3')==zeros(1,length(headers))
I(1,4)=0;
else
I(1,4)=find(strcmp(headers,'Cr2O3'));
end
I(1,5)=find(strcmp(headers,'FeO'));
I(1,6)=find(strcmp(headers,'MnO'));
I(1,7)=find(strcmp(headers,'MgO'));
I(1,8)=find(strcmp(headers,'CaO'));
%Makes Na2O optional
if strcmp(headers,'Na2O')==zeros(1,length(headers))
I(1,9)=0;
else
I(1,9)=find(strcmp(headers,'Na2O'));
end
%Makes K2O optional
if strcmp(headers,'K2O')==zeros(1,length(headers))
I(1,10)=0;
else
I(1,10)=find(strcmp(headers,'K2O'));
end
cat=4.0; %cations per formula unit
Opfu=6.0; %oxygens per formula unit
%% Molecular weights
SiO2=60.083;
TiO2=79.865;
Al2O3=101.961;
Cr2O3=151.989;
Fe2O3=159.6874;
Y2O3=225.809;
NiO=74.692;
ZnO=81.381;
FeO=71.8442;
MnO=70.937;
MgO=40.304;
CaO=56.0774;
Na2O=61.979;
K2O=94.195;
BaO=153.329;
F=18.998;
Cl=35.45;
W=[SiO2,TiO2,Al2O3,Cr2O3,FeO,MnO,MgO,CaO,Na2O,K2O];
%% Calculate cations units
MC(:,1)=data(:,I(1,1))./W(:,1); %for SiO2
%calculates for TiO2 if it is included in the analysis
if I(1,2)==0
MC(:,2)=zeros(m,1);
else
MC(:,2)=data(:,I(1,2))./W(:,2); %for TiO2
end
MC(:,3)=(data(:,I(1,3))./W(:,3)).*2; %for Al2O3
%calculates for Cr2O3 if it is included in the analysis
if I(1,4)==0
MC(:,4)=zeros(m,1);
else
MC(:,4)=(data(:,I(1,4))./W(:,4)).*2; %for Cr2O3
end
MC(:,5)=data(:,I(1,5))./W(:,5); %for FeO
MC(:,6)=data(:,I(1,6))./W(:,6); %for MnO
MC(:,7)=data(:,I(1,7))./W(:,7); %for MgO
MC(:,8)=data(:,I(1,8))./W(:,8); %for CaO
%calculates for K2O if it is included in the analysis
if I(1,9)==0
MC(:,9)=zeros(m,1);
else
MC(:,9)=(data(:,I(1,9))./W(:,9)).*2; %for Na2O
end
%calculates for K2O if it is included in the analysis
if I(1,10)==0
MC(:,10)=zeros(m,1);
else
MC(:,10)=(data(:,I(1,10))./W(:,10)).*2; %for K2O
end
MCnormfact=cat./sum(MC,2); %normalization factor
%% Calculate normalized cations units
MCnorm=MCnormfact.*MC; %creates a matrix of normalized cations
%% Calculate Oxygen Units
O2(:,1)=MCnorm(:,1).*2; %for SiO2
O2(:,2)=MCnorm(:,2).*2; %for TiO2
O2(:,3)=MCnorm(:,3).*(3/2); %for Al2O3
O2(:,4)=MCnorm(:,4).*(3/2); %for Cr2O3
O2(:,5)=MCnorm(:,5); %for FeO
O2(:,6)=MCnorm(:,6); %for MnO
O2(:,7)=MCnorm(:,7); %for MgO
O2(:,8)=MCnorm(:,8); %for CaO
O2(:,9)=MCnorm(:,9)./2; %for Na2O
O2(:,10)=MCnorm(:,10)./2; %for K2O
O2total=sum(O2,2); %O2 totals
%% Atoms pfu
APFU(:,1)=MCnorm(:,1); %for Si
APFU(:,2)=MCnorm(:,2); %for Ti
APFU(:,3)=MCnorm(:,3); %for Al
APFU(:,5)=MCnorm(:,4); %for Cr
APFU(:,7)=MCnorm(:,6); %for Mn
APFU(:,8)=MCnorm(:,7); %for Mg
APFU(:,9)=MCnorm(:,8); %for Ca
APFU(:,10)=MCnorm(:,9); %for Na
APFU(:,11)=MCnorm(:,10); %for K
%calculation of Fe3+ from stoichiometry and charge balance
%the following if statement firsts checks if totalO2 = 6
%if so, then there is no Fe3+
%if totalO2 < 6, then we assume that the deficiency is caused by the
%assumption Fetotal = Fe2+
%in the nested if statement, if FeTotal > 2*(6-totalO2) then the amount
%of Fe3+ = 2*(6-totalO2), if false then, all Fe is Fe3+
for c=1:m
if (Opfu-O2total(c,1)) > 0
if MCnorm(c,5) > 2.*(Opfu-O2total(c,1))
APFU(c,4)=2.*(Opfu-O2total(c,1));
else
APFU(c,4)=MCnorm(c,5);
end
else
APFU(c,4)=0;
end
end
APFU(:,6)=MCnorm(:,5)-APFU(:,4); %the APFU of Fe2+ = totalFe-Fe3+
APFU(:,12)=sum(APFU,2); %calculations the total, which should be 4
% Oxygen deficiency
APFU(:,13)=Opfu-O2total; %must be greater than zero
%XMg
XMg=APFU(:,8)./(APFU(:,8)+APFU(:,6));
%% structural formula calculation
%T SITE
%Si
for c=1:m
if APFU(c,1)<2.000
StrctFrm(c,1)=APFU(c,1); %If Si < 2, then Si(T) = the measured Si content
else
StrctFrm(c,1)=2; %If Si is in excess, then Si(T) = 2
end
end
%Al(T)
for c=1:m
if 2-StrctFrm(c,1)>0 %Is 2-Si > 0? If y, then some Al goes into T
if 2-StrctFrm(c,1)>APFU(c,3) %For low Al cpx, 2-Si may be > Al
StrctFrm(c,2)=APFU(c,3); %All Al goes into T
else
StrctFrm(c,2)=2-StrctFrm(c,1); %if there isn't enough space in T for all Al, the rest will go to M1
end
else
StrctFrm(c,2)=0; %if Si=2, then no Al goes into T
end
end
%Fe3+(T)
for c=1:m
if 2-StrctFrm(c,1)-StrctFrm(c,2)>0 %Is 2-(Si+Al) > 0? If y, then some Fe3+ goes into T
if 2-StrctFrm(c,1)-StrctFrm(c,2)>APFU(c,4) %For low Fe3+ cpx, 2-(Si+Al) may be > Fe3+
StrctFrm(c,3)=APFU(c,4); %All Fe3+ goes into T
else
StrctFrm(c,3)=2-StrctFrm(c,1)-StrctFrm(c,2); %if there isn't enough space in T for all Fe3+, the rest will go to M1
end
else
StrctFrm(c,3)=0; %if Si+Al=2, then no Fe3+ goes into T
end
end
%Sum of T site
StrctFrm(:,4)=StrctFrm(:,1)+StrctFrm(:,2)+StrctFrm(:,3); %Si + Al + Fe3+ in T
%M1 SITE
%Si (M1)
for c=1:m
if APFU(c,1)>2.000
StrctFrm(c,5)=APFU(c,1)-2; %If Si > 2, then some Si goes into M1
else
StrctFrm(c,5)=0; %If Si is in excess, then Si(T) = 2
end
end
%Al(M1)
StrctFrm(:,6)=APFU(:,3)-StrctFrm(:,2); %Al(M1) = Total Al - Al(T)
%Ti (M1)
StrctFrm(:,7)=APFU(:,2);
%Fe3+ (M1)
StrctFrm(:,9)=APFU(:,4)-StrctFrm(:,3); %Fe3+(M1) = Total Fe3+ - Fe3+(T)
%Cr3+ (M1)
StrctFrm(:,8)=APFU(:,5);
%Mn (M1)
StrctFrm(:,10)=APFU(:,7);
%Mg (M1)
for c=1:m
if 1-(StrctFrm(c,5)+StrctFrm(c,6)+StrctFrm(c,7)+StrctFrm(c,8)+StrctFrm(c,9)+StrctFrm(c,10))>0 %Is 1-Sum(Al to Mn) in M1 >0?, if yes then:
if XMg(c).*(1-StrctFrm(c,5)-StrctFrm(c,6)-StrctFrm(c,7)-StrctFrm(c,8)-StrctFrm(c,9)-StrctFrm(c,10))<APFU(c,8) %if XMg*(1-Sum(Al to Mn)) is < Mg
StrctFrm(c,11)=XMg(c).*(1-StrctFrm(c,5)-StrctFrm(c,6)-StrctFrm(c,7)-StrctFrm(c,8)-StrctFrm(c,9)-StrctFrm(c,10)); %then Mg(M1)=XMg*(1-Sum(Al to Mn) in M1) and some Mg goes into M2
else
StrctFrm(c,11)=APFU(c,8); %if not, all Mg goes into M1
end
else
StrctFrm(c,11)=0; %If M1 is already filled, then no Mg2+ goes into M1
end
end
%Fe2+ (M1)
for c=1:m
if 1-(StrctFrm(c,5)+StrctFrm(c,6)+StrctFrm(c,7)+StrctFrm(c,8)+StrctFrm(c,9)+StrctFrm(c,10))>0 %Is 1-Sum(Al to Mn) in M1 >0?, if yes then:
if (1-StrctFrm(c,5)-StrctFrm(c,6)-StrctFrm(c,7)-StrctFrm(c,8)-StrctFrm(c,9)-StrctFrm(c,10)-StrctFrm(c,11))>APFU(c,6) %Is 1-Sum(Al to Mg) in M1 > Fe2+?, if yes then:
StrctFrm(c,12)=APFU(c,6); %all Fe2+ goes into M1
else
StrctFrm(c,12)=1-StrctFrm(c,5)-StrctFrm(c,6)-StrctFrm(c,7)-StrctFrm(c,8)-StrctFrm(c,9)-StrctFrm(c,10)-StrctFrm(c,11); %if there isn't enough space in M1 for all Fe2+, some goes into M2
end
else
StrctFrm(c,12)=0; %If M1 is already filled, then no Fe2+ goes into M1
end
end
%Sum of M1 site
StrctFrm(:,13)=StrctFrm(:,5)+StrctFrm(:,6)+StrctFrm(:,7)+StrctFrm(:,8)+StrctFrm(:,9)+StrctFrm(:,10)+StrctFrm(:,11)+StrctFrm(:,12);
%M2 SITE
%Mg (M2)
for c=1:m
if APFU(c,8)-StrctFrm(c,11)>0 %Is Mgtotal-Mg(M1) > 0?
StrctFrm(c,14)=APFU(c,8)-StrctFrm(c,11); %if yes, then some Mg goes into M2
else
StrctFrm(c,14)=0; %if no, then all Mg is in M1
end
end
%Fe2+ (M2)
for c=1:m
if APFU(c,6)-StrctFrm(c,12)>0 %Is Fe2+total-Fe2+(M1) > 0?
StrctFrm(c,15)=APFU(c,6)-StrctFrm(c,12); %if yes, then some Fe2+ goes into M2
else
StrctFrm(c,15)=0; %if no, then all Fe2+ is in M1
end
end
%Ca (M2)
StrctFrm(:,16)=APFU(:,9);
%Na (M2)
StrctFrm(:,17)=APFU(:,10);
%K (M2)
StrctFrm(:,18)=APFU(:,11);
%Sum of M2 site
StrctFrm(:,19)=StrctFrm(:,14)+StrctFrm(:,15)+StrctFrm(:,16)+StrctFrm(:,17)+StrctFrm(:,18);
%% end member calculations
%only do endmember calculation if structural formula with endembers is selected
if strcmp(wantstrctfrm, 'y')
%endmembers after Harlow (1999)
z=APFU(:,10)+APFU(:,11); %Na + K
s2=StrctFrm(:,5); %excess Si
M3=APFU(:,5)+2.*(s2+APFU(:,2))+APFU(:,4)+(StrctFrm(:,6)-StrctFrm(:,2)); %M3 = Cr + 2*(s2+Ti)+ Fe3+ + (viAl-ivAl)
%M3 - (Na + K)
for c=1:m
if (M3(c,1)-(APFU(c,10)+APFU(c,11)))>0
e(c,1)=M3(c,1)-(APFU(c,10)+APFU(c,11));
else
e(c,1)=0; %corrects negative value to 0
end
end
%ivAl - Ti
for c=1:m
if (StrctFrm(c,2)-APFU(c,2))>0
A1n(c,1)=StrctFrm(c,2)-APFU(c,2);
else
A1n(c,1)=0; %corrects negative value to 0
end
end
%Na-Ti
for c=1:m
if (APFU(c,10)-APFU(c,2))>0
Na2(c,1)=APFU(c,10)-APFU(c,2);
else
Na2(c,1)=0; %corrects negative value to 0
end
end
%Na+K-Ti
for c=1:m
if (APFU(c,10)+APFU(c,11)-APFU(c,2))>0
zp(c,1)=APFU(c,10)+APFU(c,11)-APFU(c,2);
else
zp(c,1)=0; %corrects negative value to 0
end
end
%viAl - (ivAl - Ti)
for c=1:m
if (StrctFrm(c,6)-A1n(c,1))>0
A3n(c,1)=StrctFrm(c,6)-A1n(c,1);
else
A3n(c,1)=0; %corrects negative value to 0
end
end
for c=1:m
if (StrctFrm(c,6)-A1n(c,1))<0
F3n(c,1)=APFU(c,4)+(StrctFrm(c,6)-A1n(c,1)); %Fe3+ + (viAl - (ivAl - Ti))
else
F3n(c,1)=APFU(c,4); %Fe3+
end
end
%g = Ca - 0.5*(Cr + 2*(s2+Ti)+ Fe3+ + Al - Na - K)-(ivAl - Ti)
for c=1:m
if (APFU(c,9)-(e(c,1)./2)-A1n(c,1))>0
g(c,1)=(APFU(c,9)-(e(c,1)./2)-A1n(c,1));
else
g(c,1)=0; %corrects negative numbers to zero
end
end
%Diopside
for c=1:m
if g(c,1)>APFU(c,8) %if g > Mg
Di(c,1)=APFU(c,8); %XDi = Mg (APFU)
else
Di(c,1)=g(c,1);
end
end
%Hedenbergite
for c=1:m
if Di(c,1)==APFU(c,8)
Hd(c,1)=g(c,1)-Di(c,1);
else
Hd(c,1)=0;
end
end
%h=(Mg+Mn+Fe2+ - g2)/2
h=(APFU(:,8)+APFU(:,7)+APFU(:,6)-g(:,1))./2;
%Jadeite
for c=1:m
if A3n(c,1)>zp(c,1)
Jd(c,1)=zp(c,1);
else
Jd(c,1)=A3n(c,1);
end
end
for c=1:m
if zp(c,1)-A3n(c,1)<0
zm(c,1)=0;
else
zm(c,1)=zp(c,1)-A3n(c,1);
end
end
%Kosmochlor
for c=1:m
if APFU(c,5)>zm(c,1)
Ko(c,1)=zm(c,1);
else
Ko(c,1)=APFU(c,5);
end
end
%zl = zm - Cr
for c=1:m
if (zm(c,1)-APFU(c,5))<0
zk(c,1)=0;
else
zk(c,1)=zm(c,1)-APFU(c,5);
end
end
%aegerine
for c=1:m
if APFU(c,4)>zk(c,1)
XAeg(c,1)=zk(c,1);
else
XAeg(c,1)=APFU(c,4);
end
end
kcpx=APFU(:,11);
%XJd
for c=1:m
if kcpx(c,1)-Ko(c,1)<0
XJd(c,1)=Jd(c,1)-kcpx(c,1);
else
XJd(c,1)=Jd(c,1);
end
end
XDiHd=g(:,1);
XCaTs=A1n(:,1);
%XKos
for c=1:m
if Jd(c,1)-kcpx(c,1)<0
XKo(c,1)=Ko(c,1)-kcpx(c,1);
else
XKo(c,1)=Ko(c,1);
end
end
%XK-Ko
for c=1:m
if Jd(c,1)-kcpx(c,1)<0
XKKo(c,1)=kcpx(c,1);
else
XKKo(c,1)=0;
end
end
%XK-Jd
for c=1:m
if Ko(c,1)-kcpx(c,1)<0
XKJd(c,1)=kcpx(c,1);
else
XKJd(c,1)=0;
end
end
%XTi-Cpx
XTiCpx=APFU(:,2); %equal to Ti APFU
XCaEs=e(:,1);
for c=1:m
if h(c,1)>0
XEn(c,1)=h(c,1);
else
XEn(c,1)=0;
end
end
%put endmembers into single matrix
Endmembers(:,1)=XJd(:,1);
Endmembers(:,2)=XAeg(:,1);
Endmembers(:,3)=XDiHd(:,1);
Endmembers(:,4)=XCaTs(:,1);
Endmembers(:,5)=XKo(:,1);
Endmembers(:,6)=XKKo(:,1);
Endmembers(:,7)=XKJd(:,1);
Endmembers(:,8)=XTiCpx(:,1);
Endmembers(:,9)=XCaEs(:,1);
Endmembers(:,10)=XEn(:,1);
ENF=1./sum(Endmembers,2);
Endmembers=ENF.*Endmembers;
EnWoFs(:,1)=(APFU(:,8)./(APFU(:,9)+APFU(:,6)+APFU(:,8)+APFU(:,7)+APFU(:,4))); % XEn
EnWoFs(:,2)=(APFU(:,9)./(APFU(:,9)+APFU(:,6)+APFU(:,8)+APFU(:,7)+APFU(:,4))); % XWo
EnWoFs(:,3)=((APFU(:,6)+APFU(:,7)+APFU(:,4))./(APFU(:,9)+APFU(:,6)+APFU(:,8)+APFU(:,7)+APFU(:,4))); % XFs
%prompts the user if they wish to plot the CPX data
prompt2='Do you wish to plot clinopyroxene compositions? (y|n): ';
wantplots=input(prompt2, 's');
if strcmp(wantplots, 'y')
%prompts the user to determine which symbols to use
prompt3='What symbols do you want to use?:';
disp('Options are (CASE SENSITIVE): circle, square, diamond, and triangle.') %for simplicity only 4 options are available
wantsymbols=input(prompt3,'s');
%assigns the variable the appropriate symbol marker
if strcmp(wantsymbols,'circle')
symb='o';
end
if strcmp(wantsymbols,'square')
symb='s';
end
if strcmp(wantsymbols,'diamond')
symb='d';
end
if strcmp(wantsymbols,'triangle')
symb='^';
end
%prompts the user to determine which symbol fill color to use
prompt4='Specify the fill color:';
disp('Options are (CASE SENSITIVE): blue, orange, yellow, purple, green, cyan, & red.')
wantfil=input(prompt4,'s');
%assigns the variable the appropriate fill color
if strcmp(wantfil,'blue')
fil=[0 0.4470 0.7410];
end
if strcmp(wantfil,'orange')
fil=[0.8500 0.3250 0.0980];
end
if strcmp(wantfil,'yellow')
fil=[0.9290 0.6940 0.1250];
end
if strcmp(wantfil,'purple')
fil=[0.4940 0.1840 0.5560];
end
if strcmp(wantfil,'green')
fil=[0.4660 0.6740 0.1880];
end
if strcmp(wantfil,'cyan')
fil=[0.3010 0.7450 0.9330];
end
if strcmp(wantfil,'red')
fil=[0.6350 0.0780 0.1840];
end
%prompts the user to determine which symbol fill color to use
prompt5='Specify symbol size (numeric scalar):';
disp('Note: Between 50 & 200 is good for most applications.')
symbsize=input(prompt5);
%Q-J diagram
figure('Name','Q-J Diagram')
plot([0 2],[2 0],'k','linewidth',1.5)
hold on
plot([0 1.5],[1.5 0],'k','linewidth',1.5)
hold on
plot([0.3 0.4],[1.2 1.6],'k','linewidth',1.5)
hold on
plot([1.2 1.6],[0.3 0.4],'k','linewidth',1.5)
hold on
Y3=APFU(:,8)+APFU(:,6)+APFU(:,9);
X3=APFU(:,10).*2;
scatter(X3(:),Y3(:),symbsize,symb,'filled','MarkerFaceAlpha',3/8,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',fil)
hold off
text(0.25,1.8,'Quad','FontSize',12)
text(1.05,1,'Ca-Na','FontSize',12)
text(1.85,0.2,'Na','FontSize',12)
xlabel('J=2Na')
ylabel('Q=(Ca+Mg+Fe^{2+})')
%plots a ternary for Ca-Mg-Fe pyroxenes
figure('Name','Ca-Mg-Fe Pyroxenes')
%plot a grid intervals of 0.2 for different endmembers
pgon=polyshape([0 0.5 1],[0 sqrt(3)/2 0]);
plot(pgon,'FaceColor','w')
hold on
%plot grid (spacing of 10 %)
plot([0.45 0.55], [0.779422863 0.779422863],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.9
hold on
plot([0.4 0.6], [0.692820323 0.692820323],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XWo=0.8
hold on
plot([0.35 0.65], [0.606217783 0.606217783],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.7
hold on
plot([0.3 0.7], [0.519615242 0.519615242],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XWo=0.6
hold on
plot([0.25 0.75], [0.433012702 0.433012702],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.5
hold on
plot([0.2 0.8], [0.346410162 0.346410162],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XWo=0.4
hold on
plot([0.15 0.85], [0.259807621 0.259807621],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.3
hold on
plot([0.1 0.9], [0.173205081 0.173205081],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XWo=0.2
hold on
plot([0.05 0.95], [0.08660254 0.08660254],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.1
hold on
plot([0.05 0.1], [0.08660254 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.9
hold on
plot([0.1 0.2], [0.173205081 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XEn=0.8
hold on
plot([0.15 0.3], [0.259807621 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.7
hold on
plot([0.2 0.4], [0.346410162 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XEn=0.6
hold on
plot([0.25 0.5], [0.433012702 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.5
hold on
plot([0.3 0.6], [0.519615242 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XEn=0.4
hold on
plot([0.35 0.7], [0.606217783 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.3
hold on
plot([0.4 0.8], [0.692820323 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XEn=0.2
hold on
plot([0.45 0.9], [0.779422863 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.1
hold on
plot([0.95 0.9], [0.08660254 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.9
hold on
plot([0.9 0.8], [0.173205081 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XFs=0.8
hold on
plot([0.85 0.7], [0.259807621 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.7
hold on
plot([0.8 0.6], [0.346410162 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XFs=0.6
hold on
plot([0.75 0.5], [0.433012702 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.5
hold on
plot([0.7 0.4], [0.519615242 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XFs=0.4
hold on
plot([0.65 0.3], [0.606217783 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.3
hold on
plot([0.6 0.2], [0.692820323 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XFs=0.2
hold on
plot([0.55 0.1], [0.779422863 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.1
hold on
%plot boundaries of the triangle
plot([0 1],[0 0],'k','linewidth',1.5)
hold on
plot([0 0.5],[0 sqrt(3)/2],'k','linewidth',1.5)
hold on
plot([0.5 1],[sqrt(3)/2 0],'k','linewidth',1.5)
hold on
%plot mineral compositional fields
plot([0.25 0.75],[0.4330127 0.4330127],'k','linewidth',1.5)
hold on
plot([0.225 0.775],[0.38971143 0.38971143],'k','linewidth',1.5)
hold on
plot([0.1 0.9],[0.17320508 0.17320508],'k','linewidth',1.5)
hold on
plot([0.025 0.975],[0.04330127 0.04330127],'k','linewidth',1.5)
hold on
plot([0.5 0.5],[0.38971143 0.4330127],'k','linewidth',1.5)
hold on
plot([0.5 0.5],[0 0.04330127],'k','linewidth',1.5)
hold on
%labels
text(-0.10,0.0,'en','FontSize',14)
text(0.51,0.92,'wo','FontSize',14)
text(1.02,-0.04,'fs','FontSize',14)
text(0.20,0.02,'Enstatite','FontSize',12)
text(0.65,0.02,'Ferrosilite','FontSize',12)
text(0.425,0.1,'Pigeonite','FontSize',12)
text(0.45,0.28,'Augite','FontSize',12)
text(0.29,0.412,'Diopside','FontSize',12)
text(0.52,0.412,'Hedenbergite','FontSize',12)
%tick labels
text(-0.02,-0.039,'0.0','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.18,-0.039,'0.2','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.38,-0.039,'0.4','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.58,-0.039,'0.6','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.78,-0.039,'0.8','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.98,-0.039,'1.0','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(1.02,0.01,'0.0','FontSize',12)
text(0.92,0.18,'0.2','FontSize',12)
text(0.82,0.35,'0.4','FontSize',12)
text(0.72,0.52,'0.6','FontSize',12)
text(0.62,0.70,'0.8','FontSize',12)
text(0.52,0.87,'1.0','FontSize',12)
text(-0.025,0.040,'1.0','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.075,0.215,'0.8','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.178,0.386,'0.6','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.278,0.558,'0.4','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.382,0.735,'0.2','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.482,0.901,'0.0','FontSize',12,'HorizontalAlignment','center','Rotation',300)
%transforms the data to ternary space
X2=0.5.*(EnWoFs(:,2))+(EnWoFs(:,3));
Y2=(EnWoFs(:,2))*(cos(30*pi()/180));
scatter(X2(:),Y2(:),symbsize,symb,'filled','MarkerFaceAlpha',3/8,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',fil)
hold off
axis image
axis off
%plots a ternary figure for sodic-calcic pyroxenes
figure('Name','Sodic-Calcic Pyroxenes');
pgon=polyshape([0 0.5 1],[0 sqrt(3)/2 0]);
plot(pgon,'FaceColor','w')
hold on
plot([0.45 0.55], [0.779422863 0.779422863],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.9
hold on
plot([0.4 0.6], [0.692820323 0.692820323],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XWo=0.8
hold on
plot([0.35 0.65], [0.606217783 0.606217783],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.7
hold on
plot([0.3 0.7], [0.519615242 0.519615242],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XWo=0.6
hold on
plot([0.25 0.75], [0.433012702 0.433012702],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.5
hold on
plot([0.2 0.8], [0.346410162 0.346410162],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XWo=0.4
hold on
plot([0.15 0.85], [0.259807621 0.259807621],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.3
hold on
plot([0.1 0.9], [0.173205081 0.173205081],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XWo=0.2
hold on
plot([0.05 0.95], [0.08660254 0.08660254],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XWo=0.1
hold on
plot([0.05 0.1], [0.08660254 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.9
hold on
plot([0.1 0.2], [0.173205081 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XEn=0.8
hold on
plot([0.15 0.3], [0.259807621 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.7
hold on
plot([0.2 0.4], [0.346410162 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XEn=0.6
hold on
plot([0.25 0.5], [0.433012702 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.5
hold on
plot([0.3 0.6], [0.519615242 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XEn=0.4
hold on
plot([0.35 0.7], [0.606217783 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.3
hold on
plot([0.4 0.8], [0.692820323 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XEn=0.2
hold on
plot([0.45 0.9], [0.779422863 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XEn=0.1
hold on
plot([0.95 0.9], [0.08660254 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.9
hold on
plot([0.9 0.8], [0.173205081 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XFs=0.8
hold on
plot([0.85 0.7], [0.259807621 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.7
hold on
plot([0.8 0.6], [0.346410162 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XFs=0.6
hold on
plot([0.75 0.5], [0.433012702 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.5
hold on
plot([0.7 0.4], [0.519615242 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XFs=0.4
hold on
plot([0.65 0.3], [0.606217783 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.3
hold on
plot([0.6 0.2], [0.692820323 0],'color',[0.3 0.3 0.3],'LineStyle','--','linewidth',0.5) %XFs=0.2
hold on
plot([0.55 0.1], [0.779422863 0],'color',[0.3 0.3 0.3],'LineStyle',':','linewidth',0.5) %XFs=0.1
hold on
plot([0 1],[0 0],'k','linewidth',1.5)
hold on
plot([0 0.5],[0 sqrt(3)/2],'k','linewidth',1.5)
hold on
plot([0.5 1],[sqrt(3)/2 0],'k','linewidth',1.5)
hold on
plot([0.4 0.6],[0.69282032 0.69282032],'k','linewidth',1.5)
hold on
plot([0.1 0.9],[0.17320508 0.17320508],'k','linewidth',1.5)
hold on
plot([0.5 0.5],[0 0.69282032],'k','linewidth',1.5)
hold on
%labels
text(-0.10,0.0,'jd','FontSize',14)
text(0.52,0.92,'Quad','FontSize',14)
text(1.02,-0.04,'aeg','FontSize',14)
text(0.20,0.09,'Jadeite','FontSize',12)
text(0.66,0.09,'Aegirine','FontSize',12)
text(0.26,0.35,'Omphacite','FontSize',12)
text(0.58,0.37,'Aegirine-','FontSize',12)
text(0.60,0.33,'Augite','FontSize',12)
%tick labels
text(-0.02,-0.039,'0.0','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.18,-0.039,'0.2','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.38,-0.039,'0.4','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.58,-0.039,'0.6','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.78,-0.039,'0.8','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(0.98,-0.039,'1.0','FontSize',12,'HorizontalAlignment','center','Rotation',60)
text(1.02,0.01,'0.0','FontSize',12)
text(0.92,0.18,'0.2','FontSize',12)
text(0.82,0.35,'0.4','FontSize',12)
text(0.72,0.52,'0.6','FontSize',12)
text(0.62,0.70,'0.8','FontSize',12)
text(0.52,0.87,'1.0','FontSize',12)
text(-0.025,0.040,'1.0','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.075,0.215,'0.8','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.178,0.386,'0.6','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.278,0.558,'0.4','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.382,0.735,'0.2','FontSize',12,'HorizontalAlignment','center','Rotation',300)
text(0.482,0.901,'0.0','FontSize',12,'HorizontalAlignment','center','Rotation',300)
XQuad=(Endmembers(:,3)+Endmembers(:,10))./(Endmembers(:,3)+Endmembers(:,10)+Endmembers(:,1)+Endmembers(:,2)); %(En+Hd+Di)/(En+Hd+Di+Jd+Aeg)
XAeg2=Endmembers(:,2)./(Endmembers(:,3)+Endmembers(:,10)+Endmembers(:,1)+Endmembers(:,2)); %Aeg/(En+Hd+Di+Jd+Aeg)
%transforms the data to ternary space
X1=0.5.*(XQuad)+(XAeg2);
Y1=(XQuad)*(cos(30*pi()/180));
scatter(X1(:),Y1(:),symbsize,symb,'filled','MarkerFaceAlpha',3/8,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',fil)
hold off
axis image
axis off
figure('Name','cats vs. caes Plot')
scatter(XCaEs,XCaTs,symbsize,symb,'filled','MarkerFaceAlpha',3/8,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',fil)
xlabel('X_{caes}','FontSize',12)
ylabel('X_{cats}','FontSize',12)
%set axis font size to 12
ax=gca;
ax.FontSize=12;
axis equal %makes the spacing of the axes intervals equal
ax.Box = 'on';
xlim([0 0.5])
ylim([0 0.5])
figure('Name','K-cpx vs. caes Plot')
KCpx=Endmembers(:,6)+Endmembers(:,7);
scatter(KCpx,XCaEs,symbsize,symb,'filled','MarkerFaceAlpha',3/8,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',fil)
xlabel('X_{K-cpx}','FontSize',12)
ylabel('X_{caes}','FontSize',12)
%set axis font size to 12
ax=gca;
ax.FontSize=12;
axis equal %makes the spacing of the axes intervals equal
ax.Box = 'on';
xlim([0 0.3])
ylim([0 0.3])
end
all=[StrctFrm Endmembers APFU(:,13)];
StrctFrm=array2table(all,'VariableNames',{'Si_T','Al_T','Fe3_T','Sum_T','Si_M1','Al_M1','Ti_M1','Cr_M1','Fe3_M1','Mn_M1','Mg_M1','Fe2_M1','Sum_M1','Mg_M2','Fe2_M2','Ca_M2','Na_M2','K_M2','Sum_M2','Xjd','Xaeg','Xdihd','Xcats','Xkos','XK_kos','XK_jd','XTi_cpx','Xcaes','Xen','O2_deficiency'});
else
APFU=array2table(APFU,'VariableNames',{'Si','Ti','Al','Fe3','Cr','Fe2','Mn','Mg','Ca','Na','K','Sum','O2_deficiency'});
end
end