Ignore:
Timestamp:
11/08/11 10:47:14 (8 years ago)
Author:
paulbarber
Message:

Fixed some memory leaks and some compile warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/projects/slim-curve/src/main/c/GCI_Phasor.c

    r7781 r7803  
    2020#include "GCI_Phasor.h" 
    2121#include <math.h> 
     22#include <string.h> 
    2223 
    2324#ifndef NULL 
     
    6768 
    6869        // rep frequency, lets use the period of the measurement, but we can stay in the units of bins 
    69         w = 2.0*3.1415926535897932384626433832795028841971/(float)nBins; //2.0*PI/(float)nBins; 
     70        w = (float)2.0*(float)3.1415926535897932384626433832795028841971/(float)nBins; //2.0*PI/(float)nBins; 
    7071         
    7172        // integral over data 
     
    7677    // Take care that values correspond to the centre of the bin, hence i+0.5 
    7778        for (i=0, u=0.0; i<nBins; i++)  
    78                 u += (data[i]-bg) * cos(w*((float)i+0.5)); 
     79                u += (data[i]-bg) * (float)cos(w*((float)i+0.5)); 
    7980        u /= I; 
    8081 
    8182        for (i=0, v=0.0; i<nBins; i++)  
    82                 v += (data[i]-bg) * sin(w*((float)i+0.5)); 
     83                v += (data[i]-bg) * (float)sin(w*((float)i+0.5)); 
    8384        v /= I; 
    8485 
    8586        // taus, convert now to real time with xincr 
    8687        *taup = (xincr/w) * (v/u); 
    87         *taum = (xincr/w) * sqrt(1.0/(u*u + v*v) - 1.0); 
     88        *taum = (xincr/w) * (float)sqrt(1.0/(u*u + v*v) - 1.0); 
    8889 
    89         *tau = ((*taup) + (*taum))/2.0; 
     90        *tau = ((*taup) + (*taum))/(float)2.0; 
    9091 
    9192        *U = u; 
     
    101102        // integral over nominal fit data 
    102103        for (Ifit=0.0, i=fit_start; i<fit_end; i++)  
    103                 Ifit += exp(-(i-fit_start)*xincr/(*tau)); 
     104                Ifit += (float)exp(-(i-fit_start)*xincr/(*tau)); 
    104105 
    105106        // Estimate A 
     
    108109        // Calculate fit 
    109110        for (i=fit_start; i<fit_end; i++) 
    110                 fitted[i] = bg + A * exp(-(i-fit_start)*xincr/(*tau)); 
     111                fitted[i] = bg + A * (float)exp(-(i-fit_start)*xincr/(*tau)); 
    111112 
    112113        // OK, so now fitted contains our data for the timeslice of interest. 
     
    132133                                residuals[i] = res; 
    133134                        /* don't let variance drop below 1 */ 
    134                         sigma2 = (fitted[i] > 1 ? 1.0/fitted[i] : 1.0); 
     135                        sigma2 = (fitted[i] > 1 ? (float)1.0/fitted[i] : (float)1.0); 
    135136                        chisq_local += res * res * sigma2; 
    136137                } 
Note: See TracChangeset for help on using the changeset viewer.