Exemplo n.º 1
0
void write_save_file(uint64_t p)
{
  if (checkpoint_opt)
    write_checkpoint(p);
  if (!(checkpoint_opt && factors_opt))
    write_output_files(p);
}
Exemplo n.º 2
0
Arquivo: fit.c Projeto: timburrow/ovj3
int
mathfunc()
{
    int i;
    double val;
    double *xvars;		/* Values of the independent variable(s) */
    int nvars;			/* Nbr of independent variables */
    int np = 0;			/* Number of numerical parameters found */
    double threshold = 0;	/* Ignore pixels below this intensity */
    double sigLev = 1; // Significance level to set pixel's fit value (1=no significance)
    double chisq = 0; // Chi-square -- alternative to sigLev, if set
    double snThresh = 0; // min S/N to set value of parameter pixel
    int nparams = 0;		/* Nbr of parameters in fit */
    char *xname = "ti";
    char msg[256];
    char *str;

    int quick = FALSE;
    int noderiv = FALSE;
    int gotfun = FALSE;
    int fit_type = NONLINEAR;
    int use_prev_params = FALSE;
    int prev = FALSE;
    int noprev = FALSE;
    int pdone;

    void (*function)() = NULL;
    void (*jacobian)() = NULL;
    int (*guess)() = NULL;
    int (*parfix)() = NULL;
    int (*method)() = NULL;
    double *(*xvarfunc)() = set_xvars;

    int arg = 2;
    extern double d1mach_();

    if (in_vec_len[0]<1){
	ib_errmsg("MATH: fit: No input images");
	return FALSE;
    }
    if (input_sizes_differ){
	ib_errmsg("MATH: fit: Input image sizes differ");
	return FALSE;
    }
    if (!want_output(0)){
	ib_errmsg("MATH: fit: No frame for first output image");
	return FALSE;
    }

    /* Read numerical parameters (nothing to do with params of the fit!) */
    pdone = FALSE;
    for (i=0; i<nbr_params && !pdone; i++){
	val = in_params[i];
	switch (i){
	  case 0:
	    threshold = val;
	    pdone = TRUE;	/* Last parameter to read */
	    break;
	}
    }
    nbr_params -= i;
    in_params += i;

    /* Read string parameters */
    gotfun = FALSE;
    for (i=0; i<nbr_strings; i++){
	str = in_strings[i];
	if (!gotfun && getfunction(str, &nparams, &use_prev_params, &fit_type,
				   &function, &jacobian, &guess, &parfix))
	{
	    /* Got a functional form */
	    gotfun = TRUE;
	}else if (!quick && strcasecmp(str,"quick") == 0){
	    /* Use "quick" mode */
	    quick = TRUE;
	}else if (!noderiv && strcasecmp(str,"noderiv") == 0){
	    /* Do not use derivative, even if available */
	    noderiv = TRUE;
	}else if (!prev && strcasecmp(str,"prev") == 0){
	    /* Use previous parameter values for estimates */
	    prev = TRUE;
	}else if (!noprev && strcasecmp(str,"noprev") == 0){
	    /* Do not use previous parameter values for estimates */
	    noprev = TRUE;
	} else if (strncasecmp(str, "p=", 2) == 0) {
	    val = atof(str+2);
	    if (val != 0) {
	        val = val < 1e-20 ? 1e-20 : (val > 1 ? 1 : val);
	        sigLev = val;
	    }
        } else if (strncasecmp(str, "chisq=", 6) == 0) {
            val = atof(str+6);
            if (val != 0) {
                chisq = val;
            }
        } else if (strncasecmp(str, "snThresh=", 9) == 0) {
            val = atof(str+9);
            if (val != 0) {
                snThresh = val;
            }
	}else{
	    /* None of the above--assume independent variable name */
	    xname = str;
	}
    }

    /* Do not write to more output files than we can usefully use */
    if (nparams){
	int maxout;
	maxout = 2 * nparams + 1;
	if (maxout<nbr_outfiles) nbr_outfiles = maxout; /* Change global var */
    }
    create_output_files(nbr_outfiles, in_object[0]);

    /* Check the setup */
    if (!gotfun){
	ib_errmsg("MATH: fit: No known fit type specified");
	return FALSE;
    }

    if (noderiv){
	jacobian = NULL;
    }

    if (prev){
	use_prev_params = TRUE;
    }else if (noprev){
	use_prev_params = FALSE;
    }

    if (quick || !function){
	method = NULL;
    }else{
	method = marquardt;
    }

    /* Set the independent variable */
    xvars = (*xvarfunc)(in_object, in_vec_len[0], xname, &nvars);
    if (!xvars){
	sprintf(msg,"MATH: No values for independent variable \"%.200s\"",
                xname);
	ib_errmsg(msg);
	return FALSE;
    }

    if (chisq == 0) {
        chisq = chisqCompInv(sigLev, in_vec_len[0] - nparams + 1);
    }

    fit_images(in_object, in_vec_len[0], xvars, nvars,
	       threshold, chisq, snThresh, img_width, img_height, img_depth,
	       out_object, nbr_outfiles, want_output, fit_type,
	       nparams, use_prev_params,
	       function, jacobian, method, guess, parfix);

    write_output_files();

    return TRUE;
}