int scan_gis(char *element, char *desc, char *key, char *data, char *name, char *mapset, int gobble) { const char *ms; *mapset = 0; if (sscanf(data, "%s %s", name, mapset) < 1) { error(key, data, "illegal request (scan_gis)"); if (gobble) gobble_input(); return 0; } if (strcmp(name, "list") == 0) { if (isatty(0)) G_list_element(element, desc, mapset, (int (*)())NULL); reject(); return 0; } ms = G_find_file2(element, name, mapset); if (ms == NULL) { error(key, data, "not found"); if (gobble) gobble_input(); return 0; } strcpy(mapset, ms); return 1; }
/* Zoom - to region */ int zoom_region(void) { struct Cell_head win; char *mapset; G_debug(2, "zoom_region()"); driver_open(); mapset = G_find_file2("windows", var_getc(VAR_ZOOM_REGION), NULL); if (mapset == NULL) { G_warning(_("Cannot find window '%s'"), var_getc(VAR_ZOOM_REGION)); return 0; } G__get_window(&win, "windows", var_getc(VAR_ZOOM_REGION), mapset); G_put_window(&win); G_set_window(&win); display_redraw(); driver_close(); G_debug(3, "zoom_region(): End"); return 1; }
/*! \brief Lowest level open routine. Opens the file <i>name</i> in <i>element</i> ("cell", etc.) in mapset <i>mapset</i> according to the i/o <i>mode</i>. - mode = 0 (read) will look for <i>name</i> in <i>mapset</i> and open the file for read only the file must exist - mode = 1 (write) will create an empty file <i>name</i> in the current mapset and open the file for write only <i>mapset</i> ignored - mode = 2 (read and write) will open a file in the current mapset for reading and writing creating a new file if necessary <i>mapset</i> ignored \param element database element name \param name map file name \param mapset mapset containing map <i>name</i> \param mode r/w mode 0=read, 1=write, 2=read/write \return open file descriptor (int) \return -1 could not open */ static int G__open(const char *element, const char *name, const char *mapset, int mode) { char path[GPATH_MAX]; char xname[GNAME_MAX], xmapset[GMAPSET_MAX]; G__check_gisinit(); /* READ */ if (mode == 0) { if (G_name_is_fully_qualified(name, xname, xmapset)) { if (*mapset && strcmp(xmapset, mapset) != 0) { G_warning(_("G__open(read): mapset <%s> doesn't match xmapset <%s>"), mapset, xmapset); return -1; } name = xname; mapset = xmapset; } else if (!mapset || !*mapset) mapset = G_find_file2(element, name, mapset); if (!mapset) return -1; G_file_name(path, element, name, mapset); return open(path, 0); } /* WRITE */ if (mode == 1 || mode == 2) { mapset = G_mapset(); if (G_name_is_fully_qualified(name, xname, xmapset)) { if (strcmp(xmapset, mapset) != 0) { G_warning(_("G__open(write): xmapset <%s> != G_mapset() <%s>"), xmapset, mapset); return -1; } name = xname; } if (*name && G_legal_filename(name) == -1) return -1; G_file_name(path, element, name, mapset); if (mode == 1 || access(path, 0) != 0) { G__make_mapset_element(element); close(open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666)); } return open(path, mode); } return -1; }
int G3d_readRange(const char *name, const char *mapset, struct FPRange *drange) /* adapted from G_read_fp_range */ { int fd; char xname[GNAME_MAX], xmapset[GMAPSET_MAX]; char buf[GNAME_MAX + sizeof(G3D_DIRECTORY) + 2], buf2[GMAPSET_MAX + sizeof(G3D_RANGE_ELEMENT) + 2]; char xdr_buf[100]; DCELL dcell1, dcell2; XDR xdr_str; G_init_fp_range(drange); fd = -1; if (G__name_is_fully_qualified(name, xname, xmapset)) { sprintf(buf, "%s/%s", G3D_DIRECTORY, xname); sprintf(buf2, "%s@%s", G3D_RANGE_ELEMENT, xmapset); /* == range@mapset */ } else { sprintf(buf, "%s/%s", G3D_DIRECTORY, name); sprintf(buf2, "%s", G3D_RANGE_ELEMENT); } if (G_find_file2(buf, buf2, mapset)) { fd = G_open_old(buf, buf2, mapset); if (fd < 0) goto error; if (read(fd, xdr_buf, 2 * G3D_XDR_DOUBLE_LENGTH) != 2 * G3D_XDR_DOUBLE_LENGTH) return 2; xdrmem_create(&xdr_str, xdr_buf, (u_int) G3D_XDR_DOUBLE_LENGTH * 2, XDR_DECODE); /* if the f_range file exists, but empty */ if (!xdr_double(&xdr_str, &dcell1) || !xdr_double(&xdr_str, &dcell2)) goto error; G_update_fp_range(dcell1, drange); G_update_fp_range(dcell2, drange); close(fd); return 1; } error: if (fd > 0) close(fd); G_warning("can't read range file for [%s in %s]", name, mapset); return -1; }
GDALDataset *GRASSDataset::Open( GDALOpenInfo * poOpenInfo ) { char *pszGisdb = NULL, *pszLoc = NULL; char *pszMapset = NULL, *pszElem = NULL, *pszName = NULL; char **papszCells = NULL; char **papszMapsets = NULL; /* -------------------------------------------------------------------- */ /* Does this even look like a grass file path? */ /* -------------------------------------------------------------------- */ if( strstr(poOpenInfo->pszFilename,"/cellhd/") == NULL && strstr(poOpenInfo->pszFilename,"/group/") == NULL ) return NULL; /* Always init, if no rasters are opened G_no_gisinit resets the projection and * rasters in different projection may be then opened */ // Don't use GISRC file and read/write GRASS variables (from location G_VAR_GISRC) to memory only. G_set_gisrc_mode ( G_GISRC_MODE_MEMORY ); // Init GRASS libraries (required) G_no_gisinit(); // Doesn't check write permissions for mapset compare to G_gisinit // Set error function G_set_error_routine ( (GrassErrorHandler) Grass2CPLErrorHook ); // GISBASE is path to the directory where GRASS is installed, if ( !getenv( "GISBASE" ) ) { static char* gisbaseEnv = NULL; const char *gisbase = GRASS_GISBASE; CPLError( CE_Warning, CPLE_AppDefined, "GRASS warning: GISBASE " "enviroment variable was not set, using:\n%s", gisbase ); char buf[2000]; snprintf ( buf, sizeof(buf), "GISBASE=%s", gisbase ); buf[sizeof(buf)-1] = '\0'; CPLFree(gisbaseEnv); gisbaseEnv = CPLStrdup ( buf ); putenv( gisbaseEnv ); } if ( !SplitPath( poOpenInfo->pszFilename, &pszGisdb, &pszLoc, &pszMapset, &pszElem, &pszName) ) { return NULL; } /* -------------------------------------------------------------------- */ /* Check element name */ /* -------------------------------------------------------------------- */ if ( strcmp(pszElem,"cellhd") != 0 && strcmp(pszElem,"group") != 0 ) { G_free(pszGisdb); G_free(pszLoc); G_free(pszMapset); G_free(pszElem); G_free(pszName); return NULL; } /* -------------------------------------------------------------------- */ /* Set GRASS variables */ /* -------------------------------------------------------------------- */ G__setenv( "GISDBASE", pszGisdb ); G__setenv( "LOCATION_NAME", pszLoc ); G__setenv( "MAPSET", pszMapset); // group is searched only in current mapset G_reset_mapsets(); G_add_mapset_to_search_path ( pszMapset ); /* -------------------------------------------------------------------- */ /* Check if this is a valid grass cell. */ /* -------------------------------------------------------------------- */ if ( strcmp(pszElem,"cellhd") == 0 ) { if ( G_find_file2("cell", pszName, pszMapset) == NULL ) { G_free(pszGisdb); G_free(pszLoc); G_free(pszMapset); G_free(pszElem); G_free(pszName); return NULL; } papszMapsets = CSLAddString( papszMapsets, pszMapset ); papszCells = CSLAddString( papszCells, pszName ); } /* -------------------------------------------------------------------- */ /* Check if this is a valid GRASS imagery group. */ /* -------------------------------------------------------------------- */ else { struct Ref ref; I_init_group_ref( &ref ); if ( I_get_group_ref( pszName, &ref ) == 0 ) { G_free(pszGisdb); G_free(pszLoc); G_free(pszMapset); G_free(pszElem); G_free(pszName); return NULL; } for( int iRef = 0; iRef < ref.nfiles; iRef++ ) { papszCells = CSLAddString( papszCells, ref.file[iRef].name ); papszMapsets = CSLAddString( papszMapsets, ref.file[iRef].mapset ); G_add_mapset_to_search_path ( ref.file[iRef].mapset ); } I_free_group_ref( &ref ); } G_free( pszMapset ); G_free( pszName ); /* -------------------------------------------------------------------- */ /* Create a corresponding GDALDataset. */ /* -------------------------------------------------------------------- */ GRASSDataset *poDS; poDS = new GRASSDataset(); /* notdef: should only allow read access to an existing cell, right? */ poDS->eAccess = poOpenInfo->eAccess; poDS->pszGisdbase = pszGisdb; poDS->pszLocation = pszLoc; poDS->pszElement = pszElem; /* -------------------------------------------------------------------- */ /* Capture some information from the file that is of interest. */ /* -------------------------------------------------------------------- */ #if GRASS_VERSION_MAJOR >= 7 Rast_get_cellhd( papszCells[0], papszMapsets[0], &(poDS->sCellInfo) ); #else if( G_get_cellhd( papszCells[0], papszMapsets[0], &(poDS->sCellInfo) ) != 0 ) { CPLError( CE_Warning, CPLE_AppDefined, "GRASS: Cannot open raster header"); delete poDS; return NULL; } #endif poDS->nRasterXSize = poDS->sCellInfo.cols; poDS->nRasterYSize = poDS->sCellInfo.rows; poDS->adfGeoTransform[0] = poDS->sCellInfo.west; poDS->adfGeoTransform[1] = poDS->sCellInfo.ew_res; poDS->adfGeoTransform[2] = 0.0; poDS->adfGeoTransform[3] = poDS->sCellInfo.north; poDS->adfGeoTransform[4] = 0.0; poDS->adfGeoTransform[5] = -1 * poDS->sCellInfo.ns_res; /* -------------------------------------------------------------------- */ /* Try to get a projection definition. */ /* -------------------------------------------------------------------- */ struct Key_Value *projinfo, *projunits; projinfo = G_get_projinfo(); projunits = G_get_projunits(); poDS->pszProjection = GPJ_grass_to_wkt ( projinfo, projunits, 0, 0); if (projinfo) G_free_key_value(projinfo); if (projunits) G_free_key_value(projunits); /* -------------------------------------------------------------------- */ /* Create band information objects. */ /* -------------------------------------------------------------------- */ for( int iBand = 0; papszCells[iBand] != NULL; iBand++ ) { GRASSRasterBand *rb = new GRASSRasterBand( poDS, iBand+1, papszMapsets[iBand], papszCells[iBand] ); if ( !rb->valid ) { CPLError( CE_Warning, CPLE_AppDefined, "GRASS: Cannot open raster band %d", iBand); delete rb; delete poDS; return NULL; } poDS->SetBand( iBand+1, rb ); } CSLDestroy(papszCells); CSLDestroy(papszMapsets); /* -------------------------------------------------------------------- */ /* Confirm the requested access is supported. */ /* -------------------------------------------------------------------- */ if( poOpenInfo->eAccess == GA_Update ) { delete poDS; CPLError( CE_Failure, CPLE_NotSupported, "The GRASS driver does not support update access to existing" " datasets.\n" ); return NULL; } return poDS; }
int read_rgb(char *key, char *data) { char names[3][100]; char fullname[100]; int i; if (sscanf(data, "%s %s %s", names[0], names[1], names[2]) != 3) { error(key, data, "illegal request (rgb)"); return 0; } PS.do_raster = 0; PS.do_colortable = 0; if (PS.cell_fd >= 0) { G_close_cell(PS.cell_fd); G_free(PS.cell_name); G_free(PS.cell_mapset); G_free_colors(&PS.colors); PS.cell_fd = -1; } /* initialize group structure (for compatibility with PS_raster_plot()) */ I_init_group_ref(&grp.ref); /* * not relevant here * if (I_get_group_ref(grp.group_name, &grp.ref) == 0) G_fatal_error(_("Can't get group information")); */ grp.group_name = "RGB Group"; /* get file names for R, G, & B */ for (i = 0; i < 3; i++) { char *mapset, *name, *p; name = names[i]; p = strchr(name, '@'); if (p) { *p = '\0'; mapset = p + 1; } else { mapset = G_find_file2("cell", name, ""); if (!mapset) { error(name, "", "not found"); return 0; } } grp.name[i] = G_store(name); grp.mapset[i] = G_store(mapset); /* read in colors */ if (G_read_colors(grp.name[i], grp.mapset[i], &(grp.colors[i])) == -1) { sprintf(fullname, "%s in %s", grp.name[i], grp.mapset[i]); error(fullname, "", "can't read color table"); return 0; } /* open raster maps for reading */ if ((grp.fd[i] = G_open_cell_old(grp.name[i], grp.mapset[i])) < 0) { sprintf(fullname, "%s in %s", grp.name[i], grp.mapset[i]); error(fullname, "", "can't open raster map"); G_free_colors(&(grp.colors[i])); return 0; } } strcpy(PS.celltitle, grp.group_name); G_strip(PS.celltitle); return 1; }
int main(int argc, char *argv[]) { int i; int print_flag = 0; int flat_flag; int set_flag; double x; int ival; int row_flag = 0, col_flag = 0; struct Cell_head window, temp_window; const char *value; const char *name; const char *mapset; char **rast_ptr, **vect_ptr; struct GModule *module; struct { struct Flag *update, *print, *gprint, *flprint, *lprint, *eprint, *nangle, *center, *res_set, *dist_res, *dflt, *z, *savedefault, *bbox, *gmt_style, *wms_style; } flag; struct { struct Option *north, *south, *east, *west, *top, *bottom, *res, *nsres, *ewres, *res3, *tbres, *rows, *cols, *save, *region, *raster, *raster3d, *align, *zoom, *vect; } parm; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("general")); G_add_keyword(_("settings")); module->description = _("Manages the boundary definitions for the " "geographic region."); /* flags */ flag.dflt = G_define_flag(); flag.dflt->key = 'd'; flag.dflt->description = _("Set from default region"); flag.dflt->guisection = _("Existing"); flag.savedefault = G_define_flag(); flag.savedefault->key = 's'; flag.savedefault->label = _("Save as default region"); flag.savedefault->description = _("Only possible from the PERMANENT mapset"); flag.savedefault->guisection = _("Existing"); flag.print = G_define_flag(); flag.print->key = 'p'; flag.print->description = _("Print the current region"); flag.print->guisection = _("Print"); flag.lprint = G_define_flag(); flag.lprint->key = 'l'; flag.lprint->description = _("Print the current region in lat/long " "using the current ellipsoid/datum"); flag.lprint->guisection = _("Print"); flag.eprint = G_define_flag(); flag.eprint->key = 'e'; flag.eprint->description = _("Print the current region extent"); flag.eprint->guisection = _("Print"); flag.center = G_define_flag(); flag.center->key = 'c'; flag.center->description = _("Print the current region map center coordinates"); flag.center->guisection = _("Print"); flag.gmt_style = G_define_flag(); flag.gmt_style->key = 't'; flag.gmt_style->description = _("Print the current region in GMT style"); flag.gmt_style->guisection = _("Print"); flag.wms_style = G_define_flag(); flag.wms_style->key = 'w'; flag.wms_style->description = _("Print the current region in WMS style"); flag.wms_style->guisection = _("Print"); flag.dist_res = G_define_flag(); flag.dist_res->key = 'm'; flag.dist_res->description = _("Print region resolution in meters (geodesic)"); flag.dist_res->guisection = _("Print"); flag.nangle = G_define_flag(); flag.nangle->key = 'n'; flag.nangle->label = _("Print the convergence angle (degrees CCW)"); flag.nangle->description = _("The difference between the projection's grid north and true north, " "measured at the center coordinates of the current region."); flag.nangle->guisection = _("Print"); flag.z = G_define_flag(); flag.z->key = '3'; flag.z->description = _("Print also 3D settings"); flag.z->guisection = _("Print"); flag.bbox = G_define_flag(); flag.bbox->key = 'b'; flag.bbox->description = _("Print the maximum bounding box in lat/long on WGS84"); flag.bbox->guisection = _("Print"); flag.gprint = G_define_flag(); flag.gprint->key = 'g'; flag.gprint->description = _("Print in shell script style"); flag.gprint->guisection = _("Print"); flag.flprint = G_define_flag(); flag.flprint->key = 'f'; flag.flprint->description = _("Print in shell script style, but in one line (flat)"); flag.flprint->guisection = _("Print"); flag.res_set = G_define_flag(); flag.res_set->key = 'a'; flag.res_set->description = _("Align region to resolution (default = align to bounds, " "works only for 2D resolution)"); flag.res_set->guisection = _("Bounds"); flag.update = G_define_flag(); flag.update->key = 'u'; flag.update->description = _("Do not update the current region"); flag.update->guisection = _("Effects"); /* parameters */ parm.region = G_define_standard_option(G_OPT_M_REGION); parm.region->description = _("Set current region from named region"); parm.region->guisection = _("Existing"); parm.raster = G_define_standard_option(G_OPT_R_MAP); parm.raster->key = "raster"; parm.raster->required = NO; parm.raster->multiple = YES; parm.raster->description = _("Set region to match raster map(s)"); parm.raster->guisection = _("Existing"); parm.raster3d = G_define_standard_option(G_OPT_R3_MAP); parm.raster3d->key = "raster_3d"; parm.raster3d->required = NO; parm.raster3d->multiple = NO; parm.raster3d->description = _("Set region to match 3D raster map(s) (both 2D and 3D " "values)"); parm.raster3d->guisection = _("Existing"); parm.vect = G_define_standard_option(G_OPT_V_MAP); parm.vect->key = "vector"; parm.vect->required = NO; parm.vect->multiple = YES; parm.vect->label = _("Set region to match vector map(s)"); parm.vect->description = NULL; parm.vect->guisection = _("Existing"); parm.north = G_define_option(); parm.north->key = "n"; parm.north->key_desc = "value"; parm.north->required = NO; parm.north->multiple = NO; parm.north->type = TYPE_STRING; parm.north->description = _("Value for the northern edge"); parm.north->guisection = _("Bounds"); parm.south = G_define_option(); parm.south->key = "s"; parm.south->key_desc = "value"; parm.south->required = NO; parm.south->multiple = NO; parm.south->type = TYPE_STRING; parm.south->description = _("Value for the southern edge"); parm.south->guisection = _("Bounds"); parm.east = G_define_option(); parm.east->key = "e"; parm.east->key_desc = "value"; parm.east->required = NO; parm.east->multiple = NO; parm.east->type = TYPE_STRING; parm.east->description = _("Value for the eastern edge"); parm.east->guisection = _("Bounds"); parm.west = G_define_option(); parm.west->key = "w"; parm.west->key_desc = "value"; parm.west->required = NO; parm.west->multiple = NO; parm.west->type = TYPE_STRING; parm.west->description = _("Value for the western edge"); parm.west->guisection = _("Bounds"); parm.top = G_define_option(); parm.top->key = "t"; parm.top->key_desc = "value"; parm.top->required = NO; parm.top->multiple = NO; parm.top->type = TYPE_STRING; parm.top->description = _("Value for the top edge"); parm.top->guisection = _("Bounds"); parm.bottom = G_define_option(); parm.bottom->key = "b"; parm.bottom->key_desc = "value"; parm.bottom->required = NO; parm.bottom->multiple = NO; parm.bottom->type = TYPE_STRING; parm.bottom->description = _("Value for the bottom edge"); parm.bottom->guisection = _("Bounds"); parm.rows = G_define_option(); parm.rows->key = "rows"; parm.rows->key_desc = "value"; parm.rows->required = NO; parm.rows->multiple = NO; parm.rows->type = TYPE_INTEGER; parm.rows->description = _("Number of rows in the new region"); parm.rows->guisection = _("Resolution"); parm.cols = G_define_option(); parm.cols->key = "cols"; parm.cols->key_desc = "value"; parm.cols->required = NO; parm.cols->multiple = NO; parm.cols->type = TYPE_INTEGER; parm.cols->description = _("Number of columns in the new region"); parm.cols->guisection = _("Resolution"); parm.res = G_define_option(); parm.res->key = "res"; parm.res->key_desc = "value"; parm.res->required = NO; parm.res->multiple = NO; parm.res->type = TYPE_STRING; parm.res->description = _("2D grid resolution (north-south and east-west)"); parm.res->guisection = _("Resolution"); parm.res3 = G_define_option(); parm.res3->key = "res3"; parm.res3->key_desc = "value"; parm.res3->required = NO; parm.res3->multiple = NO; parm.res3->type = TYPE_STRING; parm.res3->description = _("3D grid resolution (north-south, east-west and top-bottom)"); parm.res3->guisection = _("Resolution"); parm.nsres = G_define_option(); parm.nsres->key = "nsres"; parm.nsres->key_desc = "value"; parm.nsres->required = NO; parm.nsres->multiple = NO; parm.nsres->type = TYPE_STRING; parm.nsres->description = _("North-south 2D grid resolution"); parm.nsres->guisection = _("Resolution"); parm.ewres = G_define_option(); parm.ewres->key = "ewres"; parm.ewres->key_desc = "value"; parm.ewres->required = NO; parm.ewres->multiple = NO; parm.ewres->type = TYPE_STRING; parm.ewres->description = _("East-west 2D grid resolution"); parm.ewres->guisection = _("Resolution"); parm.tbres = G_define_option(); parm.tbres->key = "tbres"; parm.tbres->key_desc = "value"; parm.tbres->required = NO; parm.tbres->multiple = NO; parm.tbres->type = TYPE_STRING; parm.tbres->description = _("Top-bottom 3D grid resolution"); parm.tbres->guisection = _("Resolution"); parm.zoom = G_define_option(); parm.zoom->key = "zoom"; parm.zoom->key_desc = "name"; parm.zoom->required = NO; parm.zoom->multiple = NO; parm.zoom->type = TYPE_STRING; parm.zoom->description = _("Shrink region until it meets non-NULL data from this raster map"); parm.zoom->gisprompt = "old,cell,raster"; parm.zoom->guisection = _("Bounds"); parm.align = G_define_option(); parm.align->key = "align"; parm.align->key_desc = "name"; parm.align->required = NO; parm.align->multiple = NO; parm.align->type = TYPE_STRING; parm.align->description = _("Adjust region cells to cleanly align with this raster map"); parm.align->gisprompt = "old,cell,raster"; parm.align->guisection = _("Bounds"); parm.save = G_define_option(); parm.save->key = "save"; parm.save->key_desc = "name"; parm.save->required = NO; parm.save->multiple = NO; parm.save->type = TYPE_STRING; parm.save->description = _("Save current region settings in named region file"); parm.save->gisprompt = "new,windows,region"; parm.save->guisection = _("Effects"); G_option_required(flag.dflt, flag.savedefault, flag.print, flag.lprint, flag.eprint, flag.center, flag.gmt_style, flag.wms_style, flag.dist_res, flag.nangle, flag. z, flag.bbox, flag.gprint, flag.res_set, flag.update, parm.region, parm.raster, parm.raster3d, parm.vect, parm.north, parm.south, parm.east, parm.west, parm.top, parm.bottom, parm.rows, parm.cols, parm.res, parm.res3, parm.nsres, parm.ewres, parm.tbres, parm.zoom, parm.align, parm.save, NULL); if (G_parser(argc, argv)) exit(EXIT_FAILURE); G_get_default_window(&window); set_flag = !flag.update->answer; flat_flag = flag.flprint->answer; if (flag.print->answer) print_flag |= PRINT_REG; if (flag.gprint->answer) print_flag |= PRINT_SH; if (flag.lprint->answer) print_flag |= PRINT_LL; if (flag.eprint->answer) print_flag |= PRINT_EXTENT; if (flag.center->answer) print_flag |= PRINT_CENTER; if (flag.gmt_style->answer) print_flag |= PRINT_GMT; if (flag.wms_style->answer) print_flag |= PRINT_WMS; if (flag.nangle->answer) print_flag |= PRINT_NANGLE; if (flag.dist_res->answer) print_flag |= PRINT_METERS; if (flag.z->answer) print_flag |= PRINT_3D; if (flag.bbox->answer) print_flag |= PRINT_MBBOX; if (print_flag == PRINT_METERS) print_flag |= PRINT_SH; if (print_flag == PRINT_SH || print_flag & PRINT_3D || print_flag == PRINT_METERS + PRINT_SH) { print_flag |= PRINT_REG; } if (!flag.dflt->answer) G_get_window(&window); /* region= */ if ((name = parm.region->answer)) { mapset = G_find_file2("windows", name, ""); if (!mapset) G_fatal_error(_("Region <%s> not found"), name); G_get_element_window(&window, "windows", name, mapset); } /* raster= */ if (parm.raster->answer) { int first = 0; rast_ptr = parm.raster->answers; for (; *rast_ptr != NULL; rast_ptr++) { char rast_name[GNAME_MAX]; strcpy(rast_name, *rast_ptr); mapset = G_find_raster2(rast_name, ""); if (!mapset) G_fatal_error(_("Raster map <%s> not found"), rast_name); Rast_get_cellhd(rast_name, mapset, &temp_window); if (!first) { window = temp_window; first = 1; } else { window.north = (window.north > temp_window.north) ? window.north : temp_window.north; window.south = (window.south < temp_window.south) ? window.south : temp_window.south; window.east = (window.east > temp_window.east) ? window.east : temp_window.east; window.west = (window.west < temp_window.west) ? window.west : temp_window.west; } } G_adjust_Cell_head3(&window, 0, 0, 0); } /* raster3d= */ if ((name = parm.raster3d->answer)) { RASTER3D_Region win; if ((mapset = G_find_raster3d(name, "")) == NULL) G_fatal_error(_("3D raster map <%s> not found"), name); if (Rast3d_read_region_map(name, mapset, &win) < 0) G_fatal_error(_("Unable to read header of 3D raster map <%s@%s>"), name, mapset); Rast3d_region_to_cell_head(&win, &window); } /* vector= */ if (parm.vect->answer) { int first = 0; vect_ptr = parm.vect->answers; for (; *vect_ptr != NULL; vect_ptr++) { struct Map_info Map; struct bound_box box; char vect_name[GNAME_MAX]; struct Cell_head map_window; strcpy(vect_name, *vect_ptr); mapset = G_find_vector2(vect_name, ""); if (!mapset) G_fatal_error(_("Vector map <%s> not found"), vect_name); temp_window = window; Vect_set_open_level(2); if (2 > Vect_open_old_head(&Map, vect_name, mapset)) G_fatal_error(_("Unable to open vector map <%s> on topological level"), vect_name); Vect_get_map_box(&Map, &box); map_window = window; map_window.north = box.N; map_window.south = box.S; map_window.west = box.W; map_window.east = box.E; map_window.top = box.T; map_window.bottom = box.B; if (!first) { window = map_window; first = 1; } else { window.north = (window.north > map_window.north) ? window.north : map_window.north; window.south = (window.south < map_window.south) ? window.south : map_window.south; window.east = (window.east > map_window.east) ? window.east : map_window.east; window.west = (window.west < map_window.west) ? window.west : map_window.west; if (map_window.top > window.top) window.top = map_window.top; if (map_window.bottom < window.bottom) window.bottom = map_window.bottom; } if (window.north == window.south) { window.north = window.north + 0.5 * temp_window.ns_res; window.south = window.south - 0.5 * temp_window.ns_res; } if (window.east == window.west) { window.west = window.west - 0.5 * temp_window.ew_res; window.east = window.east + 0.5 * temp_window.ew_res; } if (window.top == window.bottom) { window.bottom = (window.bottom - 0.5 * temp_window.tb_res); window.top = (window.top + 0.5 * temp_window.tb_res); } if (flag.res_set->answer) Rast_align_window(&window, &temp_window); Vect_close(&Map); } } /* n= */ if ((value = parm.north->answer)) { if ((i = nsew(value, "n+", "n-", "s+"))) { if (!G_scan_resolution(value + 2, &x, window.proj)) die(parm.north); switch (i) { case 1: window.north += x; break; case 2: window.north -= x; break; case 3: window.north = window.south + x; break; } } else if (G_scan_northing(value, &x, window.proj)) window.north = x; else die(parm.north); } /* s= */ if ((value = parm.south->answer)) { if ((i = nsew(value, "s+", "s-", "n-"))) { if (!G_scan_resolution(value + 2, &x, window.proj)) die(parm.south); switch (i) { case 1: window.south += x; break; case 2: window.south -= x; break; case 3: window.south = window.north - x; break; } } else if (G_scan_northing(value, &x, window.proj)) window.south = x; else die(parm.south); } /* e= */ if ((value = parm.east->answer)) { if ((i = nsew(value, "e+", "e-", "w+"))) { if (!G_scan_resolution(value + 2, &x, window.proj)) die(parm.east); switch (i) { case 1: window.east += x; break; case 2: window.east -= x; break; case 3: window.east = window.west + x; break; } } else if (G_scan_easting(value, &x, window.proj)) window.east = x; else die(parm.east); } /* w= */ if ((value = parm.west->answer)) { if ((i = nsew(value, "w+", "w-", "e-"))) { if (!G_scan_resolution(value + 2, &x, window.proj)) die(parm.west); switch (i) { case 1: window.west += x; break; case 2: window.west -= x; break; case 3: window.west = window.east - x; break; } } else if (G_scan_easting(value, &x, window.proj)) window.west = x; else die(parm.west); } /* t= */ if ((value = parm.top->answer)) { if ((i = nsew(value, "t+", "t-", "b+"))) { if (sscanf(value + 2, "%lf", &x) != 1) die(parm.top); switch (i) { case 1: window.top += x; break; case 2: window.top -= x; break; case 3: window.top = window.bottom + x; break; } } else if (sscanf(value, "%lf", &x) == 1) window.top = x; else die(parm.top); } /* b= */ if ((value = parm.bottom->answer)) { if ((i = nsew(value, "b+", "b-", "t-"))) { if (sscanf(value + 2, "%lf", &x) != 1) die(parm.bottom); switch (i) { case 1: window.bottom += x; break; case 2: window.bottom -= x; break; case 3: window.bottom = window.top - x; break; } } else if (sscanf(value, "%lf", &x) == 1) window.bottom = x; else die(parm.bottom); } /* res= */ if ((value = parm.res->answer)) { if (!G_scan_resolution(value, &x, window.proj)) die(parm.res); window.ns_res = x; window.ew_res = x; if (flag.res_set->answer) { window.north = ceil(window.north / x) * x; window.south = floor(window.south / x) * x; window.east = ceil(window.east / x) * x; window.west = floor(window.west / x) * x; } } /* res3= */ if ((value = parm.res3->answer)) { if (!G_scan_resolution(value, &x, window.proj)) die(parm.res); window.ns_res3 = x; window.ew_res3 = x; window.tb_res = x; } /* nsres= */ if ((value = parm.nsres->answer)) { if (!G_scan_resolution(value, &x, window.proj)) die(parm.nsres); window.ns_res = x; if (flag.res_set->answer) { window.north = ceil(window.north / x) * x; window.south = floor(window.south / x) * x; } } /* ewres= */ if ((value = parm.ewres->answer)) { if (!G_scan_resolution(value, &x, window.proj)) die(parm.ewres); window.ew_res = x; if (flag.res_set->answer) { window.east = ceil(window.east / x) * x; window.west = floor(window.west / x) * x; } } /* tbres= */ if ((value = parm.tbres->answer)) { if (sscanf(value, "%lf", &x) != 1) die(parm.tbres); window.tb_res = x; if (flag.res_set->answer) { window.top = ceil(window.top / x) * x; window.bottom = floor(window.bottom / x) * x; } } /* rows= */ if ((value = parm.rows->answer)) { if (sscanf(value, "%i", &ival) != 1) die(parm.rows); window.rows = ival; row_flag = 1; } /* cols= */ if ((value = parm.cols->answer)) { if (sscanf(value, "%i", &ival) != 1) die(parm.cols); window.cols = ival; col_flag = 1; } /* zoom= */ if ((name = parm.zoom->answer)) { mapset = G_find_raster2(name, ""); if (!mapset) G_fatal_error(_("Raster map <%s> not found"), name); zoom(&window, name, mapset); } /* align= */ if ((name = parm.align->answer)) { mapset = G_find_raster2(name, ""); if (!mapset) G_fatal_error(_("Raster map <%s> not found"), name); Rast_get_cellhd(name, mapset, &temp_window); Rast_align_window(&window, &temp_window); } /* save= */ if ((name = parm.save->answer)) { temp_window = window; G_adjust_Cell_head3(&temp_window, 0, 0, 0); if (G_put_element_window(&temp_window, "windows", name) < 0) G_fatal_error(_("Unable to set region <%s>"), name); } G_adjust_Cell_head3(&window, row_flag, col_flag, 0); if (set_flag) { if (G_put_window(&window) < 0) G_fatal_error(_("Unable to update current region")); } if (flag.savedefault->answer) { if (strcmp(G_mapset(), "PERMANENT") == 0) { G_put_element_window(&window, "", "DEFAULT_WIND"); } else { G_fatal_error(_("Unable to change default region. " "The current mapset is not <PERMANENT>.")); } } /* / flag.savedefault->answer */ if (print_flag) print_window(&window, print_flag, flat_flag); exit(EXIT_SUCCESS); }
int G_get_3dview(const char *fname, const char *mapset, struct G_3dview *View) { struct Cell_head curwin; FILE *fp; char buffer[80], keystring[24], boo[8], nbuf[128], ebuf[128]; int lap, v_maj, v_min, wind_keys = 0, reqkeys = 0; int current = 0; /* current version flag */ mapset = G_find_file2("3d.view", fname, mapset); if (mapset != NULL) { if (NULL == (fp = G_fopen_old("3d.view", fname, mapset))) { G_warning(_("Unable to open %s for reading"), fname); return (-1); } G_get_set_window(&curwin); G_get_3dview_defaults(View, &curwin); if (NULL != fgets(buffer, 80, fp)) { if (buffer[0] != '#') { /* old d.3d format */ rewind(fp); if (0 <= read_old_format(View, fp)) return (0); else return (-1); } else { sscanf(buffer, "#%d.%d\n", &v_maj, &v_min); if (v_maj == vers_major && v_min == vers_minor) current = 1; /* same version */ } } while (NULL != fgets(buffer, 75, fp)) { if (buffer[0] != '#') { sscanf(buffer, "%[^:]:", keystring); if (!strcmp(keystring, "PGM_ID")) { sscanf(buffer, "%*s%s", (View->pgm_id)); continue; } if (!strcmp(keystring, "north")) { sscanf(buffer, "%*s%lf", &(View->vwin.north)); ++wind_keys; continue; } if (!strcmp(keystring, "south")) { sscanf(buffer, "%*s%lf", &(View->vwin.south)); ++wind_keys; continue; } if (!strcmp(keystring, "east")) { sscanf(buffer, "%*s%lf", &(View->vwin.east)); ++wind_keys; continue; } if (!strcmp(keystring, "west")) { sscanf(buffer, "%*s%lf", &(View->vwin.west)); ++wind_keys; continue; } if (!strcmp(keystring, "rows")) { sscanf(buffer, "%*s%d", &(View->vwin.rows)); ++wind_keys; continue; } if (!strcmp(keystring, "cols")) { sscanf(buffer, "%*s%d", &(View->vwin.cols)); ++wind_keys; continue; } if (!strcmp(keystring, "TO_EASTING")) { sscanf(buffer, "%*s%f", &(View->from_to[1][0])); ++reqkeys; continue; } if (!strcmp(keystring, "TO_NORTHING")) { sscanf(buffer, "%*s%f", &(View->from_to[1][1])); ++reqkeys; continue; } if (!strcmp(keystring, "TO_HEIGHT")) { sscanf(buffer, "%*s%f", &(View->from_to[1][2])); ++reqkeys; continue; } if (!strcmp(keystring, "FROM_EASTING")) { sscanf(buffer, "%*s%f", &(View->from_to[0][0])); ++reqkeys; continue; } if (!strcmp(keystring, "FROM_NORTHING")) { sscanf(buffer, "%*s%f", &(View->from_to[0][1])); ++reqkeys; continue; } if (!strcmp(keystring, "FROM_HEIGHT")) { sscanf(buffer, "%*s%f", &(View->from_to[0][2])); ++reqkeys; continue; } if (!strcmp(keystring, "Z_EXAG")) { sscanf(buffer, "%*s%f", &(View->exag)); ++reqkeys; continue; } if (!strcmp(keystring, "MESH_FREQ")) { sscanf(buffer, "%*s%d", &(View->mesh_freq)); continue; } if (!strcmp(keystring, "POLY_RES")) { sscanf(buffer, "%*s%d", &(View->poly_freq)); continue; } if (!strcmp(keystring, "DOAVG")) { sscanf(buffer, "%*s%d", &(View->doavg)); continue; } if (!strcmp(keystring, "FIELD_VIEW")) { sscanf(buffer, "%*s%f", &(View->fov)); ++reqkeys; continue; } if (!strcmp(keystring, "TWIST")) { sscanf(buffer, "%*s%f", &(View->twist)); continue; } if (!strcmp(keystring, "DISPLAY_TYPE")) { sscanf(buffer, "%*s%d", &View->display_type); continue; } if (!strcmp(keystring, "DOZERO")) { sscanf(buffer, "%*s%s", boo); View->dozero = get_bool(boo); continue; } if (!strcmp(keystring, "COLORGRID")) { sscanf(buffer, "%*s%s", boo); View->colorgrid = get_bool(boo); continue; } if (!strcmp(keystring, "FRINGE")) { sscanf(buffer, "%*s%s", boo); View->fringe = get_bool(boo); continue; } if (!strcmp(keystring, "SHADING")) { sscanf(buffer, "%*s%s", boo); View->shading = get_bool(boo); continue; } if (!strcmp(keystring, "BG_COL")) { sscanf(buffer, "%*s%s", View->bg_col); continue; } if (!strcmp(keystring, "GRID_COL")) { sscanf(buffer, "%*s%s", View->grid_col); continue; } if (!strcmp(keystring, "OTHER_COL")) { sscanf(buffer, "%*s%s", View->other_col); continue; } if (!strcmp(keystring, "SURFACEONLY")) { sscanf(buffer, "%*s%s", boo); View->surfonly = get_bool(boo); continue; } if (!strcmp(keystring, "LIGHTS_ON")) { sscanf(buffer, "%*s%s", boo); View->lightson = get_bool(boo); continue; } if (!strcmp(keystring, "LIGHTPOS")) { sscanf(buffer, "%*s%f%f%f%f", &(View->lightpos[0]), &(View->lightpos[1]), &(View->lightpos[2]), &(View->lightpos[3])); continue; } if (!strcmp(keystring, "LIGHTCOL")) { sscanf(buffer, "%*s%f%f%f", &(View->lightcol[0]), &(View->lightcol[1]), &(View->lightcol[2])); continue; } if (!strcmp(keystring, "LIGHTAMBIENT")) { sscanf(buffer, "%*s%f", &(View->ambient)); continue; } if (!strcmp(keystring, "SHINE")) { sscanf(buffer, "%*s%f", &(View->shine)); continue; } } } fclose(fp); if (reqkeys != REQ_KEYS) /* required keys not found */ return (-1); /* fill rest of View->vwin */ if (wind_keys == 6) { View->vwin.ew_res = (View->vwin.east - View->vwin.west) / View->vwin.cols; View->vwin.ns_res = (View->vwin.north - View->vwin.south) / View->vwin.rows; } else return (0); /* older format */ if (!Suppress_warn) { if (95 > (lap = compare_wind(&(View->vwin), &curwin))) { fprintf(stderr, _("GRASS window when view was saved:\n")); G_format_northing(View->vwin.north, nbuf, G_projection()); fprintf(stderr, "north: %s\n", nbuf); G_format_northing(View->vwin.south, nbuf, G_projection()); fprintf(stderr, "south: %s\n", nbuf); G_format_easting(View->vwin.east, ebuf, G_projection()); fprintf(stderr, "east: %s\n", ebuf); G_format_easting(View->vwin.west, ebuf, G_projection()); fprintf(stderr, "west: %s\n", ebuf); pr_winerr(lap, fname); } } } else { G_warning(_("Unable to open %s for reading"), fname); return (-1); } if (current) return (2); return (1); }
int main(int argc, char *argv[]) { char file[GPATH_MAX], name[GNAME_MAX]; const char *search_mapset, *mapset; struct GModule *module; struct Option *elem_opt; struct Option *mapset_opt; struct Option *file_opt; struct Flag *n_flag, *l_flag; module = G_define_module(); G_add_keyword(_("general")); G_add_keyword(_("map management")); G_add_keyword(_("data base files")); module->description = _("Searches for GRASS data base files " "and sets variables for the shell."); G_gisinit(argv[0]); /* Define the different options */ elem_opt = G_define_option(); elem_opt->key = "element"; elem_opt->type = TYPE_STRING; elem_opt->required = YES; elem_opt->description = _("Name of an element"); file_opt = G_define_option(); file_opt->key = "file"; file_opt->type = TYPE_STRING; file_opt->required = YES; file_opt->description = _("Name of an existing map"); mapset_opt = G_define_option(); mapset_opt->key = "mapset"; mapset_opt->type = TYPE_STRING; mapset_opt->required = NO; mapset_opt->label = _("Name of a mapset (default: search path)"); mapset_opt->description = _("'.' for current mapset"); n_flag = G_define_flag(); n_flag->key = 'n'; n_flag->description = _("Don't add quotes"); l_flag = G_define_flag(); l_flag->key = 'l'; l_flag->description = _("List available elements and exit"); l_flag->suppress_required = YES; if (G_parser(argc, argv)) exit(EXIT_FAILURE); if (l_flag->answer) { list_elements(); return EXIT_SUCCESS; } search_mapset = mapset_opt->answer; if (!search_mapset) { search_mapset = G_store(""); } if (strcmp(".", search_mapset) == 0) search_mapset = G_mapset(); if (mapset_opt->answer && strlen(mapset_opt->answer) > 0) { char **map_mapset = G_tokenize(file_opt->answer, "@"); if (G_number_of_tokens(map_mapset) > 1) { if (strcmp(map_mapset[1], mapset_opt->answer)) G_fatal_error(_("Parameter 'file' contains reference to <%s> mapset, " "but mapset parameter <%s> does not correspond"), map_mapset[1], mapset_opt->answer); else strcpy(name, file_opt->answer); } if (G_number_of_tokens(map_mapset) == 1) strcpy(name, file_opt->answer); G_free_tokens(map_mapset); } else strcpy(name, file_opt->answer); mapset = G_find_file2(elem_opt->answer, name, search_mapset); if (mapset) { char xname[GNAME_MAX], xmapset[GMAPSET_MAX]; const char *qchar = n_flag->answer ? "" : "'"; const char *qual = G_fully_qualified_name(name, mapset); G_unqualified_name(name, mapset, xname, xmapset); G_file_name(file, elem_opt->answer, name, mapset); fprintf(stdout, "name=%s%s%s\n", qchar, xname, qchar); fprintf(stdout, "mapset=%s%s%s\n", qchar, xmapset, qchar); fprintf(stdout, "fullname=%s%s%s\n", qchar, qual, qchar); fprintf(stdout, "file=%s%s%s\n", qchar, file, qchar); return EXIT_SUCCESS; } else { fprintf(stdout, "name=\n"); fprintf(stdout, "mapset=\n"); fprintf(stdout, "fullname=\n"); fprintf(stdout, "file=\n"); } return EXIT_FAILURE; }
/*! \brief Load 3dview \param vname view name \param gv pointer to geoview struct \param gd pointer to geodisplay struct \param w current window \param defsurf default geosurf struct \return 1 */ int Gs_load_3dview(const char *vname, geoview * gv, geodisplay * gd, struct Cell_head *w, geosurf * defsurf) { const char *mapset; struct G_3dview v; int ret = -1; float pt[3]; mapset = G_find_file2("3d.view", vname, ""); if (mapset != NULL) { ret = G_get_3dview(vname, mapset, &v); } if (ret >= 0) { if (strcmp((v.pgm_id), "Nvision-ALPHA!")) { G_warning(_("View not saved by this program," "there may be some inconsistancies")); } /* set poly and mesh resolutions */ v.mesh_freq = (int)(v.mesh_freq * v.vwin.ns_res / w->ns_res); v.poly_freq = (int)(v.poly_freq * v.vwin.ns_res / w->ns_res); /* Set To and FROM positions */ /* TO */ pt[0] = (v.from_to[TO][X] - w->west) - w->ew_res / 2.; pt[1] = (v.from_to[TO][Y] - w->south) - w->ns_res / 2.; pt[2] = v.from_to[TO][Z]; GS_set_focus(pt); /* FROM */ pt[0] = (float)v.from_to[FROM][X]; pt[1] = (float)v.from_to[FROM][Y]; pt[2] = (float)v.from_to[FROM][Z]; GS_moveto_real(pt); if (defsurf) { int dmode = 0; GS_setall_drawres(v.poly_freq, v.poly_freq, v.mesh_freq, v.mesh_freq); while (v.display_type >= 10) { /* globe stuff not used */ v.display_type -= 10; } /* set drawing modes */ if (v.colorgrid) { dmode |= DM_COL_WIRE; } if (v.shading) { dmode |= DM_GOURAUD; } switch (v.display_type) { case 1: dmode |= DM_WIRE; break; case 2: dmode |= DM_POLY; break; case 3: dmode |= DM_WIRE_POLY; break; } GS_setall_drawmode(dmode); /* should also set nozeros here */ } /* set exaggeration */ if (v.exag) GS_set_global_exag(v.exag); /* Set FOV */ if (v.fov) { GS_set_fov((int) (v.fov > 0 ? v.fov * 10. + 0.5 : v.fov * 10. - 0.5)); } else { /* TODO: do ortho */ } /* Set twist */ if (v.twist) GS_set_twist((int)(v.twist > 0 ? v.twist + 0.5 : v.twist - 0.5)); /* TODO: OK to here - need to unravel/reverse lights stuff*** */ if (v.lightson) { /* Lights are on */ /* Light Position */ gv->lights[0].position[X] = v.lightpos[X]; gv->lights[0].position[Y] = v.lightpos[Y]; gv->lights[0].position[Z] = v.lightpos[Z]; /* Light Color */ gv->lights[0].color[0] = v.lightcol[0]; gv->lights[0].color[1] = v.lightcol[1]; gv->lights[0].color[2] = v.lightcol[2]; /* Light Shininess */ gv->lights[0].shine = v.shine; /* Light Ambient */ gv->lights[0].ambient[0] = gv->lights[0].ambient[1] = gv->lights[0].ambient[2] = v.ambient * 3.; } /* Done with lights */ GS_alldraw_wire(); } /* Done with file */ return (1); }
int main(int argc, char *argv[]) { char file[GPATH_MAX], name[GNAME_MAX], *mapset; char *search_mapset; struct GModule *module; struct Option *elem_opt; struct Option *mapset_opt; struct Option *file_opt; struct Flag *n_flag; module = G_define_module(); module->keywords = _("general, map management"); module->description = _("Searches for GRASS data base files " "and sets variables for the shell."); G_gisinit(argv[0]); /* Define the different options */ elem_opt = G_define_option(); elem_opt->key = "element"; elem_opt->type = TYPE_STRING; elem_opt->required = YES; elem_opt->description = _("Name of an element"); file_opt = G_define_option(); file_opt->key = "file"; file_opt->type = TYPE_STRING; file_opt->required = YES; file_opt->description = _("Name of an existing map"); mapset_opt = G_define_option(); mapset_opt->key = "mapset"; mapset_opt->type = TYPE_STRING; mapset_opt->required = NO; mapset_opt->description = _("Name of a mapset"); mapset_opt->answer = ""; n_flag = G_define_flag(); n_flag->key = 'n'; n_flag->description = _("Don't add quotes"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); search_mapset = mapset_opt->answer; if (strcmp(".", search_mapset) == 0) search_mapset = G_mapset(); if (mapset_opt->answer && strlen(mapset_opt->answer) > 0) { char **map_mapset = G_tokenize(file_opt->answer, "@"); if (G_number_of_tokens(map_mapset) > 1) { if (strcmp(map_mapset[1], mapset_opt->answer)) G_fatal_error(_("Parameter 'file' contains reference to <%s> mapset, " "but mapset parameter <%s> does not correspond"), map_mapset[1], mapset_opt->answer); else strcpy(name, file_opt->answer); } if (G_number_of_tokens(map_mapset) == 1) strcpy(name, file_opt->answer); G_free_tokens(map_mapset); } else strcpy(name, file_opt->answer); mapset = G_find_file2(elem_opt->answer, name, search_mapset); if (mapset) { const char *qchar = n_flag->answer ? "" : "'"; const char *qual = G_fully_qualified_name(name, mapset); G__file_name(file, elem_opt->answer, name, mapset); fprintf(stdout, "name=%s%s%s\n", qchar, name, qchar); fprintf(stdout, "mapset=%s%s%s\n", qchar, mapset, qchar); fprintf(stdout, "fullname=%s%s%s\n", qchar, qual, qchar); fprintf(stdout, "file=%s%s%s\n", qchar, file, qchar); } else { fprintf(stdout, "name=\n"); fprintf(stdout, "mapset=\n"); fprintf(stdout, "fullname=\n"); fprintf(stdout, "file=\n"); } exit(mapset == NULL); }