Exemple #1
0
int I_get_con_points(char *group, struct Ortho_Control_Points *cp)
{
    FILE *fd;
    char msg[100];
    int stat;

    fd = I_fopen_group_file_old(group, POINT_FILE);
    if (fd == NULL) {
	sprintf(msg,
		"unable to open control point (Z) file for group [%s in %s]",
		group, G_mapset());
	G_warning(msg);
	G_sleep(4);
	return 0;
    }

    stat = I_read_con_points(fd, cp);
    fclose(fd);
    if (stat < 0) {
	sprintf(msg, "bad format in control point file for group [%s in %s]",
		group, G_mapset());
	G_warning(msg);
	G_sleep(4);
	return 0;
    }
    return 1;
}
Exemple #2
0
int I_convert_con_points(char *group, struct Ortho_Control_Points *con_cp,
			 struct Ortho_Control_Points *photo_cp, double E12[3],
			 double N12[3])
{
    FILE *fd;
    char msg[100];
    int i, stat, status;
    double e1, e2, n1, n2, z1, z2, e0, n0;


    fd = I_fopen_group_file_old(group, POINT_FILE);
    if (fd == NULL) {
	sprintf(msg,
		"unable to open control point (Z) file for group [%s in %s]",
		group, G_mapset());
	G_warning(msg);
	G_sleep(4);
	return 0;
    }

    stat = I_read_con_points(fd, con_cp);
    fclose(fd);
    if (stat < 0) {
	sprintf(msg, "bad format in control point file for group [%s in %s]",
		group, G_mapset());
	G_warning(msg);
	G_sleep(4);
	return 0;
    }

    /* convert to photo coordinates, given E12, N12 */
    photo_cp->count = 0;
    for (i = 0; i < con_cp->count; i++) {
	status = con_cp->status[i];
	e1 = con_cp->e1[i];
	n1 = con_cp->n1[i];
	z1 = con_cp->z1[i];
	e2 = con_cp->e2[i];
	n2 = con_cp->n2[i];
	z2 = con_cp->z2[i];

	I_georef(e1, n1, &e0, &n0, E12, N12);
	/* I_new_con_point (photo_cp, e0,n0,z1,e2,n2,z2,status); */
	I_new_con_point(photo_cp, e0, n0, z1, e2, n2, z2, status);
    }

    return 1;
}
Exemple #3
0
/* 
 * run_system() - Run system command 
 *
 * RETURN: >0 success : 0 failure
 */
int run_system(char *pgm)
{
    int stat;

    if ((stat = G_spawn(pgm, pgm, NULL)))
	G_sleep(3);

    return stat;
}
Exemple #4
0
int run(char *pgm, char *flags, char *name)
{
    char path[GPATH_MAX];
    int stat;

    sprintf(path, "%s/etc/mon.%s", G_gisbase(), pgm);

    if (*flags) {
	if ((stat = G_spawn(path, pgm, flags, name, NULL)))
	    G_sleep(3);
    }
    else {
	if ((stat = G_spawn(path, pgm, name, NULL)))
	    G_sleep(3);
    }

    return stat;
}
Exemple #5
0
int show_env(void)
{
    fprintf(stderr, "env(%d) switch to LOCATION %s, MAPSET %s\n", which_env,
	    G__getenv("LOCATION_NAME") ==
	    NULL ? "?" : G__getenv("LOCATION_NAME"),
	    G__getenv("MAPSET") == NULL ? "?" : G__getenv("MAPSET"));
    G_sleep(2);

    return 0;
}
Exemple #6
0
void *dig_falloc(int nelem, int elsize)
{
    void *ret;

    if ((ret = dig__falloc(nelem, elsize)) == NULL) {
	fprintf(stderr, "Out of Memory.\n");
	G_sleep(2);
	exit(EXIT_FAILURE);
    }
    return (ret);
}
Exemple #7
0
void *dig_frealloc(void *oldptr, int nelem, int elsize, int oldnelem)
{
    char *ret;

    if ((ret = dig__frealloc(oldptr, nelem, elsize, oldnelem)) == NULL) {
	fprintf(stderr, "\nOut of Memory on realloc.\n");
	G_sleep(2);
	exit(EXIT_FAILURE);
    }
    return (ret);
}
Exemple #8
0
/* 
 * run_etc_support() - Run command in etc/support 
 *
 * RETURN: >0 success : 0 failure
 */
int run_etc_support(char *pgm, char *rast)
{
    char path[GPATH_MAX];
    int stat;

    sprintf(path, "%s/etc/%s", G_gisbase(), pgm);

    if ((stat = G_spawn(path, pgm, rast, NULL)))
	G_sleep(3);

    return stat;
}
Exemple #9
0
int I_put_con_points(char *group, struct Ortho_Control_Points *cp)
{
    FILE *fd;
    char msg[100];

    fd = I_fopen_group_file_new(group, POINT_FILE);
    if (fd == NULL) {
	sprintf(msg,
		"unable to create control point file for group [%s in %s]",
		group, G_mapset());
	G_warning(msg);
	G_sleep(4);
	return 0;
    }

    I_write_con_points(fd, cp);
    fclose(fd);
    return 1;
}
Exemple #10
0
/* Return the elev name from the block file ELEV
    returns 0 on fail,  1 on success */
int I_get_group_elev(char *group, char *elev, char *mapset_elev, char *tl,
		     char *math_exp, char *units, char *nd)
{
    char buf[IN_BUF];
    FILE *fd;

    if (!I_find_group_elev_file(group)) {
	G_warning(
	    _("Unable to find elevation file for group <%s> in mapset <%s>"),
	      group, G_mapset());
	return 0;
    }

    G_suppress_warnings(1);
    fd = I_fopen_group_elev_old(group);
    G_suppress_warnings(0);

    if (!fd) {
	G_warning(
	    _("Unable to open elevation file for group <%s> in mapset <%s>"),
	      group, G_mapset());
	G_sleep(3);

	return 0;
    }

    fgets(buf, IN_BUF, fd);
    sscanf(buf, "elevation layer :%s\n", elev);
    fgets(buf, IN_BUF, fd);
    sscanf(buf, "mapset elevation:%s\n", mapset_elev);
    fgets(buf, IN_BUF, fd);
    sscanf(buf, "location        :%s\n", tl);
    fgets(buf, IN_BUF, fd);
    sscanf(buf, "math expresion  :%s\n", math_exp);
    fgets(buf, IN_BUF, fd);
    sscanf(buf, "units           :%s\n", units);
    fgets(buf, IN_BUF, fd);
    sscanf(buf, "no data values  :%s\n", nd);
    fclose(fd);

    return 1;
}
Exemple #11
0
static Window *make_window(int top, int bottom, int left, int right)
{
    Window *window;

    if (top < 0 || bottom >= LINES || left < 0 || right >= COLS
	|| bottom - top <= 1 || right - left <= 1) {
	End_curses();
	G_warning(_("make_window(%d,%d,%d,%d): illegal screen values."),
		  top, bottom, left, right);
	G_sleep(3);
	exit(1);
    }
    window = (Window *) G_malloc(sizeof(Window));
    window->top = top;
    window->bottom = bottom;
    window->left = left;
    window->right = right;
    Curses_clear_window(window);
    return window;
}
Exemple #12
0
int main(int argc, char *argv[])
{
    struct Option *type, *rc_file;
    struct Flag *update, *nolaunch;
    struct GModule *module;
    const char *gui_type_env;
    char progname[GPATH_MAX];
    char *desc;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("general"));
    G_add_keyword(_("gui"));
    G_add_keyword(_("user interface"));
    module->label =
	_("Launches a GRASS graphical user interface (GUI) session.");
    module->description = _("And updates default user interface settings.");

    type = G_define_option();
    type->key = "ui";
    type->type = TYPE_STRING;
    type->label = _("User interface");
    type->description = _("Default value: GRASS_GUI if defined otherwise wxpython");
    desc = NULL;
    G_asprintf(&desc,
	        "wxpython;%s;text;%s",
	        _("wxPython based GUI (wxGUI)"),
	        _("command line interface only"));
    type->descriptions = desc;
    type->options = "wxpython,text";
    type->guisection = _("Type");
    
    rc_file = G_define_standard_option(G_OPT_F_INPUT);
    rc_file->key = "workspace";
    rc_file->required = NO;
    rc_file->key_desc = "name.gxw";
    rc_file->description = _("Name of workspace file to load on start-up (valid only for wxGUI)");

    update = G_define_flag();
    update->key = 'd';
    update->description = _("Update default user interface settings");
    update->guisection = _("Default");

    nolaunch = G_define_flag();
    nolaunch->key = 'n';
    nolaunch->description =
	_("Do not launch GUI after updating the default user interface settings");
    nolaunch->guisection = _("Default");

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);


    if (type->answer && strcmp(type->answer, "text") == 0 &&
	!nolaunch->answer)
	nolaunch->answer = TRUE;
    
    if (nolaunch->answer && !update->answer)
	update->answer = TRUE;
    
    gui_type_env = G__getenv("GUI");

    if (!type->answer) {
	if (gui_type_env && strcmp(gui_type_env, "text")) {
	    type->answer = G_store(gui_type_env);
	}
	else {
	    type->answer = "wxpython";
	}
    }

    if (((gui_type_env && update->answer) &&
	 strcmp(gui_type_env, type->answer) != 0) || !gui_type_env) {
	G_setenv("GUI", type->answer);
	G_message(_("<%s> is now the default GUI"), type->answer);
    }
    else {
	if(update->answer)
	    if(gui_type_env) {
		G_debug(1, "No change: old gui_type_env=[%s], new type->ans=[%s]",
			gui_type_env, type->answer);
	    }
    }

    if(nolaunch->answer)
	exit(EXIT_SUCCESS);


    G_message(_("Launching <%s> GUI in the background, please wait..."), type->answer);

    if (strcmp(type->answer, "wxpython") == 0) {
	sprintf(progname, "%s/gui/wxpython/wxgui.py", G_gisbase());
	if (rc_file->answer) {
	    G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
		    "--workspace", rc_file->answer, SF_BACKGROUND, NULL);
	}
	else {
	    G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
		    SF_BACKGROUND, NULL);
	}
    }

    /* stop the impatient from starting it again
        before the splash screen comes up */
    G_sleep(3);

    exit(EXIT_SUCCESS);
}
Exemple #13
0
static int compute_transformation(void)
{				/* returns 0 on success, 1 on fail */
    int n, count;
    double d, d1, d2, sum;
    double e1, e2, n1, n2;
    double xval, yval, gval;
    static int order_pnts[3] = { 3, 6, 10 };
    char msg[40];

    xmax = ymax = gmax = 0;
    xval = yval = gval = 0.0;

    CRS_Compute_equation(trans_order);
    if (group.equation_stat <= 0) {
	if (group.equation_stat == 0) {
	    sprintf(msg, "Not Enough Points -- %d are required.",
		    order_pnts[trans_order - 1]);
	    Menu_msg(msg);
	    G_sleep(2);
	}
	return 1;
    }


    /* compute the row,col error plus ground error 
     * keep track of largest and second largest error
     */
    sum = 0.0;
    rms = 0.0;
    count = 0;
    for (n = 0; n < group.points.count; n++) {
	if (group.points.status[n] <= 0)
	    continue;
	count++;
	CRS_georef(group.points.e2[n], group.points.n2[n], &e1, &n1,
		   group.E21, group.N21, trans_order);
	CRS_georef(group.points.e1[n], group.points.n1[n], &e2, &n2,
		   group.E12, group.N12, trans_order);

	if ((d = xres[n] = e1 - group.points.e1[n]) < 0)
	    d = -d;
	if (d > xval) {
	    xmax = n;
	    xval = d;
	}

	if ((d = yres[n] = n1 - group.points.n1[n]) < 0)
	    d = -d;
	if (d > yval) {
	    ymax = n;
	    yval = d;
	}

	/* compute ground error (ie along diagonal) */
	d1 = e2 - group.points.e2[n];
	d2 = n2 - group.points.n2[n];
	d = d1 * d1 + d2 * d2;
	sum += d;		/* add it to rms sum, before taking sqrt */
	d = sqrt(d);
	gnd[n] = d;
	if (d > gval) {		/* is this one the max? */
	    gmax = n;
	    gval = d;
	}
    }

    /* compute overall rms error */
    if (count)
	rms = sqrt(sum / count);

    return 0;
}
Exemple #14
0
int main(int argc, char *argv[])
{
    struct Option *type, *rc_file;
    struct Flag *update_ui, *fglaunch, *nolaunch;
    struct GModule *module;
    const char *gui_type_env;
    char progname[GPATH_MAX];
    char *desc;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("general"));
    G_add_keyword(_("GUI"));
    G_add_keyword(_("user interface"));

    module->label =
        _("Launches a GRASS graphical user interface (GUI) session.");
    module->description = _("Optionally updates default user interface settings.");

    type = G_define_option();
    type->key = "ui";
    type->type = TYPE_STRING;
    type->description = _("User interface");
    desc = NULL;
    G_asprintf(&desc,
               "wxpython;%s;text;%s;gtext;%s;",
               _("wxPython based GUI (wxGUI)"),
               _("command line interface only"),
               _("command line interface with GUI startup screen"));
    type->descriptions = desc;
    type->options = "wxpython,text,gtext";
    type->answer = "wxpython";
    type->guisection = _("Type");

    rc_file = G_define_standard_option(G_OPT_F_INPUT);
    rc_file->key = "workspace";
    rc_file->required = NO;
    rc_file->key_desc = "name.gxw";
    rc_file->label = _("Name of workspace file to load on start-up");
    rc_file->description = _("This is valid only for wxGUI (wxpython)");

    fglaunch = G_define_flag();
    fglaunch->key = 'f';
    fglaunch->label = _("Start GUI in the foreground");
    fglaunch->description = _("By default the GUI starts in the background"
                              " and control is immediately returned to the caller."
                              " When GUI runs in foregreound, it blocks the command line");

    update_ui = G_define_flag();
    update_ui->key = 'd';
    update_ui->description = _("Update default user interface settings");
    update_ui->guisection = _("Default");

    nolaunch = G_define_flag();
    nolaunch->key = 'n';
    nolaunch->description =
        _("Do not launch GUI after updating the default user interface settings");
    nolaunch->guisection = _("Default");

    if (G_parser(argc, argv))
        exit(EXIT_FAILURE);

    gui_type_env = G_getenv_nofatal("GUI");
    G_debug(1, "GUI: %s", gui_type_env ? gui_type_env : "unset");
    if (update_ui->answer) {
        if (!gui_type_env || strcmp(type->answer, gui_type_env)) {
            G_setenv("GUI", type->answer);
            G_message(_("<%s> is now the default GUI"), type->answer);
        }
    }

    if(strcmp(type->answer, "wxpython") != 0 || nolaunch->answer) {
        if (!update_ui->answer)
            G_warning(_("Nothing to do. For setting up <%s> as default UI use -%c flag."),
                      type->answer, update_ui->key);
        exit(EXIT_SUCCESS);
    }

    sprintf(progname, "%s/gui/wxpython/wxgui.py", G_gisbase());
    if (access(progname, F_OK) == -1)
        G_fatal_error(_("Your installation doesn't include GUI, exiting."));

    if (fglaunch->answer) {
        G_message(_("Launching <%s> GUI, please wait..."), type->answer);
        if (rc_file->answer) {
            G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
                       "--workspace", rc_file->answer, NULL);
        }
        else {
            G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
                       NULL);
        }
    }
    else {
        G_message(_("Launching <%s> GUI in the background, please wait..."), type->answer);
        if (rc_file->answer) {
            G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
                       "--workspace", rc_file->answer, SF_BACKGROUND, NULL);
        }
        else {
            G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
                       SF_BACKGROUND, NULL);
        }
        /* stop the impatient from starting it again
           before the splash screen comes up */
        G_sleep(3);
    }

    exit(EXIT_SUCCESS);
}