home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / sfit110.zip / DEMO / NDENS.C < prev    next >
C/C++ Source or Header  |  1994-10-03  |  6KB  |  175 lines

  1. #define INCL_WIN
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #include <os2.h>
  7. // the standard number of data columns
  8. #define STDCOL 5
  9. #define XSLOT 0
  10. #define YSLOT 1
  11. #define ASLOT 2
  12. #define CALCSLOT -3
  13. #define BESTSLOT -2
  14. #define FLAGSLOT -1
  15.  
  16. /* static data and parameters */
  17. static double *data;                    /* start of complete data array  */
  18.  
  19. /* The data is all in a contigous block starting with datx then daty followed by
  20.  * zero or more additional data columns as read in from the data file. The last
  21.  * three slots are: datt , the current best results and the flag array. 
  22.  * Each point not in an exclusion zone has its corresponding flag TRUE. 
  23.  */
  24.  
  25.  
  26. static double *datx;                    /* x data read in from data file */
  27. static double *daty;                    /* y data read in from data file */
  28. static double *datt;                    /* generated data */
  29. static int Ndat;                        /* number of data points */
  30. static char firsttime;
  31. static double **Ptr;                    /* pointer to parameter pointer array */
  32.  
  33. struct info_line
  34.    {
  35.    char *line;
  36.    };
  37.  
  38. /*****************************************************************************/
  39. /* Do not modify any code not enclosed by this and the end banner            */
  40. /*****************************************************************************/
  41.  
  42. /* the next two values are compared to values passed by the program as check */
  43. /* NADD is the number of additional data columns required for this function  */
  44. /* NPARAM is the number of parameters required by this function              */
  45.  
  46. #define NADD 4              
  47. #define NPARAM 5
  48.  
  49. /* edit the following lines or add and delete new lines */ 
  50. static struct info_line dll_info[] = { 
  51.    "This function calculates the resistivity in GaAs",
  52.    "to compare with measured rho values obtained fron Hall effect",
  53.    "This function Uses Newton's method to solve a cubic.",
  54.    "The first data column is the sample number",
  55.    "The second column is the measured resistivity",
  56.    "4 Additional data columns are read in from the data file", 
  57.    "The first is the C concentration, the second the Zn conc",
  58.    "the third the estimated donor concentration, last the mobility.",
  59.    "It requires 5 parameters as follows:",
  60.    "P1 is the EL2 density.",
  61.    "P2 is the EL2 activation energy.",
  62.    "P3 is the temperature.", 
  63.    "P4 is the donor concentration multiplier",
  64.    "P5 is the Zn acceptor concentration multiplier",
  65.    NULL};
  66.    
  67. VOID EXPENTRY fitfunc(void)
  68.    {
  69.    int i;      
  70.    double nets;
  71.    double net;
  72.    double Nc,Nv;
  73.    double ni2;                  /* the intrinsic density squared */
  74.    double n;                    /* the electron density */
  75.    double n2;
  76.    double Nel2;                 /* El2 concentration */
  77.    double A,D,a,b,c,fn,dfn;     /* temp values */
  78.    double ncexp;
  79.    double T,Eg,Ea;              /* temperature, Gap and EL2 activation energy */
  80.    double toler = 1e-8;
  81.    double nseed = 1e19;
  82.    double K = 8.617335e-5;      /* the Boltzmann constant in eV/K */
  83.    double Dgx,Dgl;              /* the gamma,x and gamma,l separations in eV */
  84.    double DS,ZS;                /* donor and zinc intensity divisors */
  85.  
  86.    /* set pointers to additional read in data columns (if any) */
  87.    double *dat1,*dat2,*dat3,*dat4;
  88.    dat1 = datx + Ndat * (ASLOT + 0); 
  89.    dat2 = datx + Ndat * (ASLOT + 1); 
  90.    dat3 = datx + Ndat * (ASLOT + 2); 
  91.    dat4 = datx + Ndat * (ASLOT + 3); 
  92.  
  93.    /* The next section is executed the first time through only */
  94.    /* so put any initialization code in here                   */
  95.    if (firsttime) 
  96.       {
  97.       firsttime = FALSE;
  98.       }
  99.  
  100.    /* give parameters more meaningful names  */
  101.    Nel2 = *Ptr[1];              /* The El2 concentration */
  102.    Ea = *Ptr[2];                /* The EL2 activation energy */
  103.    T = *Ptr[3];                 /* The temperature */
  104.    DS = *Ptr[4];                /* divide measured donor intensity by this */
  105.    ZS = *Ptr[5];                /* divide measured Zn intensity by this */
  106.  
  107.    /* fix up the activation energy to acount for temperature variation */
  108.    Ea -= 2.37e-4 * T;
  109.    /* calculate the band gap and gamma,x and gamma,l separations*/
  110.    Eg = 1.519 - 5.405e-4 * T*T / (T + 204);
  111.    Dgx = 0.462 + 8.05e-5 * T*T / (T + 204);
  112.    Dgl = 0.296 - 6.45e-5 * T*T / (T + 204);
  113.    /* calculate the effective conduction band density of states Blakemore R164 */
  114.    Nc = 8.63e13 * sqrt(T*T*T) * ((1 - 1.93e-4 * T - 4.19e-8 * T*T) +
  115.         21 * exp(-Dgx / K / T) + 44 * exp(-Dgl / K / T));
  116.    Nv = 1.83e15 * sqrt(T*T*T);
  117.    ncexp = Nc * exp(-Ea / K / T);
  118.    /* calculate the intrinsic electron density squared */
  119.    ni2 = Nc * Nv * exp(-Eg / K / T);
  120.    c = ni2 * ncexp;
  121.  
  122.    /* This is the main loop that calculates the function datt[] */
  123.    /* for all data points. Put your function in the loop body   */ 
  124.    for (i = 0;i < Ndat;i++)
  125.       { 
  126.       n = nseed;
  127.       A = dat1[i] + dat2[i] / ZS;             /* total acceptors */
  128.       D = dat3[i] * A / DS;                   /* shallow donors */
  129.       nets = A - D;
  130.       Nel2 = Nel2 + nets;                     /* total EL2 concentration */
  131.       net = nets - Nel2;
  132.       a = nets - ncexp;
  133.       b = net * ncexp - ni2;
  134.       while (TRUE)
  135.      {
  136.      n2 = n * n;
  137.      fn = n * n2 + a * n2 + b * n - c;
  138.      dfn = 3 * n2 + 2 * a * n + b;
  139.      if ((fn / dfn / n) < toler) break;
  140.      n = n - fn / dfn;
  141.      }
  142.       datt[i] = n;                 /*the electron density */
  143.       }
  144.    }
  145.  
  146. /*****************************************************************************/
  147. /* Do not modify any code not enclosed by this and the start banner          */
  148. /*****************************************************************************/
  149.  
  150.  
  151.  
  152. char EXPENTRY init_dll_globals(int N,int mb,int NP,double *dat,double *p[])
  153.    {
  154.    /* set globals */
  155.    firsttime = TRUE;
  156.    Ndat = N;
  157.    if (NADD != mb - STDCOL) return -1;
  158.    if (NPARAM != NP) return -2;
  159.    /* set array pointers */
  160.    data = dat;
  161.    daty = dat + N;
  162.    datx = dat;
  163.    datt = dat + (mb + CALCSLOT) * N;     /* the calculated data goes into the third last slot */
  164.    /* set parameter pointers */
  165.    Ptr = p;
  166.    return 0;
  167.    }
  168.  
  169. struct info_line * EXPENTRY get_dll_info(void)
  170.    {
  171.    /* return pointer to array of info strings set up above */
  172.    return dll_info; 
  173.    }
  174.  
  175.