home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / sfit110.zip / DLL / GAUSS9.C < prev    next >
C/C++ Source or Header  |  1994-11-22  |  6KB  |  191 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. #include <float.h>
  8. #define STDCOL 5
  9. #define XSLOT 0
  10. #define YSLOT 1
  11. #define CALCSLOT -3
  12. #define BESTSLOT -2
  13. #define FLAGSLOT -1
  14.  
  15. /* static data and parameters */
  16. static double *data;                    /* start of complete data array  */
  17.  
  18. /* The data is all in a contigous block starting with datx then daty followed by
  19.  * zero or more additional data columns as read in from the data file. The last
  20.  * three slots are: datt , the current best results and the flag array. 
  21.  * Each point not in an exclusion zone has its corresponding flag TRUE. 
  22.  */
  23.  
  24.  
  25. static double *datx;                    /* x data read in from data file */
  26. static double *daty;                    /* y data read in from data file */
  27. static double *datt;                    /* generated data */
  28. static int Ndat;                        /* number of data points */
  29. static char firsttime;
  30. static double **Ptr;                    /* pointer to parameter pointer array */
  31.  
  32. struct info_line
  33.    {
  34.    char *line;
  35.    };
  36.  
  37. /*****************************************************************************/
  38. /* Do not modify any code not enclosed by this and the end banner            */
  39. /*****************************************************************************/
  40.  
  41. /* the next two values are compared to values passed by the program as check */
  42. /* NADD is the number of additional data columns required for this function  */
  43. /* NPARAM is the number of parameters required by this function              */
  44.  
  45. #define NADD 0              
  46. #define NPARAM  28
  47.  
  48. /* edit the following lines or add and delete new lines */ 
  49. static struct info_line dll_info[] = { 
  50.    "This function calculates nine gaussians.",
  51.    "It requires 28 parameters as follows:",
  52.    "P1 is the constant background.",
  53.    "P2 is the center posiion of gaussian 1 along the x axis.",
  54.    "P3 is the amplitude of gaussian 1.",
  55.    "P4 is the width of gaussian 1.", 
  56.    "P5 is the center posiion of gaussian 2 along the x axis.",
  57.    "P6 is the amplitude of gaussian 2.",
  58.    "P7 is the width of gaussian 2.", 
  59.    "P8 is the center posiion of gaussian 3 along the x axis.",
  60.    "P9 is the amplitude of gaussian 3.",
  61.    "P10is the width of gaussian 3.", 
  62.    "P11  is the center posiion of gaussian 4 along the x axis.",
  63.    "P12 is the amplitude of gaussian 4.",
  64.    "P13 is the width of gaussian 4.", 
  65.    "P14 is the center posiion of gaussian 5 along the x axis.",
  66.    "P15 is the amplitude of gaussian 5.",
  67.    "P16 is the width of gaussian 5.", 
  68.    "P17 is the center posiion of gaussian 6 along the x axis.",
  69.    "P18 is the amplitude of gaussian 6.",
  70.    "P19 is the width of gaussian 6.", 
  71.    "P20 is the center posiion of gaussian 7 along the x axis.",
  72.    "P21 is the amplitude of gaussian 7.",
  73.    "P22 is the width of gaussian 7.", 
  74.    "P23 is the center posiion of gaussian 8 along the x axis.",
  75.    "P24 is the amplitude of gaussian 8.",
  76.    "P25 is the width of gaussian 8.", 
  77.    "P26 is the center posiion of gaussian 9 along the x axis.",
  78.    "P27 is the amplitude of gaussian 9.",
  79.    "P28 is the width of gaussian 9.", 
  80.    NULL};
  81.    
  82. VOID EXPENTRY fitfunc(void)
  83.    {
  84.    int i;
  85.    double wid1, wid2, wid6, wid7; 
  86.    double wid3, wid4, wid5, wid8, wid9;
  87.    double amp1, amp2 , amp6, amp7; 
  88.    double amp3, amp4, amp5, amp8, amp9;
  89.    double pos1, pos2, pos6, pos7;
  90.    double pos3, pos4, pos5, pos8, pos9;
  91.    double E1, E2, E6, E7;
  92.    double E3, E4, E5, E8, E9;
  93.    double gau1, gau2, gau6, gau7;
  94.    double gau3, gau4, gau5, gau8, gau9;
  95.    double offset;
  96.  
  97.    /* The next section is executed the first time through only */
  98.    /* so put any initialization code in here                   */
  99.    if (firsttime) 
  100.       {
  101.       firsttime = FALSE;
  102.       /* Mask off all floating point exceptions */
  103.       _control87(MCW_EM,MCW_EM);
  104.       }
  105.  
  106.    /* give parameters more meaningful names  */
  107.    offset=*Ptr[1];
  108.    pos1 = *Ptr[2];
  109.    amp1 = *Ptr[3];
  110.    wid1 = *Ptr[4];
  111.    pos2 = *Ptr[5];
  112.    amp2 = *Ptr[6];
  113.    wid2 = *Ptr[7];
  114.    pos3 = *Ptr[8];
  115.    amp3 = *Ptr[9];
  116.    wid3 = *Ptr[10];
  117.    pos4 = *Ptr[11];
  118.    amp4 = *Ptr[12];
  119.    wid4 = *Ptr[13];
  120.    pos5 = *Ptr[14];
  121.    amp5 = *Ptr[15];
  122.    wid5 = *Ptr[16];
  123.    pos6 = *Ptr[17];
  124.    amp6 = *Ptr[18];
  125.    wid6 = *Ptr[19];
  126.    pos7 = *Ptr[20];
  127.    amp7 = *Ptr[21];
  128.    wid7 = *Ptr[22];
  129.    pos8 = *Ptr[23];
  130.    amp8 = *Ptr[24];
  131.    wid8 = *Ptr[25];
  132.    pos9 = *Ptr[26];
  133.    amp9 = *Ptr[27];
  134.    wid9 = *Ptr[28];
  135.  
  136.    /* This is the main loop that calculates the function datt[] */
  137.    /* for all data points. Put your function in the loop body   */ 
  138.    for (i = 0;i < Ndat;i++)
  139.       {
  140.       E1 = datx[i] - pos1;
  141.       E2 = datx[i] - pos2;
  142.       E3 = datx[i] - pos3;
  143.       E4 = datx[i] - pos4;
  144.       E5 = datx[i] - pos5;
  145.       E6 = datx[i] - pos6;
  146.       E7 = datx[i] - pos7;
  147.       E8 = datx[i] - pos8;
  148.       E9 = datx[i] - pos9;
  149.       gau1 = amp1 * exp(-E1*E1/wid1/wid1);        /*Gaussian */
  150.       gau2 = amp2 * exp(-E2*E2/wid2/wid2); 
  151.       gau3 = amp3 * exp(-E3*E3/wid3/wid3); 
  152.       gau4 = amp4 * exp(-E4*E4/wid4/wid4); 
  153.       gau5 = amp5 * exp(-E5*E5/wid5/wid5); 
  154.       gau6 = amp6 * exp(-E6*E6/wid6/wid6); 
  155.       gau7 = amp7 * exp(-E7*E7/wid7/wid7); 
  156.       gau8 = amp8 * exp(-E8*E8/wid8/wid8); 
  157.       gau9 = amp9 * exp(-E9*E9/wid9/wid9); 
  158.       datt[i] = gau1 + gau2 + gau3 + gau4 + gau5 + gau6 + gau7 + gau8 + gau9 +offset;
  159.       }
  160.    }
  161.  
  162. /*****************************************************************************/
  163. /* Do not modify any code not enclosed by this and the start banner          */
  164. /*****************************************************************************/
  165.  
  166.  
  167.  
  168. char EXPENTRY init_dll_globals(int N,int mb,int NP,double *dat,double *p[])
  169.    {
  170.    /* set globals */
  171.    firsttime = TRUE;
  172.    Ndat = N;
  173.    if (NADD != mb - STDCOL) return -1;
  174.    if (NPARAM != NP) return -2;
  175.    /* set array pointers */
  176.    data = dat;
  177.    daty = dat + N;
  178.    datx = dat;
  179.    datt = dat + (mb + CALCSLOT) * N;     /* the calculated data goes into the third last slot */
  180.    /* set parameter pointers */
  181.    Ptr = p;
  182.    return 0;
  183.    }
  184.  
  185. struct info_line * EXPENTRY get_dll_info(void)
  186.    {
  187.    /* return pointer to array of info strings set up above */
  188.    return dll_info; 
  189.    }
  190.  
  191.