#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <math.h>
#include <complex>
#include <string>
#include <vector>
#include "tools.h"
#include "Grating2D.h"
#include <tbci/vector.h>
#include <tbci/matrix.h>
#include <tbci/f_matrix.h>
#include <tbci/lapack_stdcplx.h>
using namespace std;
using TBCI::Vector;
using TBCI::F_Matrix;
int nOrds, nPixelsX, nPixelsY, nLayers, px;
double periodX, periodY;
vector<double> thicknes;
double lambda, theta, phi;
complex<double> n1, n3, ref;
vector < Matrix< complex<double> > > refInd;
Matrix< complex<double> > incidX, incidY, trans, refl;
int main(void)
{
complex<double> I;
I=complex<double>(0.,1.);
nOrds=3;
nPixelsX=2;
nPixelsY=2;
periodX=10;
periodY=10;
nLayers=1;
lambda=1.01;
theta=0.;
phi=0.;
n1=1.;
n3=1.;
Vector<double> thickness(nLayers);
Vector<string> file;
Vector<double> transPtX(2),transPtY(2);
nPixelsX=2;nPixelsY=2;
refInd.assign(nLayers, Matrix< complex<double> >(nPixelsX, nPixelsY));
refInd[0](0,0)=complex<double>(1.,0.0);
refInd[0](0,1)=complex<double>(2.,0.0);
refInd[0](1,0)=complex<double>(2.,0.0);
refInd[0](1,1)=complex<double>(1.,0.0);
transPtX[0]=0.25;
transPtX[1]=1.;
transPtY[0]=0.1;
transPtY[1]=1.;
Grating2D DOE(nLayers);
cout<<nOrds<<endl;
incidX.resize(0.,nOrds, nOrds);
incidY.resize(0.,nOrds, nOrds);
trans.resize(0.,nOrds, nOrds);
refl.resize(0.,nOrds, nOrds);
thicknes.resize(nLayers);
for (int i=0;i<nLayers;i++) thickness(i)=10;
incidX((nOrds-1)/2,(nOrds-1)/2)=1.;
incidY((nOrds-1)/2,(nOrds-1)/2)=1.;
DOE.setMemsave(true);
DOE.setParameters(nOrds, periodX, periodY, thickness, lambda, theta, phi, n1, n3);
DOE.setTransPt(transPtX,transPtY);
DOE.setIncid(incidX, incidY);
for (int i=0;i<nLayers;i++)
{
DOE.layer[i].setRefInd(refInd[i]);
DOE.layer[i].solve();
}
DOE.setSMatrix();
DOE.writeParameters("Parameters-test"+to_str(nOrds)+".dat");
}