void update_all(int gno) { update_set_lists(gno); update_world(gno); update_view(gno); update_status(gno, cur_statusitem, -1); update_ticks(gno); update_autos(gno); updatelegends(gno); updatesymbols(gno, -1); update_label_proc(); update_locator_items(gno); update_draw(); update_frame_items(gno); update_graph_items(); update_hotlinks(); }
static int leval_aac_cb(void *data) { int i, nscols, type; double start, stop; int npts; char *formula[MAX_SET_COLS]; Quark *pset, *gr; GVar *t; Leval_ui *ui = (Leval_ui *) data; Grace *grace; gr = ui->gr; type = GetOptionChoice(ui->set_type); nscols = settype_cols(type); if (xv_evalexpr(ui->start, &start) != RETURN_SUCCESS) { errmsg("Start item undefined"); return RETURN_FAILURE; } if (xv_evalexpr(ui->stop, &stop) != RETURN_SUCCESS) { errmsg("Stop item undefined"); return RETURN_FAILURE; } if (xv_evalexpri(ui->npts, &npts) != RETURN_SUCCESS) { errmsg("Number of points undefined"); return RETURN_FAILURE; } TableCommitEdit(ui->mw, FALSE); for (i = 0; i < nscols; i++) { formula[i] = TableGetCell(ui->mw, i, 0); } pset = gapp_set_new(gr); set_set_type(pset, type); grace = grace_from_quark(pset); t = graal_get_var(grace_get_graal(grace), "$t", TRUE); if (t == NULL) { errmsg("Internal error"); return RETURN_FAILURE; } #if 0 if (t->length != 0) { xfree(t->data); t->length = 0; } t->data = allocate_mesh(start, stop, npts); if (t->data == NULL) { return RETURN_FAILURE; } t->length = npts; if (set_set_length(pset, npts) != RETURN_SUCCESS) { quark_free(pset); XCFREE(t->data); t->length = 0; return RETURN_FAILURE; } #endif for (i = 0; i < nscols; i++) { char buf[32], *expr; int res; /* preparing the expression */ sprintf(buf, "%s = ", dataset_col_name(grace, i)); expr = copy_string(NULL, buf); expr = concat_strings(expr, formula[i]); /* evaluate the expression */ res = graal_parse_line(grace_get_graal(grace), expr, NULL); xfree(expr); if (res != RETURN_SUCCESS) { quark_free(pset); return RETURN_FAILURE; } } #if 0 XCFREE(t->data); t->length = 0; #endif update_set_lists(gr); return RETURN_SUCCESS; }
/* ARGSUSED */ static void do_nonl_proc(Widget w, XtPointer client_data, XtPointer call_data) { int i, npts = 0, info; double delx, *xfit, *y, *yfit; int nsteps = (int) client_data; set_wait_cursor(); curset = nlsetno = GetSelectedSet(nonl_set_item); if (curset == SET_SELECT_ERROR) { errmsg("No set selected"); unset_wait_cursor(); return; } nonl_opts.tolerance = atof((char *) xv_getstr(nonl_tol_item)); nonl_opts.parnum = GetChoice(nonl_nparm_item); strcpy(nonl_opts.formula, (char *) xv_getstr(nonl_formula_item)); for (i = 0; i < nonl_opts.parnum; i++) { strcpy(buf, (char *) xv_getstr(nonl_value_item[i])); if (sscanf(buf, "%lf", &nonl_parms[i].value) != 1) { errmsg("Invalid input in parameter field"); unset_wait_cursor(); return; } nonl_parms[i].constr = XmToggleButtonGetState(nonl_constr_item[i]); if (nonl_parms[i].constr) { strcpy(buf, (char *) xv_getstr(nonl_lowb_item[i])); if (sscanf(buf, "%lf", &nonl_parms[i].min) != 1) { errmsg("Invalid input in low-bound field"); unset_wait_cursor(); return; } strcpy(buf, (char *) xv_getstr(nonl_uppb_item[i])); if (sscanf(buf, "%lf", &nonl_parms[i].max) != 1) { errmsg("Invalid input in upper-bound field"); unset_wait_cursor(); return; } if ((nonl_parms[i].value < nonl_parms[i].min) || (nonl_parms[i].value > nonl_parms[i].max)) { errmsg("Initial values must be within bounds"); unset_wait_cursor(); return; } } } nonl_prefs.autoload = XmToggleButtonGetState(nonl_autol_item); for (i = 0; i < 3; i++) { if (XmToggleButtonGetState(nonl_load_item[i])) { nonl_prefs.load = i; break; } } if (nonl_prefs.load == LOAD_FUNCTION) { strcpy(buf, (char *) xv_getstr(nonl_start_item)); if (sscanf(buf, "%lf", &nonl_prefs.start) != 1) { errmsg("Invalid input in start field"); unset_wait_cursor(); return; } strcpy(buf, (char *) xv_getstr(nonl_stop_item)); if (sscanf(buf, "%lf", &nonl_prefs.stop) != 1) { errmsg("Invalid input in stop field"); unset_wait_cursor(); return; } strcpy(buf, (char *) xv_getstr(nonl_npts_item)); if (sscanf(buf, "%d", &nonl_prefs.npoints) != 1) { errmsg("Invalid input in start field"); unset_wait_cursor(); return; } } if (nsteps) { /* we are asked to fit */ sprintf(buf, "Fitting with formula: %s\n", nonl_opts.formula); stufftext(buf, 0); sprintf(buf, "Initial guesses:\n"); stufftext(buf, 0); for (i = 0; i < nonl_opts.parnum; i++) { sprintf(buf, "\ta%1d = %g\n", i, nonl_parms[i].value); stufftext(buf, 0); } sprintf(buf, "Tolerance = %g\n", nonl_opts.tolerance); stufftext(buf, 0); /* * The fit itself! */ info = do_nonlfit(cg, nlsetno, nsteps); if (info == -1) { errmsg("Memory allocation error in do_nonlfit()"); unset_wait_cursor(); return; } for (i = 0; i < nonl_opts.parnum; i++) { sprintf(buf, "%g", nonl_parms[i].value); xv_setstr(nonl_value_item[i], buf); } if ((info > 0 && info < 4) || (info == 5)) { sprintf(buf, "Computed values:\n"); stufftext(buf, 0); for (i = 0; i < nonl_opts.parnum; i++) { sprintf(buf, "\ta%1d = %g\n", i, nonl_parms[i].value); stufftext(buf, 0); } } if (info >= 0 && info <= 7) { char *s; switch (info) { case 0: s = "Improper input parameters.\n"; break; case 1: s = "Relative error in the sum of squares is at most tol.\n"; break; case 2: s = "Relative error between A and the solution is at most tol.\n"; break; case 3: s = "Relative error in the sum of squares and A and the solution is at most tol.\n"; break; case 4: s = "Fvec is orthogonal to the columns of the jacobian to machine precision.\n"; break; case 5: s = "\n"; break; case 6: s = "Tol is too small. No further reduction in the sum of squares is possible.\n"; break; case 7: s = "Tol is too small. No further improvement in the approximate solution A is possible.\n"; break; default: s = "\n"; errmsg("Internal error in do_nonl_proc(), please report"); break; } stufftext(s, 0); stufftext("\n", 0); } } /* endif (nsteps) */ /* * Select & activate a set to load results to */ if (!nsteps || nonl_prefs.autoload) { /* check if the set is already allocated */ if ((nlloadset == -1) || (nlloadset == nlsetno) || !getsetlength(cg, nlloadset)) { nlloadset = nextset(cg); if (nlloadset == -1) { errmsg("No more sets!"); unset_wait_cursor(); return; } else { activateset(cg, nlloadset); setlength(cg, nlloadset, 1); } } switch (nonl_prefs.load) { case LOAD_VALUES: sprintf(buf, "Evaluating fitted values and loading result to set %d:\n", nlloadset); stufftext(buf, 0); npts = getsetlength(cg, nlsetno); setlength(cg, nlloadset, npts); copycol2(cg, nlsetno, cg, nlloadset, 0); break; case LOAD_RESIDUALS: sprintf(buf, "Evaluating fitted values and loading residuals to set %d:\n", nlloadset); stufftext(buf, 0); npts = getsetlength(cg, nlsetno); setlength(cg, nlloadset, npts); copycol2(cg, nlsetno, cg, nlloadset, 0); break; case LOAD_FUNCTION: sprintf(buf, "Computing fitting function and loading result to set %d:\n", nlloadset); stufftext(buf, 0); npts = nonl_prefs.npoints; if (npts <= 1) { errmsg("Number of points must be > 1"); unset_wait_cursor(); return; } setlength(cg, nlloadset, npts); delx = (nonl_prefs.stop - nonl_prefs.start)/(npts - 1); xfit = getx(cg, nlloadset); for (i = 0; i < npts; i++) { xfit[i] = nonl_prefs.start + i * delx; } break; } setcomment(cg, nlloadset, nonl_opts.formula); do_compute(nlloadset, 0, cg, nonl_opts.formula); if (nonl_prefs.load == LOAD_RESIDUALS) { /* load residuals */ y = gety(cg, nlsetno); yfit = gety(cg, nlloadset); for (i = 0; i < npts; i++) { yfit[i] -= y[i]; } } update_set_lists(cg); drawgraph(); } unset_wait_cursor(); }