コード例 #1
0
ファイル: labelwin.c プロジェクト: doughunt/xmgr-resurrection
void update_label_proc(void)
{
    if (label_frame) {
	if (g[cg].labs.title.s != NULL) {
	    xv_setstr(label_title_text_item, g[cg].labs.title.s);
	}
	if (g[cg].labs.stitle.s != NULL) {
	    xv_setstr(label_subtitle_text_item, g[cg].labs.stitle.s);
	}
    }
}
コード例 #2
0
ファイル: graph_ui.c プロジェクト: astrotycoon/grace
/*
 * This CB services the axis "Scale" selector 
 */
static void axis_scale_cb(OptionStructure *opt, int value, void *data)
{
    int scale = value;
    double axestart, axestop;
    char buf[32];
    Widget axis_world_start, axis_world_stop;

    ExplorerUI *eui = (ExplorerUI *) data;
    GraphUI *ui = eui->graph_ui;
    
    if (opt == ui->scale_x) {
        axis_world_start = ui->start_x;
        axis_world_stop  = ui->stop_x;
    } else {
        axis_world_start = ui->start_y;
        axis_world_stop  = ui->stop_y;
    }
    
    xv_evalexpr(axis_world_start, &axestart) ;
    xv_evalexpr(axis_world_stop,  &axestop);
    
    switch (scale) {
    case SCALE_LOG:
        if (axestart <= 0.0 && axestop <= 0.0) {
            errmsg("Can't set logarithmic scale for negative coordinates");
            SetOptionChoice(opt, SCALE_NORMAL);
            return;
        } else if (axestart <= 0.0) {
            axestart = axestop/1.0e3;
            sprintf(buf, "%g", axestart);
            xv_setstr(axis_world_start, buf);
        }
        break;
     case SCALE_LOGIT:
        if (axestart <= 0.0 && axestop <= 0.0) {
            errmsg("Can't set logit scale for values outside 0 and 1");
            SetOptionChoice(opt, SCALE_NORMAL);
            return;
        } 
	if (axestart <= 0.0) {
            axestart = 0.1;
            sprintf(buf, "%g", axestart);
            xv_setstr(axis_world_start, buf);
        }
	if (axestop >= 1.0) {
	    axestop = 0.95;
	    sprintf(buf, "%g", axestop);
            xv_setstr(axis_world_stop, buf);
	}
        break;	
    }
}
コード例 #3
0
ファイル: nonlwin.c プロジェクト: TehTreag/xmgr-resurrection
void update_nonl_frame(void)
{
    int i;
    
    if (nonl_frame) {
        XmString str = XmStringCreateSimple(nonl_opts.title);
        XtVaSetValues(nonl_title_item, XmNlabelString, str, NULL);
/* 
 * If I define only XmALIGNMENT_CENTER (default!) then it's ignored - bug in Motif???
 */
    	XtVaSetValues(nonl_title_item, XmNalignment, XmALIGNMENT_BEGINNING, NULL);
        XtVaSetValues(nonl_title_item, XmNalignment, XmALIGNMENT_CENTER, NULL);
        XmStringFree(str);
        
        xv_setstr(nonl_formula_item, nonl_opts.formula);
        sprintf(buf, "%g", nonl_opts.tolerance);
        xv_setstr(nonl_tol_item, buf);
        SetChoice(nonl_nparm_item, nonl_opts.parnum);
        for (i = 0; i < MAXPARM; i++) {
            sprintf(buf, "%g", nonl_parms[i].value);
            xv_setstr(nonl_value_item[i], buf);
            XmToggleButtonSetState(nonl_constr_item[i], nonl_parms[i].constr, False);
            sprintf(buf, "%g", nonl_parms[i].min);
            xv_setstr(nonl_lowb_item[i], buf);
            XtSetSensitive(nonl_lowb_item[i], nonl_parms[i].constr);
            sprintf(buf, "%g", nonl_parms[i].max);
            xv_setstr(nonl_uppb_item[i], buf);
            XtSetSensitive(nonl_uppb_item[i], nonl_parms[i].constr);
            if (i < nonl_opts.parnum) {
                if (!XtIsManaged (nonl_parm_item[i])) {
                    XtManageChild(nonl_parm_item[i]);
                }
            } else {
                if (XtIsManaged (nonl_parm_item[i])) {
                    XtUnmanageChild(nonl_parm_item[i]);
                }
            }
        }
        
        XmToggleButtonSetState(nonl_autol_item, nonl_prefs.autoload, False);
        for (i = 0; i < 3; i++) {
	    XmToggleButtonSetState(nonl_load_item[i], False, False);
        }
        XmToggleButtonSetState(nonl_load_item[nonl_prefs.load], True, False);
        
        if (nonl_prefs.load == LOAD_FUNCTION) {
            XtSetSensitive(nonl_fload_rc, True);
        } else {
            XtSetSensitive(nonl_fload_rc, False);
        }
        
        sprintf(buf, "%g", nonl_prefs.start);
        xv_setstr(nonl_start_item, buf);
        sprintf(buf, "%g", nonl_prefs.stop);
        xv_setstr(nonl_stop_item, buf);
        sprintf(buf, "%d", nonl_prefs.npoints);
        xv_setstr(nonl_npts_item, buf);
    }

}
コード例 #4
0
ファイル: nonlwin.c プロジェクト: TehTreag/xmgr-resurrection
void create_savefit_popup(Widget w, XtPointer client_data, XtPointer call_data)
{
    Widget fr, dialog;
    XmString dirmask;
    
    set_wait_cursor();
    
    if (savefit_dialog == NULL) {
	savefit_dialog = XmCreateFileSelectionDialog(app_shell, "savefit_dialog", NULL, 0);
	XtVaSetValues(XtParent(savefit_dialog), XmNtitle, "Save fit parameter file", NULL);
	XtAddCallback(savefit_dialog, XmNcancelCallback, (XtCallbackProc) destroy_dialog, savefit_dialog);
	XtAddCallback(savefit_dialog, XmNokCallback, (XtCallbackProc) do_savefit_proc, 0);
	XtAddCallback(savefit_dialog, XmNhelpCallback, (XtCallbackProc) HelpCB, 
	              (XtPointer) NULL);
	fr = XmCreateFrame(savefit_dialog, "fr", NULL, 0);
	dialog = XmCreateRowColumn(fr, "dialog_rc", NULL, 0);

	save_title_item = CreateTextItem2(dialog, 25, "Title: ");

	XtManageChild(dialog);
	XtManageChild(fr);
    }
    
    XtManageChild(savefit_dialog);
    XtRaise(XtParent(savefit_dialog));
    
    xv_setstr(save_title_item, nonl_opts.title);

    dirmask = XmStringCreateSimple(workingdir);
    XmFileSelectionDoSearch(savefit_dialog, dirmask);
    XmStringFree(dirmask);

    unset_wait_cursor();
}
コード例 #5
0
ファイル: ssd_ui.c プロジェクト: astrotycoon/grace
static int do_hotlinkfile_proc(FSBStructure *fsb, char *filename, void *data)
{
    SSDataUI *ui = (SSDataUI *) data;
    
    xv_setstr(ui->hotfile, filename);
    
    return TRUE;
}
コード例 #6
0
ファイル: tickwin.c プロジェクト: hsaadaoui/xmgr-resurrection
static void load_special(int gno, int a)
{
    int i;
    char buf[128];
    tickmarks t;

    if (special_frame) {
	get_graph_tickmarks(gno, &t, a);
	sprintf(buf, "%d", t.t_spec);
	xv_setstr(nspec, buf);
	for (i = 0; i < t.t_spec; i++) {
	    sprintf(buf, "%f", t.t_specloc[i]);
	    xv_setstr(specloc[i], buf);
	    if (t.t_speclab[i].s != NULL) {
		xv_setstr(speclabel[i], t.t_speclab[i].s);
	    }
	}
    }
}
コード例 #7
0
ファイル: fileswin.cpp プロジェクト: nixz/covise
static void select_dir(Widget, XtPointer, XmListCallbackStruct *cbs)
{
    char buf[MAXPATHLEN], *str;

    XmStringGetLtoR(cbs->item, charset, &str);
    strcpy(buf, str);
    XtFree(str);

    xv_setstr(dir_item, buf);
    XmFileSelectionDoSearch(workingd_dialog, NULL);
}
コード例 #8
0
ファイル: ptswin.c プロジェクト: astrotycoon/grace
void update_point_locator(int gno, int setno, int loc)
{
    int col, ncols;
    Datapoint dpoint;
    char *s, buf[64];
    
    if (points_frame == NULL) {
        return;
    }
    
    if (get_datapoint(gno, setno, loc, &ncols, &dpoint) == RETURN_SUCCESS) {
        SelectListChoice(track_set_sel, setno);

        s = copy_string(NULL, "(");
        for (col = 0; col < ncols; col++) {
            sprintf(buf, "%g", dpoint.ex[col]);
            s = concat_strings(s, buf);
            if (col != ncols - 1) {
                s = concat_strings(s, ", ");
            }
        }
        if (dpoint.s != NULL) {
            s = concat_strings(s, ", \"");
            s = concat_strings(s, dpoint.s);
            s = concat_strings(s, "\"");
        }
        s = concat_strings(s, ")");
        SetTextString(locate_point_item, s);
        xfree(s);

        sprintf(buf, "%d", loc);
        xv_setstr(goto_index_item, buf);
    } else {
        track_setno = -1;
        SelectListChoices(track_set_sel, 0, NULL);
        SetTextString(locate_point_item, "");
        xv_setstr(goto_index_item, "");
    }
}
コード例 #9
0
ファイル: graph_ui.c プロジェクト: astrotycoon/grace
void update_graph_ui(GraphUI *ui, Quark *q)
{
    if (q && quark_fid_get(q) == QFlavorGraph) {
        char buf[32];
        world w;
        GLocator *locator;
        
        graph_get_world(q, &w);
        locator = graph_get_locator(q);

        SetOptionChoice(ui->graph_type, graph_get_type(q));
        SetToggleButtonState(ui->stacked, graph_is_stacked(q));
        SetToggleButtonState(ui->flip_xy, graph_get_xyflip(q));

        sprintf(buf, "%.9g", w.xg1);
        xv_setstr(ui->start_x, buf);
        sprintf(buf, "%.9g", w.xg2);
        xv_setstr(ui->stop_x, buf);
        SetOptionChoice(ui->scale_x, graph_get_xscale(q));
        SetToggleButtonState(ui->invert_x, graph_is_xinvert(q));

        sprintf(buf, "%.9g", w.yg1);
        xv_setstr(ui->start_y, buf);
        sprintf(buf, "%.9g", w.yg2);
        xv_setstr(ui->stop_y, buf);
        SetOptionChoice(ui->scale_y, graph_get_yscale(q));
        SetToggleButtonState(ui->invert_y, graph_is_yinvert(q));

        sprintf(buf, "%g", graph_get_znorm(q));
        xv_setstr(ui->znorm, buf);

        SetSpinChoice(ui->bargap, graph_get_bargap(q));


	SetToggleButtonState(ui->fixedp, locator->pointset);
	SetOptionChoice(ui->loc_type, locator->type);
        SetFormatChoice(ui->loc_fx, &locator->fx);
        SetFormatChoice(ui->loc_fy, &locator->fy);
	sprintf(buf, "%g", locator->origin.x);
	xv_setstr(ui->locx, buf);
	sprintf(buf, "%g", locator->origin.y);
	xv_setstr(ui->locy, buf);
    }
}
コード例 #10
0
ファイル: hotwin.cpp プロジェクト: nixz/covise
static void do_hotlinkfile_proc(Widget, XtPointer client_data, XtPointer)
{
    Widget dialog = (Widget)client_data;
    Arg args;
    XmString list_item;
    char *s;

    set_wait_cursor();

    XtSetArg(args, XmNtextString, &list_item);
    XtGetValues(dialog, &args, 1);
    XmStringGetLtoR(list_item, charset, &s);

    xv_setstr(hotlink_file_item, s);

    XtFree(s);

    unset_wait_cursor();

    XtUnmanageChild(dialog);
}
コード例 #11
0
ファイル: tickwin.c プロジェクト: hsaadaoui/xmgr-resurrection
static void update_axislabel_items(int gno)
{
    Arg a;
    tickmarks t;
    int iv;
    char buf[128];

    if (axislabel_frame) {
	get_graph_tickmarks(gno, &t, curaxis);
	SetChoice(axislabellayout, t.label_layout == LAYOUT_PERPENDICULAR ? 1 : 0);
	SetChoice(axislabelplace, t.label_place == TYPE_AUTO ? 0 : 1);
	sprintf(buf, "%.2f %.2f", t.label.x, t.label.y);
	xv_setstr(axislabelspec, buf);
	SetChoice(axislabelfont, t.label.font);
	SetChoice(axislabelcolor, t.label.color);
	SetChoice(axislabellinew, t.label.linew - 1);
	iv = (int) (100 * t.label.charsize);
	XtSetArg(a, XmNvalue, iv);
	XtSetValues(axislabelcharsize, &a, 1);
    }
}
コード例 #12
0
ファイル: fileswin.cpp プロジェクト: nixz/covise
void create_workingdir_popup(Widget w, XtPointer, XtPointer)
{
    XmString str;

    set_wait_cursor();
    if (workingd_dialog == NULL)
    {
        workingd_dialog = XmCreateFileSelectionDialog(app_shell, (char *)"workingd_dialog", NULL, 0);
        XtVaSetValues(XtParent(workingd_dialog), XmNtitle, "Set working directory", NULL);
        XtAddCallback(workingd_dialog, XmNcancelCallback, (XtCallbackProc)destroy_dialog, (XtPointer)workingd_dialog);
        XtAddCallback(workingd_dialog, XmNokCallback, (XtCallbackProc)workingdir_apply_notify_proc, (XtPointer)0);

        /* unmanage unneeded items */
        w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_LIST);
        XtUnmanageChild(XtParent(w));
        w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_LIST_LABEL);
        XtUnmanageChild(w);
        w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_FILTER_LABEL);
        XtUnmanageChild(w);
        w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_FILTER_TEXT);
        XtUnmanageChild(w);
        w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_APPLY_BUTTON);
        XtUnmanageChild(w);

        /* save the name of the text item used for definition */
        dir_item = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_TEXT);

        /* Add a callback to the dir list */
        w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_DIR_LIST);
        XtAddCallback(w, XmNsingleSelectionCallback, (XtCallbackProc)select_dir, (XtPointer)0);
        XtVaSetValues(w, XmNselectionPolicy, XmSINGLE_SELECT, NULL);
    }
    xv_setstr(dir_item, workingdir);
    XtVaSetValues(workingd_dialog, XmNdirectory,
                  str = XmStringCreateLtoR(workingdir, charset), NULL);
    XmFileSelectionDoSearch(workingd_dialog, NULL);
    XmStringFree(str);
    XtRaise(workingd_dialog);
    unset_wait_cursor();
}
コード例 #13
0
ファイル: fileswin.cpp プロジェクト: nixz/covise
static void do_netcdffile_proc(Widget, XtPointer, XtPointer)
{
    Widget dialog = (Widget)client_data;
    Arg args;
    XmString list_item;
    char *s;
    char fname[256];

    set_wait_cursor();

    XtSetArg(args, XmNtextString, &list_item);
    XtGetValues(dialog, &args, 1);
    XmStringGetLtoR(list_item, charset, &s);

    xv_setstr(netcdf_file_item, s);

    XtFree(s);

    unset_wait_cursor();

    XtUnmanageChild(dialog);
    update_netcdfs();
}
コード例 #14
0
ファイル: nonlwin.cpp プロジェクト: nixz/covise
/* ARGSUSED */
void create_nonl_frame(Widget, XtPointer, XtPointer)
{
    int i;
    int x, y;
    Widget sw, fr, rc, rc1, rc2, lab, but1[3];
    set_wait_cursor();
    if (nonl_frame == NULL)
    {
        char *label1[3];
        /*
         label1[0] = "Accept";
         label1[1] = "Eval...";
         label1[2] = "Close";
      */
        label1[0] = (char *)"Accept";
        label1[1] = (char *)"Close";
        XmGetPos(app_shell, 0, &x, &y);
        nonl_frame = XmCreateDialogShell(app_shell, (char *)"Non-linear curve fitting", NULL, 0);
        handle_close(nonl_frame);
        XtVaSetValues(nonl_frame, XmNx, x, XmNy, y, NULL);
        nonl_panel = XmCreateForm(nonl_frame, (char *)"nonl_frame_rc", NULL, 0);
        fr = XmCreateFrame(nonl_panel, (char *)"nonl_frame", NULL, 0);
        rc = XmCreateRowColumn(fr, (char *)"nonl_rc", NULL, 0);

        nonl_set_item = CreateSetChoice(rc, (char *)"Use set:", maxplot, 0);

        nonl_load_item = CreatePanelChoice(rc,
                                           "Load:",
                                           4,
                                           "Fitted values",
                                           "Residuals",
                                           "None",
                                           NULL, NULL);

        nonl_loadgraph_item = CreateGraphChoice(rc, (char *)"To graph:", maxgraph, 0);

        nonl_formula_item = (Widget)CreateTextItem2(rc, 35, (char *)"Function:");
        xv_setstr(nonl_formula_item, (char *)"y = ");

        nonl_nparm_item = CreateTextItem2(rc, 5, (char *)"# of parameters:");
        nonl_tol_item = CreateTextItem2(rc, 10, (char *)"Tolerance:");
        XtManageChild(rc);
        XtManageChild(fr);
        sw = XtVaCreateManagedWidget("sw",
                                     xmScrolledWindowWidgetClass, nonl_panel,
                                     XmNscrollingPolicy, XmAUTOMATIC,
                                     NULL);

        rc = XmCreateRowColumn(sw, (char *)"rc", NULL, 0);
        XtVaSetValues(rc, XmNorientation, XmHORIZONTAL, NULL);

        rc1 = XmCreateRowColumn(rc, (char *)"rc1", NULL, 0);
        lab = XmCreateLabel(rc1, (char *)"Initial guess:", NULL, 0);
        XtManageChild(lab);
        rc2 = XmCreateRowColumn(rc, (char *)"rc2", NULL, 0);
        lab = XmCreateLabel(rc2, (char *)"Computed values:", NULL, 0);
        XtManageChild(lab);

        for (i = 0; i < MAXPARM; i++)
        {
            sprintf(buf, "A%1d: ", i);
            nonl_initial_item[i] = CreateTextItem2(rc1, 15, buf);
        }
        for (i = 0; i < MAXPARM; i++)
        {
            nonl_computed_item[i] = CreateTextItem2(rc2, 15, (char *)"");
        }
        XtManageChild(rc1);
        XtManageChild(rc2);
        XtManageChild(rc);
        XtVaSetValues(sw,
                      XmNworkWindow, rc,
                      NULL);

        rc = XmCreateRowColumn(nonl_panel, (char *)"rc", NULL, 0);
        CreateCommandButtons(rc, 2, but1, label1);
        XtAddCallback(but1[0], XmNactivateCallback,
                      (XtCallbackProc)do_nonl_proc, (XtPointer)NULL);
        /*
         XtAddCallback(but1[1], XmNactivateCallback,
                (XtCallbackProc) create_nonleval_frame, (XtPointer) NULL);
      */
        XtAddCallback(but1[1], XmNactivateCallback,
                      (XtCallbackProc)destroy_dialog, (XtPointer)nonl_frame);
        XtManageChild(rc);

        XtVaSetValues(fr,
                      XmNtopAttachment, XmATTACH_FORM,
                      XmNleftAttachment, XmATTACH_FORM,
                      XmNrightAttachment, XmATTACH_FORM,
                      NULL);
        XtVaSetValues(sw,
                      XmNtopAttachment, XmATTACH_WIDGET,
                      XmNtopWidget, fr,
                      XmNleftAttachment, XmATTACH_FORM,
                      XmNrightAttachment, XmATTACH_FORM,
                      XmNbottomAttachment, XmATTACH_WIDGET,
                      XmNbottomWidget, rc,
                      NULL);
        XtVaSetValues(rc,
                      XmNleftAttachment, XmATTACH_FORM,
                      XmNrightAttachment, XmATTACH_FORM,
                      XmNbottomAttachment, XmATTACH_FORM,
                      NULL);

        XtManageChild(nonl_panel);
    }
    XtRaise(nonl_frame);
    unset_wait_cursor();
}
コード例 #15
0
ファイル: tickwin.c プロジェクト: hsaadaoui/xmgr-resurrection
static void update_ticklabel_items(int gno)
{
    Arg a;
    tickmarks t;
    int iv;

    if (ticklabel_frame) {
	get_graph_tickmarks(gno, &t, curaxis);
	SetChoice(tlfont, t.tl_font);
	SetChoice(tlcolor, t.tl_color);
	SetChoice(tllinew, t.tl_linew - 1);
	SetChoice(tlskip, t.tl_skip);
	SetChoice(tlstagger, t.tl_staggered);
	xv_setstr(tlappstr, t.tl_appstr);
	xv_setstr(tlprestr, t.tl_prestr);
	SetChoice(tlstarttype, t.tl_starttype == TYPE_SPEC);
	if (t.tl_starttype == TYPE_SPEC) {
	    sprintf(buf, "%f", t.tl_start);
	    xv_setstr(tlstart, buf);
	    sprintf(buf, "%f", t.tl_stop);
	    xv_setstr(tlstop, buf);
	}
	SetChoice(tlstoptype, t.tl_stoptype == TYPE_SPEC);
	if (t.tl_stoptype == TYPE_SPEC) {
	    sprintf(buf, "%f", t.tl_stop);
	    xv_setstr(tlstop, buf);
	}
	iv = get_format_index(t.tl_format);
	SetChoice(tlform, iv);
	switch (t.tl_op) {
	case PLACE_LEFT:
	    SetChoice(ticklop, 0);
	    break;
	case PLACE_RIGHT:
	    SetChoice(ticklop, 1);
	    break;
	case PLACE_BOTTOM:
	    SetChoice(ticklop, 0);
	    break;
	case PLACE_TOP:
	    SetChoice(ticklop, 1);
	    break;
	case PLACE_BOTH:
	    SetChoice(ticklop, 2);
	    break;
	}
	switch (t.tl_sign) {
	case SIGN_NORMAL:
	    SetChoice(tlsign, 0);
	    break;
	case SIGN_ABSOLUTE:
	    SetChoice(tlsign, 1);
	    break;
	case SIGN_NEGATE:
	    SetChoice(tlsign, 2);
	    break;
	}
	SetChoice(tlprec, t.tl_prec);
	iv = (int) (100 * t.tl_charsize);
	XtSetArg(a, XmNvalue, iv);
	XtSetValues(tlcharsize, &a, 1);
	switch (t.tl_layout) {
	case TICKS_HORIZONTAL:
	    SetChoice(tllayout, 0);
	    break;
	case TICKS_VERTICAL:
	    SetChoice(tllayout, 1);
	    break;
	case TYPE_SPEC:
	    SetChoice(tllayout, 2);
	    break;
	}
	switch (t.tl_loc) {
	case LABEL_ONTICK:
	    SetChoice(tlloc, 0);
	    break;
	case LABEL_BETWEEN:
	    SetChoice(tlloc, 1);
	    break;
	}
	iv = (int) t.tl_angle % 360;
	XtSetArg(a, XmNvalue, iv);
	XtSetValues(tlangle, &a, 1);
    }
}
コード例 #16
0
ファイル: fileswin.cpp プロジェクト: nixz/covise
void create_netcdfs_popup(Widget, XtPointer, XtPointer)
{
    int x, y;
    static Widget top, dialog;
    Widget wbut, lab, rc, rcl, rc1, rc2, form;
    Arg args[3];

    set_wait_cursor();
    if (top == NULL)
    {
        char *label1[5];
        Widget but1[5];

        label1[0] = (char *)"Accept";
        label1[1] = (char *)"Files...";
        label1[2] = (char *)"Update";
        label1[3] = (char *)"Query";
        label1[4] = (char *)"Close";
        XmGetPos(app_shell, 0, &x, &y);
#ifdef HAVE_MFHDF
        top = XmCreateDialogShell(app_shell, (char *)"netCDF/HDF", NULL, 0);
#else
#ifdef HAVE_NETCDF
        top = XmCreateDialogShell(app_shell, (char *)"netCDF", NULL, 0);
#endif
#endif
        handle_close(top);
        XtVaSetValues(top, XmNx, x, XmNy, y, NULL);
        dialog = XmCreateRowColumn(top, (char *)"dialog_rc", NULL, 0);

        /*
         form = XmCreateForm(dialog, "form", NULL, 0);
      */
        form = XmCreateRowColumn(dialog, (char *)"form", NULL, 0);
        XtVaSetValues(form,
                      XmNpacking, XmPACK_COLUMN,
                      XmNnumColumns, 1,
                      XmNorientation, XmHORIZONTAL,
                      XmNisAligned, True,
                      XmNadjustLast, False,
                      XmNentryAlignment, XmALIGNMENT_END,
                      NULL);

        XtSetArg(args[0], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE);
        XtSetArg(args[1], XmNvisibleItemCount, 5);

        rc1 = XmCreateRowColumn(form, (char *)"rc1", NULL, 0);
        lab = XmCreateLabel(rc1, (char *)"Select set X:", NULL, 0);
        XtManageChild(lab);
        netcdf_listx_item = XmCreateScrolledList(rc1, (char *)"list", args, 2);
        XtManageChild(netcdf_listx_item);
        XtManageChild(rc1);

        rc2 = XmCreateRowColumn(form, (char *)"rc2", NULL, 0);
        lab = XmCreateLabel(rc2, (char *)"Select set Y:", NULL, 0);
        XtManageChild(lab);
        netcdf_listy_item = XmCreateScrolledList(rc2, (char *)"list", args, 2);
        XtManageChild(netcdf_listy_item);
        XtManageChild(rc2);

        XtManageChild(form);

        netcdf_file_item = CreateTextItem2(dialog, 30, "netCDF file:");
        netcdf_set_item = CreateSetChoice(dialog, "Read to set:", maxplot, 4);
        netcdf_auto_item = XmCreateToggleButton(dialog, "Autoscale on read", NULL, 0);
        XtManageChild(netcdf_auto_item);

        XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, dialog, NULL);

        CreateCommandButtons(dialog, 5, but1, label1);
        XtAddCallback(but1[0], XmNactivateCallback, (XtCallbackProc)do_netcdf_proc,
                      (XtPointer)NULL);
        XtAddCallback(but1[1], XmNactivateCallback, (XtCallbackProc)create_netcdffiles_popup,
                      (XtPointer)NULL);
        XtAddCallback(but1[2], XmNactivateCallback, (XtCallbackProc)do_netcdfupdate_proc,
                      (XtPointer)NULL);
        XtAddCallback(but1[3], XmNactivateCallback, (XtCallbackProc)do_netcdfquery_proc,
                      (XtPointer)NULL);
        XtAddCallback(but1[4], XmNactivateCallback, (XtCallbackProc)destroy_dialog,
                      (XtPointer)top);

        XtManageChild(dialog);
        netcdf_frame = top;
        if (strlen(netcdf_name))
        {
            xv_setstr(netcdf_file_item, netcdf_name);
        }
    }
    update_netcdfs();
    XtRaise(top);
    unset_wait_cursor();
}
コード例 #17
0
ファイル: nonlwin.cpp プロジェクト: nixz/covise
/* ARGSUSED */
static void do_nonl_proc(Widget, XtPointer, XtPointer)
{
    int i, setno, loadset, loadto, graphto, npar, info;
    double tol, a[MAXPARM];
    char fstr[256];
    double *y, *yp;

    set_wait_cursor();
    curset = setno = (int)GetChoice(nonl_set_item);
    loadto = (int)GetChoice(nonl_load_item);
    graphto = (int)GetChoice(nonl_loadgraph_item) - 1;
    tol = atof((char *)xv_getstr(nonl_tol_item));
    if (graphto < 0)
    {
        graphto = cg;
    }
    npar = atoi((char *)xv_getstr(nonl_nparm_item));
    strcpy(fstr, (char *)xv_getstr(nonl_formula_item));
    for (i = 0; i < MAXPARM; i++)
    {
        a[i] = 0.0;
        strcpy(buf, (char *)xv_getstr(nonl_initial_item[i]));
        sscanf(buf, "%lf", &a[i]);
    }
    yp = (double *)calloc(getsetlength(cg, setno), sizeof(double));
    if (yp == NULL)
    {
        errwin("Memory allocation error, operation cancelled");
        unset_wait_cursor();
        return;
    }
    y = gety(cg, setno);
    for (i = 0; i < getsetlength(cg, setno); i++)
    {
        yp[i] = y[i];
    }
    sprintf(buf, "Fitting: %s\n", fstr);
    stufftext(buf, 0);
    sprintf(buf, "Initial guess:\n");
    stufftext(buf, 0);
    for (i = 0; i < npar; i++)
    {
        sprintf(buf, "\ta%1d = %.9lf\n", i, a[i]);
        stufftext(buf, 0);
    }
    sprintf(buf, "Tolerance = %.9lf\n", tol);
    stufftext(buf, 0);
    lmfit(fstr, getsetlength(cg, setno), getx(cg, setno),
          yp, y, npar, a, tol, &info);
    for (i = 0; i < getsetlength(cg, setno); i++)
    {
        y[i] = yp[i];
    }
    free(yp);
    for (i = 0; i < MAXPARM; i++)
    {
        sprintf(buf, "%.9lf", a[i]);
        xv_setstr(nonl_computed_item[i], buf);
        nonl_parms[i] = a[i];
    }
    if (info > 0 && info < 4)
    {
        sprintf(buf, "Computed values:\n");
        stufftext(buf, 0);
        for (i = 0; i < npar; i++)
        {
            sprintf(buf, "\ta%1d = %.9lf\n", i, a[i]);
            stufftext(buf, 0);
        }
        loadset = nextset(cg);
        if (loadset != -1)
        {
            do_copyset(cg, setno, cg, loadset);
        }
        else
        {
            unset_wait_cursor();
            return;
        }
        switch (loadto)
        {
        case 0:
            sprintf(buf, "Evaluating function and loading result to set %d:\n", loadset);
            stufftext(buf, 0);
            do_compute(loadset, 0, graphto, fstr);
            break;
        case 1:
            sprintf(buf, "Evaluating function and loading residuals to set %d:\n", loadset);
            stufftext(buf, 0);
            do_compute(loadset, 0, graphto, fstr);
            break;
        case 2:
            sprintf(buf, "Computed function not evaluated\n");
            stufftext(buf, 0);
            break;
        }
    }
    /*
       if (info >= 4) {
      do_compute(setno, 1, graphto, fstr);
       }
   */
    if (info >= 0 && info <= 7)
    {
        char *s;
        switch (info)
        {
        case 0:
            s = (char *)"Improper input parameters.\n";
            break;
        case 1:
            s = (char *)"Relative error in the sum of squares is at most tol.\n";
            break;
        case 2:
            s = (char *)"Relative error between A and the solution is at most tol.\n";
            break;
        case 3:
            s = (char *)"Relative error in the sum of squares and A and the solution is at most tol.\n";
            break;
        case 4:
            s = (char *)"Fvec is orthogonal to the columns of the jacobian to machine precision.\n";
            break;
        case 5:
            s = (char *)"Number of calls to fcn has reached or exceeded 200*(n+1).\n";
            break;
        case 6:
            s = (char *)"Tol is too small. No further reduction in the sum of squares is possible.\n";
            break;
        case 7:
            s = (char *)"Tol is too small. No further improvement in the approximate solution A is possible.\n";
            break;
        }
        stufftext(s, 0);
        stufftext((char *)"\n", 0);
    }
    unset_wait_cursor();
}
コード例 #18
0
ファイル: nonlwin.c プロジェクト: TehTreag/xmgr-resurrection
/* 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();
}