/**************************************************************************** This routine assumes the existance of file named "vbs_files.txt" and the files decribed in the that file in current directory. File vbs_files.txt contains vbs values and corresponding Id-Vds_Vgs file names e.g. one entry may be 0.2 vbs_0.2.txt *****************************************************************************/ /******************* Header *********************************/ #include #include #include #include #include #include struct CoeffStruct{ double x; double y; double z; }; class NaturalCubicSpline1D{ public: double ValueAtX(double x); void initialize(int n,double* xData,double* yData); NaturalCubicSpline1D(int NO_OF_POINTS,double* xData,double* yData); //Read from array NaturalCubicSpline1D(); //User input ~NaturalCubicSpline1D(); private: void DetermineCoeff(); int NO_OF_POINTS; CoeffStruct* coeffsArray; }; class yCSpair{ public: double y; NaturalCubicSpline1D xCubicSpline; yCSpair(); ~yCSpair(); }; class CubicCubic{ public: double evaluate(double x,double y); void Initialize(char* Id_Vd_Vg); const CubicCubic & operator=(const CubicCubic &rhs); CubicCubic(char* Id_Vd_Vg); CubicCubic(char* yfileName,char* xzfileName); CubicCubic(int no_yPoints, double yArray[],int *pxArray,double** xArray,double** zArray); CubicCubic(); ~CubicCubic(); private: int noYPoints; yCSpair *CubicSplines1D; }; class IdVbs{ public: double Evaluate(double vds,double vgs,double vbs); void Initialize(double vbs); IdVbs(); ~IdVbs(); private: double vbs_l,vbs_h; //vbs lies in interval [vbs_l,vbs_h] CubicCubic cc_l; CubicCubic cc_h; }; /******************* Header *********************************/ /********************* SciLab Callable Routine *******************************/ //extern "C" _declspec(dllexport) extern "C" void ids_c( double *vds, double *vgs, double *vbs, double *ids){ IdVbs id; *ids=id.Evaluate(*vds,*vgs,*vbs); } /****************************************************/ using namespace std; double NaturalCubicSpline1D::ValueAtX(double x){ /* x < Start Point first polynomial to be used x > End Point last polynomial to be used */ // Find the segment where x lies int i=0; // i is used outside loop for(i=0;i0;--i){ h1=coeffsArray[i+1].x - coeffsArray[i].x; coeffsArray[i].z = (v[i] - h1*coeffsArray[i+1].z ) / u[i]; } } void NaturalCubicSpline1D::initialize(int n,double* xData,double* yData){ NO_OF_POINTS=n; coeffsArray=new CoeffStruct[NO_OF_POINTS]; for(int i=0;i>n_diffVgs; idvdvg_file>>n_diffVds; noYPoints=n_diffVgs; CubicSplines1D= new yCSpair[noYPoints]; double* vds_array; double* ids_array; vds_array=new double[n_diffVds]; ids_array=new double[n_diffVds]; int index; double vds; double ids; double vgs; for(int i=0;i>index; idvdvg_file>>vds; idvdvg_file>>ids; idvdvg_file>>vgs; CubicSplines1D[i].y=vgs; //repeat avoid vds_array[j]=vds; ids_array[j]=ids; } CubicSplines1D[i].xCubicSpline.initialize(n_diffVds,vds_array,ids_array); } } const CubicCubic & CubicCubic::operator=(const CubicCubic &rhs){ if (this != &rhs) { // make sure not same object for(int i=0;i>n_diffVgs; idvdvg_file>>n_diffVds; noYPoints=n_diffVgs; CubicSplines1D= new yCSpair[noYPoints]; double* vds_array; double* ids_array; vds_array=new double[n_diffVds]; ids_array=new double[n_diffVds]; int index; double vds; double ids; double vgs; for(int i=0;i>index; idvdvg_file>>vds; idvdvg_file>>ids; idvdvg_file>>vgs; CubicSplines1D[i].y=vgs; vds_array[j]=vds; ids_array[j]=ids; } CubicSplines1D[i].xCubicSpline.initialize(n_diffVds,vds_array,ids_array); } } CubicCubic::CubicCubic(int no_yPoints, double yArray[],int *pxArray,double* xArray[],double* zArray[]){ noYPoints=no_yPoints; CubicSplines1D= new yCSpair[noYPoints]; for(int i=0;i>n; double* vds_array; double* ids_array; vds_array=new double[n]; ids_array=new double[n]; if(!yf.is_open() || !xzf.is_open()){cout<<"Failed to open file "<>noYPoints; CubicSplines1D= new yCSpair[noYPoints]; for(int i=0;i>CubicSplines1D[i].y; for(int j=0;j>vds_array[j]; xzf>>ids_array[j]; } CubicSplines1D[i].xCubicSpline.initialize(n,vds_array,ids_array); } } } CubicCubic::CubicCubic(){ } CubicCubic::~CubicCubic(){ delete [] CubicSplines1D; CubicSplines1D=0; } yCSpair::yCSpair(){ } yCSpair::~yCSpair(){ } double IdVbs::Evaluate(double vds,double vgs,double vbs){ if(vbs_l<=vbs && vbs>vbs_lp; vbsf>>filename_l; bool found=false; while(!found || !vbsf.eof()){ vbsf>>vbs_hp; vbsf>>filename_h; if(vbs>=vbs_lp && vbs