Esempio n. 1
0
void lmdif_driver(void *fcn, int m, int n, double *xvec, double tol) {
    int info;
    int lwa = m * n + 5 * n + m;
    int *iwa;
    double *fvec, *wa;

    if (n > m) {
        printf("Error: lmdif called with n > m\n");
        return;
    }

    iwa = (int *)malloc(sizeof(int) * n);
    fvec = (double *)malloc(sizeof(double) * m);
    wa = (double *)malloc(sizeof(double) * lwa);

//#ifdef WIN32
//    LMDIF1(fcn, &m, &n, xvec, fvec, &tol, &info, iwa, wa, &lwa);
//#else
    lmdif1_(fcn, &m, &n, xvec, fvec, &tol, &info, iwa, wa, &lwa);
//#endif

#if 0
    switch (info) {
        case 0:
            printf("Improper input parameters\n");
            break;
        case 1:
            printf("Sum of squares tolerance reached\n");
            break;
        case 2:
            printf("x is within tolerance\n");
            break;
        case 3:
            printf("Sum of squares and x are within tolerance\n");
            break;
        case 4:
            printf("fvec orthogonal\n");
            break;
        case 5:
            printf("max function calls made\n");
            break;
        case 6:
            printf("tolerance is too small (squares)\n");
            break;
        case 7:
            printf("tolerance is too small (x)\n");
            break;
    }
#endif

    free(iwa);
    free(fvec);
    free(wa);
}
Esempio n. 2
0
int fit( double *p0, int *info){

  int m, n, lwa, iwa[4], one=1;
  double tol, fnorm, x[4], fvec[64], wa[512];
  extern void fcn();
        /*Fits one set of intensities from threshold scan. ud is 1 for lower threshold scan,
        -1 for upper threshold scan. Returns intensity, centroid and width of best fit to
        erf() function. x is array of DAC values for intensities y_meas.
        p0[0...3] is initial guess for solution.*/
	
	tol = sqrt(dpmpar_(&one));
	m=NPOINTS;
	n=4;
	lwa=512;
	lmdif1_(&fcn, &m, &n, p0, fvec, &tol, info, iwa, wa, &lwa);

	}