/* * Start up editor using GR_EDITOR variable * Note the change to the GR_EDITOR variable: If it requires a text * terminal it must provide it explicitly with an xterm -e prefix */ void do_ext_editor(Widget w, XtPointer client_data, XtPointer call_data) { char buf[256], tbuf[256], *fname, *mktemp(char *); char ebuf[256], *s; int setno = GetSelectedSet(editp_set_item), curgraph=cg; if (setno == SET_SELECT_ERROR) { errwin("No set selected"); return; } strcpy(tbuf, "/tmp/xmgrXXXXXX"); fname = mktemp(tbuf); if( setno == SET_SELECT_NEXT ){ if( (setno=nextset(curgraph)) == -1 ){ errwin("Not enough sets"); return; } activateset( curgraph, setno ); do_writesets(curgraph, setno, 0, fname, sformat); } else do_writesets(curgraph, setno, 0, fname, sformat); if ((s = getenv("GR_EDITOR")) != NULL) { strcpy(ebuf, s); } else { strcpy(ebuf, "xterm -e vi"); } sprintf(buf, "%s %s", ebuf, fname); system(buf); if( isactive_set( curgraph, setno ) ) { softkillset( curgraph, setno ); getdata(curgraph, fname, SOURCE_DISK, dataset_type( curgraph, setno ) ); } else { setcomment( curgraph, setno, "editor" ); getdata(curgraph, fname, SOURCE_DISK, SET_XY ); } sprintf(buf, "rm %s", fname); system(buf); update_all( curgraph ); doforce_redraw(); }
static void eblock_accept_notify_proc(Widget, XtPointer, XtPointer) { int i = 0; char buf[256]; int setno, graphno; int cx, cy, c1 = 0, c2 = 0, c3 = 0, c4 = 0; //d1, double *tx, *ty, *t2, *t3, *t4, *t5; //d1 = (int) GetChoice(eblock_type_choice_item); cx = (int)GetChoice(eblock_x_choice_item) - 1; cy = (int)GetChoice(eblock_y_choice_item); if (cx >= 0 && cx >= blockncols) { errwin("Column for X exceeds the number of columns in block data"); return; } if (cy >= blockncols) { errwin("Column for Y exceeds the number of columns in block data"); return; } switch (block_curtype) { case XY: break; case XYRT: case XYDX: case XYDY: case XYZ: c1 = (int)GetChoice(eblock_e1_choice_item); if (c1 >= blockncols) { errwin("Column for E1 exceeds the number of columns in block data"); return; } break; case XYDXDX: case XYDYDY: case XYDXDY: c1 = (int)GetChoice(eblock_e1_choice_item); c2 = (int)GetChoice(eblock_e2_choice_item); if (c1 >= blockncols) { errwin("Column for E1 exceeds the number of columns in block data"); return; } if (c2 >= blockncols) { errwin("Column for E2 exceeds the number of columns in block data"); return; } break; case XYHILO: case XYBOX: c1 = (int)GetChoice(eblock_e1_choice_item); c2 = (int)GetChoice(eblock_e2_choice_item); c3 = (int)GetChoice(eblock_e3_choice_item); if (c1 >= blockncols) { errwin("Column for E1 exceeds the number of columns in block data"); return; } if (c2 >= blockncols) { errwin("Column for E2 exceeds the number of columns in block data"); return; } if (c3 >= blockncols) { errwin("Column for E3 exceeds the number of columns in block data"); return; } break; case XYBOXPLOT: c1 = (int)GetChoice(eblock_e1_choice_item); c2 = (int)GetChoice(eblock_e2_choice_item); c3 = (int)GetChoice(eblock_e3_choice_item); c4 = (int)GetChoice(eblock_e4_choice_item); if (c1 >= blockncols) { errwin("Column for E1 exceeds the number of columns in block data"); return; } if (c2 >= blockncols) { errwin("Column for E2 exceeds the number of columns in block data"); return; } if (c3 >= blockncols) { errwin("Column for E3 exceeds the number of columns in block data"); return; } if (c4 >= blockncols) { errwin("Column for E4 exceeds the number of columns in block data"); return; } } setno = -1; graphno = (int)GetChoice(eblock_graph_choice_item) - 1; if (graphno == -1) { graphno = cg; } if (setno == -1) { setno = nextset(graphno); } if (setno == -1) { return; } if (g[graphno].active == OFF) { set_graph_active(graphno); } activateset(graphno, setno); settype(graphno, setno, block_curtype); tx = (double *)calloc(blocklen, sizeof(double)); if (tx == NULL) { errwin("Can't allocate memory for X"); return; } ty = (double *)calloc(blocklen, sizeof(double)); if (ty == NULL) { cfree(tx); errwin("Can't allocate memory for Y"); return; } for (i = 0; i < blocklen; i++) { if (cx == -1) { tx[i] = i + 1; } else { tx[i] = blockdata[cx][i]; } ty[i] = blockdata[cy][i]; } setcol(graphno, tx, setno, blocklen, 0); setcol(graphno, ty, setno, blocklen, 1); switch (block_curtype) { case XY: sprintf(buf, "Cols %d %d", cx + 1, cy + 1); break; case XYRT: case XYDX: case XYDY: case XYZ: sprintf(buf, "Cols %d %d %d", cx + 1, cy + 1, c1 + 1); t2 = (double *)calloc(blocklen, sizeof(double)); for (i = 0; i < blocklen; i++) { t2[i] = blockdata[c1][i]; } setcol(graphno, t2, setno, blocklen, 2); break; case XYDXDX: case XYDYDY: case XYDXDY: sprintf(buf, "Cols %d %d %d %d", cx + 1, cy + 1, c1 + 1, c2 + 1); t2 = (double *)calloc(blocklen, sizeof(double)); t3 = (double *)calloc(blocklen, sizeof(double)); for (i = 0; i < blocklen; i++) { t2[i] = blockdata[c1][i]; t3[i] = blockdata[c2][i]; } setcol(graphno, t2, setno, blocklen, 2); setcol(graphno, t3, setno, blocklen, 3); break; case XYHILO: case XYBOX: sprintf(buf, "Cols %d %d %d %d %d", cx + 1, cy + 1, c1 + 1, c2 + 1, c3 + 1); t2 = (double *)calloc(blocklen, sizeof(double)); t3 = (double *)calloc(blocklen, sizeof(double)); t4 = (double *)calloc(blocklen, sizeof(double)); for (i = 0; i < blocklen; i++) { t2[i] = blockdata[c1][i]; t3[i] = blockdata[c2][i]; t4[i] = blockdata[c3][i]; } setcol(graphno, t2, setno, blocklen, 2); setcol(graphno, t3, setno, blocklen, 3); setcol(graphno, t4, setno, blocklen, 4); break; case XYBOXPLOT: sprintf(buf, "Cols %d %d %d %d %d %d", cx + 1, cy + 1, c1 + 1, c2 + 1, c3 + 1, c4 + 1); t2 = (double *)calloc(blocklen, sizeof(double)); t3 = (double *)calloc(blocklen, sizeof(double)); t4 = (double *)calloc(blocklen, sizeof(double)); t5 = (double *)calloc(blocklen, sizeof(double)); for (i = 0; i < blocklen; i++) { t2[i] = blockdata[c1][i]; t3[i] = blockdata[c2][i]; t4[i] = blockdata[c3][i]; t5[i] = blockdata[c4][i]; } setcol(graphno, t2, setno, blocklen, 2); setcol(graphno, t3, setno, blocklen, 3); setcol(graphno, t4, setno, blocklen, 4); setcol(graphno, t5, setno, blocklen, 5); break; } setcomment(graphno, setno, buf); updatesetminmax(graphno, setno); update_status_popup(NULL, NULL, NULL); drawgraph(); }
/* 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(); }