home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / sfit110.zip / DLL / QUADRAT.C < prev    next >
C/C++ Source or Header  |  1994-11-22  |  4KB  |  117 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  4
  47.  
  48. /* edit the following lines or add and delete new lines */ 
  49. static struct info_line dll_info[] = { 
  50.    "This function calculates a quadratic.",
  51.    "It requires 4 parameters as follows:",
  52.    "P1 is the shift along the x axis.",
  53.    "P2 is the shift along the y value.",
  54.    "P3 is the magnitude of the linear term.", 
  55.    "P4 is the magnitude of the quadratic term",
  56.    NULL};
  57.    
  58. VOID EXPENTRY fitfunc(void)
  59.    {
  60.    int i;
  61.    double b, a0, a1, a2;
  62.    double x;
  63.  
  64.    /* The next section is executed the first time through only */
  65.    /* so put any initialization code in here                   */
  66.    if (firsttime) 
  67.       {
  68.       firsttime = FALSE;
  69.       /* Mask off all floating point exceptions */
  70.       _control87(MCW_EM,MCW_EM);
  71.       }
  72.  
  73.    /* give parameters more meaningful names  */
  74.    b = *Ptr[1];
  75.    a0 = *Ptr[2];
  76.    a1 = *Ptr[3];
  77.    a2 = *Ptr[4];
  78.  
  79.    /* This is the main loop that calculates the function datt[] */
  80.    /* for all data points. Put your function in the loop body   */ 
  81.    for (i = 0;i < Ndat;i++)
  82.       {
  83.       x = datx[i] - b;
  84.       datt[i] = a0 + x * (a1 + x * a2);
  85.       }
  86.    }
  87.  
  88. /*****************************************************************************/
  89. /* Do not modify any code not enclosed by this and the start banner          */
  90. /*****************************************************************************/
  91.  
  92.  
  93.  
  94. char EXPENTRY init_dll_globals(int N,int mb,int NP,double *dat,double *p[])
  95.    {
  96.    /* set globals */
  97.    firsttime = TRUE;
  98.    Ndat = N;
  99.    if (NADD != mb - STDCOL) return -1;
  100.    if (NPARAM != NP) return -2;
  101.    /* set array pointers */
  102.    data = dat;
  103.    daty = dat + N;
  104.    datx = dat;
  105.    datt = dat + (mb + CALCSLOT) * N;     /* the calculated data goes into the third last slot */
  106.    /* set parameter pointers */
  107.    Ptr = p;
  108.    return 0;
  109.    }
  110.  
  111. struct info_line * EXPENTRY get_dll_info(void)
  112.    {
  113.    /* return pointer to array of info strings set up above */
  114.    return dll_info; 
  115.    }
  116.  
  117.