Functions for field parameterization conversion

Ax[{0,0},ComplexAmplitude]=0;

Ax[{Ex_,Ey_},ComplexAmplitude]:=((Abs[Ex])/(Sqrt[((Abs[Ex])^2)+((Abs[Ey])^2)]))

Ay[{0,0},ComplexAmplitude]=0;

Ay[{Ex_,Ey_},ComplexAmplitude]:=((Abs[Ey])/(Sqrt[((Abs[Ex])^2)+((Abs[Ey])^2)]))

ϕ[{0,Ey_},ComplexAmplitude]=0;
ϕ[{Ex_,0},ComplexAmplitude]=0;

ϕ[{Ex_,Ey_},ComplexAmplitude]:=Arg[(Ey/(Abs[Ey]))((Abs[Ex])/Ex)]

AmplitudePhase[{Ex_,Ey_},ComplexAmplitude]:={Ax[#1,#2],Ay[#1,#2],ϕ[#1,#2]}&[{Ex,Ey},ComplexAmplitude]

S1[{Ax_,Ay_,ϕ_},AmplitudePhase]:=(Ax^2)-(Ay^2)
S2[{Ax_,Ay_,ϕ_},AmplitudePhase]:=2Ax Ay Cos[ϕ]
S3[{Ax_,Ay_,ϕ_},AmplitudePhase]:=2Ax Ay Sin[ϕ]

Stokes[{Ax_,Ay_,ϕ_},AmplitudePhase]:={S1[#1,#2],S2[#1,#2],S3[#1,#2]}&[{Ax,Ay,ϕ},AmplitudePhase]

α[{S1_,S2_,S3_},Stokes]:=(1/2)ArcTan[S1,S2]
ϵ[{S1_,S2_,S3_},Stokes]:=(1/2)ArcSin[S3]

AngleEllipticity[{S1_,S2_,S3_},Stokes]:={α[#1,#2],ϵ[#1,#2]}&[{S1,S2,S3},Stokes]

AngleEllipticity[{Ax_,Ay_,ϕ_},AmplitudePhase]:=AngleEllipticity[Stokes[{Ax,Ay,ϕ},AmplitudePhase],Stokes]

AngleEllipticity[{Ex_,Ey_},ComplexAmplitude]:=AngleEllipticity[AmplitudePhase[{Ex,Ey},ComplexAmplitude],AmplitudePhase]

Read and plot data

SetDirectory[NotebookDirectory[]];
fpDat = OpenRead["Genas_system_mg0.dat",BinaryFormat -> True];
z1Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
z1 = Flatten[BinaryReadList[fpDat, {"Real64"}, z1Len, ByteOrdering->-1]];
t1Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
t1 = Flatten[BinaryReadList[fpDat, {"Real64"}, t1Len, ByteOrdering->-1]];
Exreout1Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
Exreout1 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t1Len, ByteOrdering->-1],{j1,1,z1Len}],{{1},{2,3}}];
Eximout1Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
Eximout1 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t1Len, ByteOrdering->-1],{j1,1,z1Len}],{{1},{2,3}}];
Eyreout1Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
Eyreout1 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t1Len, ByteOrdering->-1],{j1,1,z1Len}],{{1},{2,3}}];
Eyimout1Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
Eyimout1 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t1Len, ByteOrdering->-1],{j1,1,z1Len}],{{1},{2,3}}];
Close[fpDat];
ResetDirectory[];
SetDirectory[NotebookDirectory[]];
fpDat = OpenRead["Genas_system_mg1.dat",BinaryFormat -> True];
z2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
z2 = Flatten[BinaryReadList[fpDat, {"Real64"}, z2Len, ByteOrdering->-1]];
t2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
t2 = Flatten[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1]];
r11out2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r11out2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r22out2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r22out2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r33out2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r33out2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r44out2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r44out2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r12reout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r12reout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r12imout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r12imout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r13reout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r13reout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r13imout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r13imout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r14reout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r14reout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r14imout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r14imout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r23reout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r23reout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r23imout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r23imout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r24reout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r24reout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r24imout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r24imout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r34reout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r34reout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
r34imout2Len = BinaryRead[fpDat, "UnsignedInteger32", ByteOrdering->-1];
r34imout2 = Flatten[Table[BinaryReadList[fpDat, {"Real64"}, t2Len, ByteOrdering->-1],{j1,1,z2Len}],{{1},{2,3}}];
Close[fpDat];
ResetDirectory[];

declaredVariables={"z1", "t1", "Exreout1", "Eximout1", "Eyreout1", "Eyimout1", "z2", "t2", "r11out2", "r22out2", "r33out2", "r44out2", "r12reout2", "r12imout2", "r13reout2", "r13imout2", "r14reout2", "r14imout2", "r23reout2", "r23imout2", "r24reout2", "r24imout2", "r34reout2", "r34imout2"}

Exout1=Exreout1+I Eximout1;
Eyout1=Eyreout1+I Eyimout1;
ListAnimate@Table[
intens=.5 (10^(-7))Abs[#]&/@Transpose@{Exout1[[All,i]],Eyout1[[All,i]]};
mask=If[#<.1,Null,1]&/@intens[[All,1]];
alep=AngleEllipticity[#,ComplexAmplitude]&/@Transpose@{Exout1[[All,i]],Eyout1[[All,i]]};ListLinePlot[{Transpose[{z1,mask alep[[All,1]]}],Transpose[{z1,intens[[All,1]]}]},PlotRange->{-π/2,π/2}],{i,1,Length[t1],1}]