<commit_before>//---------------------------------------------------------------------------


#pragma hdrstop

#include "BeamSolver.h"
//---------------------------------------------------------------------------
__fastcall TBeamSolver::TBeamSolver(AnsiString UserIniPath)
{
    this->UserIniPath = UserIniPath;
    Initialize();
}
//---------------------------------------------------------------------------
__fastcall TBeamSolver::TBeamSolver()
{
    Initialize();
}
//---------------------------------------------------------------------------
__fastcall TBeamSolver::~TBeamSolver()
{
    delete[] Cells;
    delete[] Structure;

    for (int i=0;i<Npoints;i++)
        delete Beam[i];
    delete[] Beam;

    delete[] Par;
    for (int i=0;i<Ncoef;i++)
        delete[] K[i];
    delete[] K;

    #ifndef RSLINAC
    if (SmartProgress!=NULL)
        delete SmartProgress;
    #endif

    delete InputStrings;
    delete ParsedStrings;

    //fclose(logFile);
}
//---------------------------------------------------------------------------
void TBeamSolver::Initialize()
{
    MaxCells=500;
    Nmesh=20;
    Kernel=0.9;
    SplineType=LSPLINE;
    Nstat=100;
    Ngraph=500;
    Nbars=100;
    Nav=10;
    Smooth=0.95;
    Npoints=1;

    Np=1;
    Nlim=-1;

    Magnetized=false;

    LoadIniConstants();

    DataReady=false;
    Stop=false;

    K=new TIntegration*[Ncoef];
    for (int i=0;i<Ncoef;i++)
        K[i]=new TIntegration[Np];

    Par=new TIntParameters[Ncoef];

    Cells = new TCell[1];

    Np_beam=1;
    Beam=new TBeam*[Npoints];
    for (int i=0;i<Npoints;i++) {
        Beam[i]=new TBeam(1);
    }

    Structure=new TStructure[Npoints];

    InputStrings=new TStringList;
    ParsedStrings=new TStringList;

    #ifndef RSLINAC
    SmartProgress=NULL;
    #endif
}
//---------------------------------------------------------------------------
void TBeamSolver::SaveToFile(AnsiString& Fname)
{
    FILE *F;
    F=fopen(Fname.c_str(),"wb");

    fwrite(&Npoints,sizeof(int),1,F);
    fwrite(&Np,sizeof(int),1,F);
    fwrite(&Nbars,sizeof(int),1,F);

    fwrite(Structure,sizeof(TStructure),Npoints,F);

    for(int i=0;i<Npoints;i++){
        fwrite(&(Beam[i]->lmb),sizeof(double),1,F);
        fwrite(&(Beam[i]->h),sizeof(double),1,F);
        fwrite(&(Beam[i]->Ib),sizeof(double),1,F);
        fwrite(&(Beam[i]->I0),sizeof(double),1,F);
        fwrite(Beam[i]->Particle,sizeof(TParticle),Np,F);
    }

    fclose(F);
}
//---------------------------------------------------------------------------
bool TBeamSolver::LoadFromFile(AnsiString& Fname)
{
    FILE *F;
    F=fopen(Fname.c_str(),"rb");
    bool Success;

    delete[] Structure;

    for (int i=0;i<Np_beam;i++)
        delete Beam[i];
    delete[] Beam;

    Beam=new TBeam*[Npoints];
    for (int i=0;i<Npoints;i++)
        Beam[i]=new TBeam(Np);
    Np_beam=Npoints;

    try{
        fread(&Npoints,sizeof(int),1,F);
        fread(&Np,sizeof(int),1,F);
        fread(&Nbars,sizeof(int),1,F);

        Structure=new TStructure[Npoints];
        Beam=new TBeam*[Npoints];
        for (int i=0;i<Npoints;i++)
            Beam[i]=new TBeam(Np);

        fread(Structure,sizeof(TStructure),Npoints,F);
      //    fread(Beam,sizeof(TBeam),Npoints,F);


        for (int i=0;i<Npoints;i++){
            fread(&(Beam[i]->lmb),sizeof(double),1,F);
            fread(&(Beam[i]->h),sizeof(double),1,F);
            fread(&(Beam[i]->Ib),sizeof(double),1,F);
            fread(&(Beam[i]->I0),sizeof(double),1,F);
            fread(Beam[i]->Particle,sizeof(TParticle),Np,F);
        }
        Success=true;
    } catch (...){
        Success=false;
    }

    fclose(F);
    return Success;
}
//---------------------------------------------------------------------------
#ifndef RSLINAC
void TBeamSolver::AssignSolverPanel(TObject *SolverPanel)
{
    SmartProgress=new TSmartProgress(static_cast <TWinControl *>(SolverPanel));
}
#endif
//---------------------------------------------------------------------------
void TBeamSolver::LoadIniConstants()
{
    TIniFile *UserIni;
    int t;
    double stat;

    UserIni=new TIniFile(UserIniPath);
    MaxCells=UserIni->ReadInteger("OTHER","Maximum Cells",MaxCells);
    Nmesh=UserIni->ReadInteger("NUMERIC","Number of Mesh Points",Nmesh);
    Kernel=UserIni->ReadFloat("Beam","Percent Of Particles in Kernel",Kernel);
    if (Kernel>0)
    	Kernel/=100;
    	else
    	Kernel=0.9;

    
    t=UserIni->ReadInteger("NUMERIC","Spline Interpolation",t);
    switch (t) {
        case (0):{
            SplineType=LSPLINE;
            break;
        }
        case (1):{
            SplineType=CSPLINE;
            break;
        }
        case (2):{
            SplineType=SSPLINE;
            break;
        }
    }

    stat=UserIni->ReadFloat("NUMERIC","Statistics Error",stat);
    if (stat<1e-6)
        stat=1e-6;
    if (stat>25)
        stat=25;
	int Nstat=round(100.0/stat);
	AngErr=UserIni->ReadFloat("NUMERIC","Angle Error",AngErr);
    Smooth=UserIni->ReadFloat("NUMERIC","Smoothing",Smooth);
    Ngraph=UserIni->ReadInteger("OTHER","Chart Points",Nbars);
    Nbars=UserIni->ReadInteger("NUMERIC","Hystogram Bars",Ngraph);
    Nav=UserIni->ReadInteger("NUMERIC","Averaging Points",Nav);
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfPoints()
{
    return Npoints;
}
/*//---------------------------------------------------------------------------
double TBeamSolver::GetWaveLength()
{
    return lmb;
} */
//---------------------------------------------------------------------------
int TBeamSolver::GetMeshPoints()
{
    return Nmesh;
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfParticles()
{
    return Np;
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfChartPoints()
{
    return Ngraph;
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfBars()
{
    return Nbars;
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfCells()
{
    return Ncells;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetFrequency()
{
    return F0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetPower()
{
    return P0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputCurrent()
{
    return I0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetSolenoidField()
{
    return B0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetSolenoidPosition()
{
    return Zmag;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetSolenoidLength()
{
    return Lmag;
}
/*//---------------------------------------------------------------------------
double TBeamSolver::GetMode(int *N,int *M)
{
    if (M!=NULL)
        *M=Mode_M;
    if (N!=NULL)
        *N=Mode_N;
    return Mode_N*pi/Mode_M;
}     */
//---------------------------------------------------------------------------
double TBeamSolver::GetInputAverageEnergy()
{
    return W0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputEnergyDeviation()
{
    return dW;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputAveragePhase()
{
    return Phi0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputPhaseDeviation()
{
    return dPhi;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputAlpha()
{
    return AlphaCS;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputBetta()
{
    return BettaCS;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputEpsilon()
{
    return EmittanceCS;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsCoulombAccounted()
{
    return Coulomb;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsWaveReversed()
{
    return Reverse;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsEnergyEquiprobable()
{
    return W_Eq;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsPhaseEquiprobable()
{
    return Phi_Eq;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsKeyWord(AnsiString& S)
{
    return S=="POWER" ||
        S=="SOLENOID" ||
        S=="BEAM" ||
        S=="CURRENT" ||
        S=="DRIFT" ||
        S=="CELL" ||
        S=="CELLS" ||
        S=="OPTIONS";
}
//---------------------------------------------------------------------------
TInputParameter TBeamSolver::Parse(AnsiString& S)
{
    TInputParameter P;
    if (S=="POWER")
        P=COUPLER;
    else if (S=="SOLENOID")
        P=SOLENOID;
    else if (S=="BEAM")
        P=BEAM;
    else if (S=="CURRENT")
        P=CURRENT;
    else if (S=="DRIFT")
        P=DRIFT;
    else if (S=="CELL")
        P=CELL;
    else if (S=="CELLS")
        P=CELLS;
    else if (S=="OPTIONS")
        P=OPTIONS;
    return  P;
}
//---------------------------------------------------------------------------
void TBeamSolver::GetDimensions(TCell& Cell)
{
    
    int Nbp=0,Nep=0;
    int Nar=0,Nab=0;
    int Mode=Cell.Mode;

    switch (Mode) {
        case 90:    Nbp=Nb12; Nep=Ne12;Nar=Nb23; Nab=Ne23; break;
        case 120:   Nbp=Nb23; Nep=Ne23;Nar=Nb23; Nab=Ne23; break;
        case 240:   Nbp=Nb43; Nep=Ne43;Nar=Nb23; Nab=Ne43; break;
        default: return;
    }

    double *Xo,*Yo,*Xi,*Yi;
    
    Xo=new double[Nep];
    Yo=new double[Nep];
    Xi=new double[Nbp];
    Yi=new double[Nbp];

    //Searching for a/lmb

  /*FILE *T;
    T=fopen("table.log","a");     */

    for (int i=0;i<Nbp;i++){
        for (int j=0;j<Nep;j++){
            switch (Mode) {
                case 90:    Xo[j]=E12[Nbp-i-1][j]; Yo[j]=R12[Nbp-i-1][j]; break;
                case 120:   Xo[j]=E23[Nbp-i-1][j]; Yo[j]=R23[Nbp-i-1][j]; break;
                case 240:   Xo[j]=E43[Nbp-i-1][j]; Yo[j]=R43[Nbp-i-1][j]; break;
                default: return;
            }
        }
        TSpline Spline;
        Spline.SoftBoundaries=false;
        Spline.MakeLinearSpline(Xo,Yo,Nep);
        Yi[i]=Spline.Interpolate(Cell.ELP);
       //   Xi[i]=mode90?B12[i]:B23[i];
        switch (Mode) {
            case 90:    Xi[i]=B12[i];break;
            case 120:   Xi[i]=B23[i];break;
            case 240:   Xi[i]=B43[i];break;
            default: return;
        }
    }

    TSpline rSpline;
    rSpline.SoftBoundaries=false;
    rSpline.MakeLinearSpline(Xi,Yi,Nbp);
    Cell.AkL=rSpline.Interpolate(Cell.betta);

    delete[] Xo;
    delete[] Yo;
    delete[] Xi;
    delete[] Yi;

    Xo=new double[Nar];
    Yo=new double[Nar];
    Xi=new double[Nab];
    Yi=new double[Nab];

    for (int i=0;i<Nab;i++){
        for (int j=0;j<Nar;j++){
            switch (Mode) {
                case 90:    Xo[j]=AR[j]; Yo[j]=A12[i][j]; break;
                case 120:   Xo[j]=AR[j]; Yo[j]=A23[i][j]; break;
                case 240:   Xo[j]=AR43[j]; Yo[j]=A43[i][j]; break;
                default: return;
            }

            /*Xo[j]=AR[j];
            Yo[j]=mode90?A12[i][j]:A23[i][j]; */
        }
        TSpline Spline;
        Spline.SoftBoundaries=false;
        Spline.MakeLinearSpline(Xo,Yo,Nar);
        Yi[i]=Spline.Interpolate(Cell.AkL);
        //Xi[i]=AB[i];
        switch (Mode) {
            case 90:    Xi[i]=AB[i];break;
            case 120:   Xi[i]=AB[i];break;
            case 240:   Xi[i]=AB[i];break;
            default: return;
        }
    }

    TSpline aSpline;
    aSpline.SoftBoundaries=false;
    aSpline.MakeLinearSpline(Xi,Yi,Nab);
    Cell.AL32=1e-4*aSpline.Interpolate(Cell.betta);

    delete[] Xo;
    delete[] Yo;
    delete[] Xi;
    delete[] Yi;

  /*    fprintf(T,"%f %f %f %f\n",Cell.betta,Cell.ELP,Cell.AkL,Cell.AL32);
    fclose(T);  */
    //ShowMessage(E12[0][1]);

    
  /*    for (int i=0;i<Nbt;i++){
        akl[i]=solve(ELP(akl),ELP=E0,bf[i]);
    }
    akl(bf);
    y=interp(akl(bf),bf);    */


}
//---------------------------------------------------------------------------
TInputLine *TBeamSolver::ParseFile(int& N)
{
    TInputLine *Lines;<commit_msg>Switch statement format<commit_after>//---------------------------------------------------------------------------


#pragma hdrstop

#include "BeamSolver.h"
//---------------------------------------------------------------------------
__fastcall TBeamSolver::TBeamSolver(AnsiString UserIniPath)
{
    this->UserIniPath = UserIniPath;
    Initialize();
}
//---------------------------------------------------------------------------
__fastcall TBeamSolver::TBeamSolver()
{
    Initialize();
}
//---------------------------------------------------------------------------
__fastcall TBeamSolver::~TBeamSolver()
{
    delete[] Cells;
    delete[] Structure;

    for (int i=0;i<Npoints;i++)
        delete Beam[i];
    delete[] Beam;

    delete[] Par;
    for (int i=0;i<Ncoef;i++)
        delete[] K[i];
    delete[] K;

    #ifndef RSLINAC
    if (SmartProgress!=NULL)
        delete SmartProgress;
    #endif

    delete InputStrings;
    delete ParsedStrings;

    //fclose(logFile);
}
//---------------------------------------------------------------------------
void TBeamSolver::Initialize()
{
    MaxCells=500;
    Nmesh=20;
    Kernel=0.9;
    SplineType=LSPLINE;
    Nstat=100;
    Ngraph=500;
    Nbars=100;
    Nav=10;
    Smooth=0.95;
    Npoints=1;

    Np=1;
    Nlim=-1;

    Magnetized=false;

    LoadIniConstants();

    DataReady=false;
    Stop=false;

    K=new TIntegration*[Ncoef];
    for (int i=0;i<Ncoef;i++)
        K[i]=new TIntegration[Np];

    Par=new TIntParameters[Ncoef];

    Cells = new TCell[1];

    Np_beam=1;
    Beam=new TBeam*[Npoints];
    for (int i=0;i<Npoints;i++) {
        Beam[i]=new TBeam(1);
    }

    Structure=new TStructure[Npoints];

    InputStrings=new TStringList;
    ParsedStrings=new TStringList;

    #ifndef RSLINAC
    SmartProgress=NULL;
    #endif
}
//---------------------------------------------------------------------------
void TBeamSolver::SaveToFile(AnsiString& Fname)
{
    FILE *F;
    F=fopen(Fname.c_str(),"wb");

    fwrite(&Npoints,sizeof(int),1,F);
    fwrite(&Np,sizeof(int),1,F);
    fwrite(&Nbars,sizeof(int),1,F);

    fwrite(Structure,sizeof(TStructure),Npoints,F);

    for(int i=0;i<Npoints;i++){
        fwrite(&(Beam[i]->lmb),sizeof(double),1,F);
        fwrite(&(Beam[i]->h),sizeof(double),1,F);
        fwrite(&(Beam[i]->Ib),sizeof(double),1,F);
        fwrite(&(Beam[i]->I0),sizeof(double),1,F);
        fwrite(Beam[i]->Particle,sizeof(TParticle),Np,F);
    }

    fclose(F);
}
//---------------------------------------------------------------------------
bool TBeamSolver::LoadFromFile(AnsiString& Fname)
{
    FILE *F;
    F=fopen(Fname.c_str(),"rb");
    bool Success;

    delete[] Structure;

    for (int i=0;i<Np_beam;i++)
        delete Beam[i];
    delete[] Beam;

    Beam=new TBeam*[Npoints];
    for (int i=0;i<Npoints;i++)
        Beam[i]=new TBeam(Np);
    Np_beam=Npoints;

    try{
        fread(&Npoints,sizeof(int),1,F);
        fread(&Np,sizeof(int),1,F);
        fread(&Nbars,sizeof(int),1,F);

        Structure=new TStructure[Npoints];
        Beam=new TBeam*[Npoints];
        for (int i=0;i<Npoints;i++)
            Beam[i]=new TBeam(Np);

        fread(Structure,sizeof(TStructure),Npoints,F);
      //    fread(Beam,sizeof(TBeam),Npoints,F);


        for (int i=0;i<Npoints;i++){
            fread(&(Beam[i]->lmb),sizeof(double),1,F);
            fread(&(Beam[i]->h),sizeof(double),1,F);
            fread(&(Beam[i]->Ib),sizeof(double),1,F);
            fread(&(Beam[i]->I0),sizeof(double),1,F);
            fread(Beam[i]->Particle,sizeof(TParticle),Np,F);
        }
        Success=true;
    } catch (...){
        Success=false;
    }

    fclose(F);
    return Success;
}
//---------------------------------------------------------------------------
#ifndef RSLINAC
void TBeamSolver::AssignSolverPanel(TObject *SolverPanel)
{
    SmartProgress=new TSmartProgress(static_cast <TWinControl *>(SolverPanel));
}
#endif
//---------------------------------------------------------------------------
void TBeamSolver::LoadIniConstants()
{
    TIniFile *UserIni;
    int t;
    double stat;

    UserIni=new TIniFile(UserIniPath);
    MaxCells=UserIni->ReadInteger("OTHER","Maximum Cells",MaxCells);
    Nmesh=UserIni->ReadInteger("NUMERIC","Number of Mesh Points",Nmesh);
    Kernel=UserIni->ReadFloat("Beam","Percent Of Particles in Kernel",Kernel);
    if (Kernel>0)
    	Kernel/=100;
    	else
    	Kernel=0.9;

    
    t=UserIni->ReadInteger("NUMERIC","Spline Interpolation",t);
    switch (t) {
        case (0):{
            SplineType=LSPLINE;
            break;
        }
        case (1):{
            SplineType=CSPLINE;
            break;
        }
        case (2):{
            SplineType=SSPLINE;
            break;
        }
    }

    stat=UserIni->ReadFloat("NUMERIC","Statistics Error",stat);
    if (stat<1e-6)
        stat=1e-6;
    if (stat>25)
        stat=25;
	int Nstat=round(100.0/stat);
	AngErr=UserIni->ReadFloat("NUMERIC","Angle Error",AngErr);
    Smooth=UserIni->ReadFloat("NUMERIC","Smoothing",Smooth);
    Ngraph=UserIni->ReadInteger("OTHER","Chart Points",Nbars);
    Nbars=UserIni->ReadInteger("NUMERIC","Hystogram Bars",Ngraph);
    Nav=UserIni->ReadInteger("NUMERIC","Averaging Points",Nav);
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfPoints()
{
    return Npoints;
}
/*//---------------------------------------------------------------------------
double TBeamSolver::GetWaveLength()
{
    return lmb;
} */
//---------------------------------------------------------------------------
int TBeamSolver::GetMeshPoints()
{
    return Nmesh;
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfParticles()
{
    return Np;
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfChartPoints()
{
    return Ngraph;
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfBars()
{
    return Nbars;
}
//---------------------------------------------------------------------------
int TBeamSolver::GetNumberOfCells()
{
    return Ncells;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetFrequency()
{
    return F0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetPower()
{
    return P0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputCurrent()
{
    return I0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetSolenoidField()
{
    return B0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetSolenoidPosition()
{
    return Zmag;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetSolenoidLength()
{
    return Lmag;
}
/*//---------------------------------------------------------------------------
double TBeamSolver::GetMode(int *N,int *M)
{
    if (M!=NULL)
        *M=Mode_M;
    if (N!=NULL)
        *N=Mode_N;
    return Mode_N*pi/Mode_M;
}     */
//---------------------------------------------------------------------------
double TBeamSolver::GetInputAverageEnergy()
{
    return W0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputEnergyDeviation()
{
    return dW;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputAveragePhase()
{
    return Phi0;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputPhaseDeviation()
{
    return dPhi;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputAlpha()
{
    return AlphaCS;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputBetta()
{
    return BettaCS;
}
//---------------------------------------------------------------------------
double TBeamSolver::GetInputEpsilon()
{
    return EmittanceCS;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsCoulombAccounted()
{
    return Coulomb;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsWaveReversed()
{
    return Reverse;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsEnergyEquiprobable()
{
    return W_Eq;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsPhaseEquiprobable()
{
    return Phi_Eq;
}
//---------------------------------------------------------------------------
bool TBeamSolver::IsKeyWord(AnsiString& S)
{
    return S=="POWER" ||
        S=="SOLENOID" ||
        S=="BEAM" ||
        S=="CURRENT" ||
        S=="DRIFT" ||
        S=="CELL" ||
        S=="CELLS" ||
        S=="OPTIONS";
}
//---------------------------------------------------------------------------
TInputParameter TBeamSolver::Parse(AnsiString& S)
{
    TInputParameter P;
    if (S=="POWER")
        P=COUPLER;
    else if (S=="SOLENOID")
        P=SOLENOID;
    else if (S=="BEAM")
        P=BEAM;
    else if (S=="CURRENT")
        P=CURRENT;
    else if (S=="DRIFT")
        P=DRIFT;
    else if (S=="CELL")
        P=CELL;
    else if (S=="CELLS")
        P=CELLS;
    else if (S=="OPTIONS")
        P=OPTIONS;
    return  P;
}
//---------------------------------------------------------------------------
void TBeamSolver::GetDimensions(TCell& Cell)
{
    
    int Nbp=0,Nep=0;
    int Nar=0,Nab=0;
    int Mode=Cell.Mode;

    switch (Mode) {
        case 90:    
            Nbp=Nb12; 
            Nep=Ne12;
            Nar=Nb23; 
            Nab=Ne23; 
            break;
        case 120:   
            Nbp=Nb23; 
            Nep=Ne23;
            Nar=Nb23; 
            Nab=Ne23; 
            break;
        case 240:   
            Nbp=Nb43; 
            Nep=Ne43;
            Nar=Nb23; 
            Nab=Ne43; 
            break;
        default: 
            return;
    }

    double *Xo,*Yo,*Xi,*Yi;
    
    Xo=new double[Nep];
    Yo=new double[Nep];
    Xi=new double[Nbp];
    Yi=new double[Nbp];

    //Searching for a/lmb

  /*FILE *T;
    T=fopen("table.log","a");     */

    for (int i=0;i<Nbp;i++){
        for (int j=0;j<Nep;j++){
            switch (Mode) {
                case 90:    
                    Xo[j]=E12[Nbp-i-1][j]; 
                    Yo[j]=R12[Nbp-i-1][j]; 
                    break;
                case 120:   
                    Xo[j]=E23[Nbp-i-1][j]; 
                    Yo[j]=R23[Nbp-i-1][j]; 
                    break;
                case 240:   
                    Xo[j]=E43[Nbp-i-1][j]; 
                    Yo[j]=R43[Nbp-i-1][j]; 
                    break;
                default: 
                    return;
            }
        }
        TSpline Spline;
        Spline.SoftBoundaries=false;
        Spline.MakeLinearSpline(Xo,Yo,Nep);
        Yi[i]=Spline.Interpolate(Cell.ELP);
       //   Xi[i]=mode90?B12[i]:B23[i];
        switch (Mode) {
            case 90:    
                Xi[i]=B12[i];
                break;
            case 120:   
                Xi[i]=B23[i];
                break;
            case 240:   
                Xi[i]=B43[i];
                break;
            default: 
                return;
        }
    }

    TSpline rSpline;
    rSpline.SoftBoundaries=false;
    rSpline.MakeLinearSpline(Xi,Yi,Nbp);
    Cell.AkL=rSpline.Interpolate(Cell.betta);

    delete[] Xo;
    delete[] Yo;
    delete[] Xi;
    delete[] Yi;

    Xo=new double[Nar];
    Yo=new double[Nar];
    Xi=new double[Nab];
    Yi=new double[Nab];

    for (int i=0;i<Nab;i++){
        for (int j=0;j<Nar;j++){
            switch (Mode) {
                case 90:    
                    Xo[j]=AR[j]; 
                    Yo[j]=A12[i][j]; 
                    break;
                case 120:   
                    Xo[j]=AR[j]; 
                    Yo[j]=A23[i][j]; 
                    break;
                case 240:   
                    Xo[j]=AR43[j]; 
                    Yo[j]=A43[i][j]; 
                    break;
                default: 
                    return;
            }

            /*Xo[j]=AR[j];
            Yo[j]=mode90?A12[i][j]:A23[i][j]; */
        }
        TSpline Spline;
        Spline.SoftBoundaries=false;
        Spline.MakeLinearSpline(Xo,Yo,Nar);
        Yi[i]=Spline.Interpolate(Cell.AkL);
        //Xi[i]=AB[i];
        switch (Mode) {
            case 90:    
                Xi[i]=AB[i];
                break;
            case 120:   
                Xi[i]=AB[i];
                break;
            case 240:   
                Xi[i]=AB[i];
                break;
            default: 
                return;
        }
    }

    TSpline aSpline;
    aSpline.SoftBoundaries=false;
    aSpline.MakeLinearSpline(Xi,Yi,Nab);
    Cell.AL32=1e-4*aSpline.Interpolate(Cell.betta);

    delete[] Xo;
    delete[] Yo;
    delete[] Xi;
    delete[] Yi;

  /*    fprintf(T,"%f %f %f %f\n",Cell.betta,Cell.ELP,Cell.AkL,Cell.AL32);
    fclose(T);  */
    //ShowMessage(E12[0][1]);

    
  /*    for (int i=0;i<Nbt;i++){
        akl[i]=solve(ELP(akl),ELP=E0,bf[i]);
    }
    akl(bf);
    y=interp(akl(bf),bf);    */


}
//---------------------------------------------------------------------------
TInputLine *TBeamSolver::ParseFile(int& N)
{
    TInputLine *Lines;
{'fraction_non_alphanumeric': 0.3465496368038741, 'fraction_numerical': 0.015662832929782083, 'mean_word_length': 1.1887058044216279, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3071547', 'n_tokens_mistral': 8744, 'n_tokens_neox': 8214, 'n_words': 1180}