home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / sfit110.zip / DLL / EXPDECAY.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. // the standard number of data columns
  9. #define STDCOL 5
  10. #define XSLOT 0
  11. #define YSLOT 1
  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 0              
  47. #define NPARAM  3
  48.  
  49. /* edit the following lines or add and delete new lines */ 
  50. static struct info_line dll_info[] = { 
  51.    "This function calculates an exponential decay.",
  52.    "It requires 3 parameters as follows:",
  53.    "P1 is the starting position of the exponential along the x axis.",
  54.    "P2 is the amplitude of exponential.",
  55.    "P3 is the decay constant.", 
  56.    NULL};
  57.    
  58. VOID EXPENTRY fitfunc(void)
  59.    {
  60.    int i;
  61.    double tau;
  62.    double amplitude;
  63.    double position;
  64.    double E;
  65.  
  66.    /* The next section is executed the first time through only */
  67.    /* so put any initialization code in here                   */
  68.    if (firsttime) 
  69.       {
  70.       firsttime = FALSE;
  71.       /* Mask off all floating point exceptions */
  72.       _control87(MCW_EM,MCW_EM);
  73.       }
  74.  
  75.    /* give parameters more meaningful names  */
  76.    position = *Ptr[1];
  77.    amplitude = *Ptr[2];
  78.    tau = *Ptr[3];
  79.  
  80.    /* This is the main loop that calculates the function datt[] */
  81.    /* for all data points. Put your function in the loop body   */ 
  82.    for (i = 0;i < Ndat;i++)
  83.       {
  84.       datt[i] = amplitude * exp(-(datx[i] - position) / tau);
  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.