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