[GRASS-SVN] r31995 - in grass/trunk: include lib/sites raster raster/r.cost raster/r.drain raster/r.volume raster/r.walk visualization/nviz/src

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 4 16:56:46 EDT 2008


Author: glynn
Date: 2008-07-04 16:56:45 -0400 (Fri, 04 Jul 2008)
New Revision: 31995

Modified:
   grass/trunk/include/P_site.h
   grass/trunk/lib/sites/sites.c
   grass/trunk/raster/Makefile
   grass/trunk/raster/r.cost/main.c
   grass/trunk/raster/r.drain/main.c
   grass/trunk/raster/r.volume/main.c
   grass/trunk/raster/r.walk/main.c
   grass/trunk/visualization/nviz/src/site_attr_commands.c
Log:
Elminate FILE* <-> struct Map_info* hack from sites library
Use "const" where appropriate in sites library
Disable raster/simwe as it's too badly broken


Modified: grass/trunk/include/P_site.h
===================================================================
--- grass/trunk/include/P_site.h	2008-07-04 19:52:02 UTC (rev 31994)
+++ grass/trunk/include/P_site.h	2008-07-04 20:56:45 UTC (rev 31995)
@@ -2,6 +2,8 @@
 #ifndef GRASS_P_SITE_H
 #define GRASS_P_SITE_H
 
+struct Map_info;
+
 /* The same for old and new, format independent */
 Site *G_site_new_struct (RASTER_MAP_TYPE cattype, int ndim, int ns, int nd);
 void G_site_free_struct (Site *s);
@@ -10,8 +12,8 @@
 int G_site_c_cmp (const void *a, const void *b);
 int G_site_s_cmp (const void *a, const void *b);
 char *G_site_format (const Site *s, const char *fs, int id);
-/* SITE_ATT * G_sites_get_atts (FILE * ptr, int* cat);*/
-int G_sites_get_fields (FILE * ptr, char*** cnames, int** ctypes, int** ndx);
+/* SITE_ATT * G_sites_get_atts (struct Map_info * ptr, int* cat);*/
+int G_sites_get_fields (struct Map_info * ptr, char*** cnames, int** ctypes, int** ndx);
 void G_sites_free_fields (int ncols, char** cnames, int* ctypes, int* ndx);
 
 /* Old version used by v.in.sites */
@@ -21,25 +23,25 @@
 int G__oldsite_get ( FILE *, Site *, int);
 
 /* New version based on vectors used in old, not updated sites modules */
-int G_site_get (FILE *p, Site *s);
-int G_site_put (FILE *p, const Site *s);
-int G_site_describe (FILE *p, int *dims, int *cat, int *strs, int *dbls);
-int G_site_get_head (FILE *p, Site_head *head);
-int G_site_put_head (FILE *p, Site_head *head);
-FILE * G_sites_open_old (char *name, char *mapset);
-FILE * G_sites_open_new (char *name);
-void G_sites_close ( FILE * );
+int G_site_get (struct Map_info *p, Site *s);
+int G_site_put (struct Map_info *p, const Site *s);
+int G_site_describe (struct Map_info *p, int *dims, int *cat, int *strs, int *dbls);
+int G_site_get_head (struct Map_info *p, Site_head *head);
+int G_site_put_head (struct Map_info *p, Site_head *head);
+struct Map_info * G_sites_open_old (const char *name, const char *mapset);
+struct Map_info * G_sites_open_new (const char *name);
+void G_sites_close ( struct Map_info * );
 char * G_find_sites (char *name, const char *mapset);
 char * G_find_sites2 (const char *name, const char *mapset);
 char * G_ask_sites_new (const char *prompt, char *name);
 char * G_ask_sites_old (const char *prompt, char *name);
 char * G_ask_sites_any (const char *prompt, char *name);
 char * G_ask_sites_in_mapset (const char *prompt, char *name);
-int G__site_put ( FILE *, Site *, int);
+int G__site_put ( struct Map_info *, Site *, int);
 
-FILE *G_fopen_sites_old(char *, char *);
-FILE *G_fopen_sites_new(char *);
-int G_get_site(FILE *, double *, double *, char **);
-int G_put_site(FILE *, double, double, const char *);
+struct Map_info *G_fopen_sites_old(const char *, const char *);
+struct Map_info *G_fopen_sites_new(const char *);
+int G_get_site(struct Map_info *, double *, double *, char **);
+int G_put_site(struct Map_info *, double, double, const char *);
 
 #endif

Modified: grass/trunk/lib/sites/sites.c
===================================================================
--- grass/trunk/lib/sites/sites.c	2008-07-04 19:52:02 UTC (rev 31994)
+++ grass/trunk/lib/sites/sites.c	2008-07-04 20:56:45 UTC (rev 31995)
@@ -48,16 +48,13 @@
  *                      -2 on other fatal error or insufficient data,
  *                       1 on format mismatch (extra data)
  */
-int G_site_get ( FILE *fptr, Site *s)
+int G_site_get (struct Map_info *Map, Site *s)
 {
     int    i, type, cat;
-    struct Map_info *Map;
     static struct line_pnts *Points = NULL;
     static struct line_cats *Cats = NULL;
     SITE_ATT *sa;
 
-    Map = (struct Map_info *) fptr;
-
     if ( Points == NULL ) Points = Vect_new_line_struct ();
     if ( Cats == NULL ) Cats = Vect_new_cats_struct ();
 
@@ -101,14 +98,11 @@
 
 
 /* Writes a site to file open on fptr. */
-int G_site_put ( FILE *fptr, const Site *s)
+int G_site_put (struct Map_info *Map, const Site *s)
 {
-    struct Map_info *Map;
     static struct line_pnts *Points = NULL;
     static struct line_cats *Cats = NULL;
 
-    Map = (struct Map_info *) fptr;
-
     if ( Points == NULL ) Points = Vect_new_line_struct ();
     if ( Cats == NULL ) Cats = Vect_new_cats_struct ();
 
@@ -140,13 +134,8 @@
  *                      -1 on EOF,
  *                      -2 for other error.
  */
-int G_site_describe ( FILE *ptr,
-  int *dims,int *cat,int *strs,int *dbls)
+int G_site_describe (struct Map_info *Map, int *dims,int *cat,int *strs,int *dbls)
 {
-    struct Map_info *Map;
-
-    Map = (struct Map_info *) ptr;
-    
     if ( Vect_is_3d(Map) ) {
 	G_debug (1, "Vector is 3D -> number of site dimensions is 3");
 	*dims = 3;
@@ -168,13 +157,10 @@
 /*-
  * Writes site_head struct.
  */
-int G_site_put_head ( FILE *ptr, Site_head *head)
+int G_site_put_head ( struct Map_info *Map, Site_head *head)
 {
-    struct Map_info *Map;
     static char buf[128];
 
-    Map = (struct Map_info *) ptr;
-
     if (head->name!=NULL)
 	Vect_set_map_name (Map, head->name);
       
@@ -217,12 +203,8 @@
 /*-
  * Fills in site_head struct.
  */
-int G_site_get_head (FILE *ptr, Site_head *head)
+int G_site_get_head (struct Map_info *Map, Site_head *head)
 {
-    struct Map_info *Map;
-
-    Map = (struct Map_info *) ptr;
-
     head->name = Vect_get_name(Map);
     head->desc = Vect_get_comment(Map);
     head->form = NULL;
@@ -275,11 +257,11 @@
  *      rejects all names that begin with .
  **********************************************************************
  *
- *  FILE *
+ *  struct Map_info *
  *  G_sites_open_old (name, mapset)
  *      opens the existing site list file 'name' in the 'mapset'
  *
- *  FILE *
+ *  struct Map_info *
  *  G_sites_open_new (name)
  *      opens a new site list file 'name' in the current mapset
  *
@@ -325,7 +307,7 @@
 }
 
 
-FILE * G_sites_open_old (char *name,char *mapset)
+struct Map_info * G_sites_open_old (const char *name, const char *mapset)
 {
     struct Map_info *Map;
     struct field_info *fi;
@@ -357,7 +339,7 @@
     fi = Vect_get_field(Map, 1);
     if ( fi == NULL ) {  /* not attribute table */ 
 	G_debug ( 1, "No attribute table" );
-	return (FILE *) Map;
+	return Map;
     }
     
     driver = db_start_driver_open_database ( fi->driver, fi->database );
@@ -453,11 +435,11 @@
     /* sort attributes */
     qsort ( (void *)Map->site_att, Map->n_site_att, sizeof(SITE_ATT), site_att_cmp );
     
-    return (FILE *) Map;
+    return Map;
 }
 
 
-FILE * G_sites_open_new (char *name)
+struct Map_info *G_sites_open_new (const char *name)
 {
     struct Map_info *Map;
     
@@ -470,17 +452,14 @@
 
     G_debug ( 1, "New vector map opened");
 
-    return (FILE *) Map;
+    return Map;
 }
 
 
-void G_sites_close ( FILE * ptr)
+void G_sites_close (struct Map_info *Map)
 {
     int i, j;
-    struct Map_info *Map;
 
-    Map = (struct Map_info *) ptr;
-
     if (Map->mode == GV_MODE_WRITE || Map->mode == GV_MODE_RW)
 	Vect_build (Map, stderr);
     
@@ -505,19 +484,19 @@
 /* They are retained here only for backwards */
 /* compatability while porting applications  */
 /*********************************************/
-FILE *G_fopen_sites_old (char *name, char *mapset)
+struct Map_info *G_fopen_sites_old (const char *name, const char *mapset)
 {
     return G_sites_open_old (name, mapset);
 }
 
 
-FILE *G_fopen_sites_new (char *name)
+struct Map_info *G_fopen_sites_new (const char *name)
 {
     return G_sites_open_new (name);
 }
 
 
-int G_get_site ( FILE *fd, double *east,double *north, char **desc)
+int G_get_site (struct Map_info *fd, double *east,double *north, char **desc)
 {
     /* TODO ? */
     G_fatal_error ( "G_get_site() not yet updated.");
@@ -526,7 +505,7 @@
 }
 
 
-int G_put_site ( FILE *fd, double east,double north, const char *desc)
+int G_put_site (struct Map_info *fd, double east,double north, const char *desc)
 {
     /* TODO ? */
     G_fatal_error ( "G_put_site() not yet updated.");
@@ -1209,19 +1188,13 @@
 
  Functions to obtain fields in order to draw sites with each point having a
  geometric property depending from database values.
-
- IN ALL THESE FUNCTIONS I FOLLOW THE CONVENTION TO PASS Map_info* as FILE*
-  FOR COHERENCE WITH OTHER ALREADY WRITTEN FUNCTION IN sites.c FILE.
 */
 
 /*
  Returns a pointer to the SITE_ATT in Map_info *ptr and with category cat
 */
-SITE_ATT * G_sites_get_atts (FILE * ptr, int* cat)
+SITE_ATT * G_sites_get_atts (struct Map_info *Map, int* cat)
 {
-    struct Map_info *Map;
-    Map = (struct Map_info *) ptr;
-
 	return (SITE_ATT *) bsearch ( (void *) cat, (void *)Map->site_att, Map->n_site_att,
 					 sizeof(SITE_ATT), site_att_cmp );
 }
@@ -1231,9 +1204,8 @@
 
   WARNING: user is responsible to free allocated memory, directly or calling G_sites_free_fields()
 */
-int G_sites_get_fields(FILE * ptr, char*** cnames, int** ctypes, int** ndx)
+int G_sites_get_fields(struct Map_info *Map, char*** cnames, int** ctypes, int** ndx)
 {
-    struct Map_info *Map;
     struct field_info *fi;
     int nrows, row, ncols, col, ndbl, nstr, ctype;
 
@@ -1251,7 +1223,6 @@
 		Should it be not true in the future, maybe we'll have to change this by choosing
 		appropriate fields and multiple categories */
 
-    Map = (struct Map_info *) ptr;
     fi = (struct field_info *)Vect_get_field(Map, 1);
 
 

Modified: grass/trunk/raster/Makefile
===================================================================
--- grass/trunk/raster/Makefile	2008-07-04 19:52:02 UTC (rev 31994)
+++ grass/trunk/raster/Makefile	2008-07-04 20:56:45 UTC (rev 31995)
@@ -106,7 +106,6 @@
 	r.watershed \
 	r.what \
 	r.what.color \
-	simwe \
 	wildfire
 
 GDALBASED = r.in.gdal r.out.gdal

Modified: grass/trunk/raster/r.cost/main.c
===================================================================
--- grass/trunk/raster/r.cost/main.c	2008-07-04 19:52:02 UTC (rev 31994)
+++ grass/trunk/raster/r.cost/main.c	2008-07-04 20:56:45 UTC (rev 31995)
@@ -459,7 +459,7 @@
      */
     if (opt7->answer) {
 #if 1
-	FILE *fp;
+	struct Map_info *fp;
 	struct start_pt *new_start_pt;
 	Site *site = NULL;	/* pointer to Site */
 	int got_one = 0;
@@ -510,7 +510,7 @@
 
     if (opt8->answer) {
 #if 1
-	FILE *fp;
+	struct Map_info *fp;
 	struct start_pt *new_start_pt;
 	Site *site = NULL;	/* pointer to Site */
 	int dims, strs, dbls;

Modified: grass/trunk/raster/r.drain/main.c
===================================================================
--- grass/trunk/raster/r.drain/main.c	2008-07-04 19:52:02 UTC (rev 31994)
+++ grass/trunk/raster/r.drain/main.c	2008-07-04 20:56:45 UTC (rev 31995)
@@ -204,7 +204,7 @@
     }
     if (vpointopt->answer) {
 	for (i = 0; vpointopt->answers[i] != NULL; i++) {
-	    FILE *fp;
+	    struct Map_info *fp;
 	    /* struct start_pt  *new_start_pt; */
 	    Site *site = NULL;	/* pointer to Site */
 	    int dims, strs, dbls;

Modified: grass/trunk/raster/r.volume/main.c
===================================================================
--- grass/trunk/raster/r.volume/main.c	2008-07-04 19:52:02 UTC (rev 31994)
+++ grass/trunk/raster/r.volume/main.c	2008-07-04 20:56:45 UTC (rev 31995)
@@ -42,7 +42,7 @@
     char *curr_mapset, *data_mapset, *clump_mapset;
     double avg, vol, total_vol, east, north, *sum;
     struct Cell_head window;
-    FILE *fd_sites = NULL;
+    struct Map_info *fd_sites = NULL;
     Site *mysite;
     Site_head site_info;
     struct GModule *module;

Modified: grass/trunk/raster/r.walk/main.c
===================================================================
--- grass/trunk/raster/r.walk/main.c	2008-07-04 19:52:02 UTC (rev 31994)
+++ grass/trunk/raster/r.walk/main.c	2008-07-04 20:56:45 UTC (rev 31995)
@@ -393,7 +393,7 @@
 
 
     if (opt7->answer) {
-	FILE *fp;
+	struct Map_info *fp;
 	struct start_pt *new_start_pt;
 	Site *site = NULL;	/* pointer to Site */
 	int dims, strs, dbls;
@@ -439,7 +439,7 @@
     }
 
     if (opt8->answer) {
-	FILE *fp;
+	struct Map_info *fp;
 	struct start_pt *new_start_pt;
 	Site *site = NULL;	/* pointer to Site */
 	int dims, strs, dbls;

Modified: grass/trunk/visualization/nviz/src/site_attr_commands.c
===================================================================
--- grass/trunk/visualization/nviz/src/site_attr_commands.c	2008-07-04 19:52:02 UTC (rev 31994)
+++ grass/trunk/visualization/nviz/src/site_attr_commands.c	2008-07-04 20:56:45 UTC (rev 31995)
@@ -288,7 +288,7 @@
 							float *mr, float *mg, float *mb);
 
 /* better move to ../../../include/P_site.h */
-SITE_ATT * G_sites_get_atts (FILE * ptr, int* cat);
+SITE_ATT * G_sites_get_atts (struct Map_info * ptr, int* cat);
 
 /*******************************************************************************/
 /*******************************************************************************/
@@ -322,7 +322,7 @@
     if (argc != 2) return (TCL_ERROR);
 
 	Map = (struct Map_info *)G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
-	ncols=G_sites_get_fields((FILE *)Map, &cnames, &ctypes, &ndx);
+	ncols=G_sites_get_fields(Map, &cnames, &ctypes, &ndx);
 
 	for(i=0; i<ncols; i++) {
 		sprintf(buf, "%s", cnames[i]);
@@ -354,8 +354,8 @@
 
     if (argc != 2) return (TCL_ERROR);
 
-	Map = (struct Map_info *)G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
-	ncols=G_sites_get_fields((FILE *)Map, &cnames, &ctypes, &ndx);
+	Map = G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
+	ncols=G_sites_get_fields(Map, &cnames, &ctypes, &ndx);
 
 	for(i=0; i<ncols; i++) {
 		sprintf(buf, "%c", ctypes[i]);
@@ -387,8 +387,8 @@
 
     if (argc != 2) return (TCL_ERROR);
 
-	Map = (struct Map_info *)G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
-	ncols=G_sites_get_fields((FILE *)Map, &cnames, &ctypes, &ndx);
+	Map = G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
+	ncols=G_sites_get_fields(Map, &cnames, &ctypes, &ndx);
 
 	for(i=0; i<ncols; i++) {
 		sprintf(buf, "%s", cnames[i]);
@@ -433,8 +433,8 @@
 
 	index=atoi(argv[2]);
 
-	Map = (struct Map_info *)G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
-	ncols=G_sites_get_fields((FILE *)Map, &cnames, &ctypes, &ndx);
+	Map = G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
+	ncols=G_sites_get_fields(Map, &cnames, &ctypes, &ndx);
 
 	for (i=0; i<Map->n_site_att; i++) {
 		sa = &(Map->site_att[i]);
@@ -483,8 +483,8 @@
 
 	index=atoi(argv[2]);
 
-	Map = (struct Map_info *)G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
-	ncols=G_sites_get_fields((FILE *)Map, &cnames, &ctypes, &ndx);
+	Map = G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
+	ncols=G_sites_get_fields(Map, &cnames, &ctypes, &ndx);
 
 	for (i=0; i<Map->n_site_att; i++) {
 		sa = &(Map->site_att[i]);
@@ -534,11 +534,11 @@
 
 	cat=atoi(argv[2]);
 
-	Map = (struct Map_info *)G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
-	ncols=G_sites_get_fields((FILE *)Map, &cnames, &ctypes, &ndx);
+	Map = G_sites_open_old(argv[1], G_find_vector2(argv[1], ""));
+	ncols=G_sites_get_fields(Map, &cnames, &ctypes, &ndx);
 
 
-	if ( (sa = (SITE_ATT *)G_sites_get_atts((FILE *)Map, &cat)) == NULL ) return (TCL_ERROR);
+	if ( (sa = (SITE_ATT *)G_sites_get_atts(Map, &cat)) == NULL ) return (TCL_ERROR);
 
 	for (i=0; i<ncols; i++) {
 		switch(ctypes[i]) {
@@ -606,10 +606,10 @@
 {
 	const char *function_name="site_attr_open_map";
 
-	*Map = (struct Map_info *)G_sites_open_old(gp->filename, G_find_vector2(gp->filename, ""));
+	*Map = G_sites_open_old(gp->filename, G_find_vector2(gp->filename, ""));
 
 	/* this is needed to find association between names and proper indexes/types */
-	*ncols=G_sites_get_fields((FILE *)*Map, cnames, ctypes, ndx);
+	*ncols=G_sites_get_fields(*Map, cnames, ctypes, ndx);
 
 	if (*ncols <= 0) {
 		printf("WARNING / \"%s()\": site \"%s\" database error\n", function_name, gp->filename);
@@ -748,10 +748,10 @@
 			gpt->color[nattr] = attr_eval_color(gpt->cat, n, x, yr, yg, yb, mr, mg, mb);
 		}
 		else if (ctypes[index] == 'd') {
-			if ( (sa = (SITE_ATT *)G_sites_get_atts((FILE *)Map, &(gpt->cat))) == NULL ) continue;
+			if ( (sa = (SITE_ATT *)G_sites_get_atts(Map, &(gpt->cat))) == NULL ) continue;
 			else gpt->color[nattr] = attr_eval_color(sa->dbl[ndx[index]], n, x, yr, yg, yb, mr, mg, mb);
 		} else {
-			if ( (sa = (SITE_ATT *)G_sites_get_atts((FILE *)Map, &(gpt->cat))) == NULL ) continue;
+			if ( (sa = (SITE_ATT *)G_sites_get_atts(Map, &(gpt->cat))) == NULL ) continue;
 			else gpt->color[nattr] = attr_eval_color_string(sa->str[ndx[index]], n, argvX, yr, yg, yb);
 		}
 	}
@@ -783,11 +783,11 @@
 			gpt->size[nattr] = attr_eval_entry(gpt->cat, n, x, y, m);
 		}
 		else if (ctypes[index] == 'd') {
-			if ( (sa = (SITE_ATT *)G_sites_get_atts((FILE *)Map, &(gpt->cat))) == NULL ) continue;
+			if ( (sa = (SITE_ATT *)G_sites_get_atts(Map, &(gpt->cat))) == NULL ) continue;
 			else gpt->size[nattr] = attr_eval_entry(sa->dbl[ndx[index]], n, x, y, m);
 		}
 		else {
-			if ( (sa = (SITE_ATT *)G_sites_get_atts((FILE *)Map, &(gpt->cat))) == NULL ) continue;
+			if ( (sa = (SITE_ATT *)G_sites_get_atts(Map, &(gpt->cat))) == NULL ) continue;
 			else gpt->size[nattr] = attr_eval_entry_string(sa->str[ndx[index]], n, argvX, y);
 		}
 	}



More information about the grass-commit mailing list