AppendTo[$Path,"~/RHPackage"];

Quiet[<<RiemannHilbert`];

ParallelEvaluate[AppendTo[$Path,"~/RHPackage"];];
ParallelEvaluate[Quiet[<<RiemannHilbert`;]];

l = 10;
q0[x_]:=Exp[-x^2+I x];
lfun = Fun[q0,Line[{-l,0}]]
rfun = Fun[q0,Line[{0,l}]]
Dl= DerivativeMatrix[lfun];
Dr=DerivativeMatrix[rfun];

DomainIntegrate[lfun]+DomainIntegrate[rfun]

NIntegrate[q0[x],{x,-∞,∞}]

z=3;
lmat= Dl- I z IdentityMatrix[lfun//Values//Length];
lmat[[1,All]]=0*lmat[[1,All]];
lmat[[1,1]]=1;
sol=LinearSolve[lmat,lfun//Values//Chop];
Fun[sol,lfun//Domain]

rmat= Dr- I z IdentityMatrix[rfun//Values//Length];
rmat[[-1,All]]=0*rmat[[1,All]];
rmat[[-1,-1]]=1;
sol=LinearSolve[rmat,rfun//Values//Chop];
Fun[sol,rfun//Domain]

hatq0[z_]:=Module[{rmat,lmat,sol,out},
lmat= Dl- I z IdentityMatrix[lfun//Values//Length];
lmat[[1,All]]=0*lmat[[1,All]];
lmat[[1,1]]=1;
sol=LinearSolve[lmat,lfun//Values//Chop];
out=sol[[-1]];
rmat= Dr- I z IdentityMatrix[rfun//Values//Length];
rmat[[-1,All]]=0*rmat[[1,All]];
rmat[[-1,-1]]=1;
sol=LinearSolve[rmat,rfun//Values//Chop];
out-sol[[1]]
];

z//Clear;

FourierTransform[q0[x],x,z]/.z->1.0I

hatq0[I]/Sqrt[2Pi]

θ[x_,t_][z_]:=I x z+ I z^2 t;
z0[x_,t_]:=-x/(2t);
ν=1;
L = 10;
Ends[x_,t_]:= {z0[x,t],z0[x,t]+Exp[I Pi/4]Sqrt[2]ν,z0[x,t]+L +I ν};

Ends[1,1]

{Fun[0&,Line[Ends[1,1][[1;;2]]]], Fun[0&,Line[Ends[1,1][[2;;3]]]]}//DomainPlot

q//Clear;
q[x_,t_,n_]:=q[x,t,n]=Module[{f,out,ends,fun,fun1,fun2},
f[z_]:=Exp[θ[x,t][z]]hatq0[z]/(2 Pi);
ends=Ends[x,t];
fun1={Fun[f,Line[ends[[1;;2]]],n], Fun[f,Line[ends[[2;;3]]],n]};
ends=-Reverse[ends]+2z0[x,t];
fun2={Fun[f,Line[ends[[1;;2]]],n], Fun[f,Line[ends[[2;;3]]],n]};
fun=Join[fun1,fun2];
fun//DomainIntegrate
];

q[10,1,10]

data=ParallelTable[{x,q[x,10,20]},{x,-100,100,.1}];

ReImListPlot[data,Joined->True]

Monitor[ReImTablePlot[q[x,1,20],{x,-10,10,.1}],x]