opts = {BaseStyle->{FontSize->15}, Frame->True, PlotStyle->Black, ImageSize->600};
SetOptions[{Plot,ListPlot,ListLogPlot}, opts];

mec2N = 0.510998910 (10^6);

ibs_linac

workdir = NotebookDirectory[]<>"LCLS2/"

IBSData[file_]:=Module[{},
rdat = Import[file, "Table"];
ix1 = Position[rdat, "BEGIN_DATA"][[1,1]] ;
ix2 = Position[rdat, "END_DATA"][[1,1]] ;
header=rdat[[ix1+1]];
units = rdat[[ix1+2]];
rdat[[ix1+3;;ix2-1]]
];

dat =IBSData[ workdir<>"ibs.out1"];

Table[{i, header[[i]]}, {i,1,Length[header]}]

units

{"m",1,"mm-mrad","mm-mrad","fs","eV","mm-mrad","mm-mrad","eV"}

energyG=ListPlot[{#[[1]], (10^(-6))mec2N#[[2]]}&/@dat, FrameLabel->{"s (m)", "Energy (MeV)"}, Joined->True , AspectRatio->1/4]

sigmazG=ListLogPlot[{#[[1]], #[[5]]}&/@dat, FrameLabel->{"s (m)", "(Subscript[σ, z])/c (fs)"}, Joined->True , AspectRatio->1/4, PlotRange->{1,4000}]

c1=Red;
c2=Green;
emitG =ListPlot[{
{#[[1]], #[[3]]}&/@dat,
{#[[1]], #[[4]]}&/@dat}, FrameLabel->{"s (m)", "normalized emittance\n(mm-mrad)"}, Joined->True , AspectRatio->1/4, PlotRange->{0,2}, PlotStyle->{c1,c2}]

sigmaEG=ListPlot[{#[[1]], #[[6]]}&/@dat, FrameLabel->{"s (m)", "(Subscript[σ, E]) (eV)"}, Joined->True , AspectRatio->1/4,PlotRange->{0,All}]

isize = 800;
ipad={{100,10},{50,10}};
gout = Grid[{
{Show[energyG, ImageSize->isize, ImagePadding->ipad]},
{Show[sigmazG, ImageSize->isize, ImagePadding->ipad]},
{Show[sigmaEG, ImageSize->isize, ImagePadding->ipad]},
{Show[emitG, ImageSize->isize, ImagePadding->ipad]}}]

(*Export[workdir<>"ibs.pdf", gout]

(*headerstrings = StringSplit[ Import[outfile, "String"], "\n"][[1;;17]]*)

Comparison

dat0 =IBSData[ workdir<>"ibs.out0"];
dat1 =IBSData[ workdir<>"ibs.out1"];
dat2 =IBSData[ workdir<>"ibs.out2"];

myf = {#[[1]], (10^(-3))#[[6]]}&;
compG1 = ListPlot[{
(myf /@dat0),
(myf /@dat1),
(myf /@dat2)},
 FrameLabel->{"s (m)", "(Subscript[σ, E]) (keV)"}, Joined->True , AspectRatio->1/4,PlotRange->{1, 1000}, PlotStyle->{Black,Red, Blue}]

myf = {#[[1]], (10^(-3))#[[6]]}&;
compG1zoom= ListLogPlot[{
(myf /@dat0),
(myf /@dat1),
(myf /@dat2)},
 FrameLabel->{"s (m)", "(Subscript[σ, E]) (keV)"}, Joined->True , AspectRatio->1/4,PlotRange->{500, 1000}, PlotStyle->{Black,Red, Blue}]

myf = {#[[1]], #[[5]]}&;
compG2 = ListLogPlot[{
(myf /@dat0),
(myf /@dat1),
(myf /@dat2)},
 FrameLabel->{"s (m)", "(Subscript[σ, z])/c (fs)"}, Joined->True , AspectRatio->1/4,PlotRange->{5, 2500}, PlotStyle->{Black,Red, Blue}]

myf = {#[[1]], #[[5]]}&;
compG2zoom = ListPlot[{
(myf /@dat0),
(myf /@dat1),
(myf /@dat2)},
 FrameLabel->{"s (m)", "(Subscript[σ, z])/c (fs)"}, Joined->True , AspectRatio->1/4,PlotRange->{7,50}, PlotStyle->{Black,Red, Blue}]

myf = {#[[1]], #[[3]]}&;
compG3 = ListLogPlot[{
(myf /@dat0),
(myf /@dat1),
(myf /@dat2)},
 FrameLabel->{"s (m)", "normalized emittance\n(mm-mrad)"}, Joined->True , AspectRatio->1/4,PlotRange->{0,0.5}, PlotStyle->{Black,Red, Blue}]

isize = 800;
ipad={{100,10},{50,10}};
gout1 = Grid[{
{Show[energyG, ImageSize->isize, ImagePadding->ipad]},
{Show[compG1, ImageSize->isize, ImagePadding->ipad]},
{Show[compG2 , ImageSize->isize, ImagePadding->ipad]},
{Show[compG3 , ImageSize->isize, ImagePadding->ipad]}}]

isize = 800;
ipad={{100,10},{50,10}};
gout2 = Grid[{
{Show[energyG, ImageSize->isize, ImagePadding->ipad]},
{Show[compG1zoom, ImageSize->isize, ImagePadding->ipad]},
{Show[compG2zoom , ImageSize->isize, ImagePadding->ipad]},
{Show[compG3 , ImageSize->isize, ImagePadding->ipad]}}]

Export[workdir<>"ibs_comparison1.pdf", gout1]

Export[workdir<>"ibs_comparison2.pdf", gout2]