[GRASS-windows] Re: r.sim.water

Markus Neteler neteler at osgeo.org
Sat Sep 13 04:37:16 EDT 2008


On Sat, Sep 13, 2008 at 2:18 AM, Glynn Clements
<glynn at gclements.plus.com> wrote:
>
> Markus Neteler wrote:
>
>> > thanks for testing - I think simwe has a problem on MSwindows due to
>> > the problem with sites to vector update - that is why Glynn has disabled
>> > it.
>>
>> when was it disabled (don't remember)? Post-6.3.?
>
> Only in 7.x.
>
> The compatibility wrappers use a "FILE *" in their interfaces, which
> is cast to/from a "struct Map_info *" internally. In 7.x, I changed
> this to use the correct type, and changed any code which uses those
> functions.

This had been backported to 6.4.svn.

> Except that simwe has some mismatches, e.g. using G_sites_close() on a
> normal text file and using fclose() on a "pseudo-FILE*". With the
> changes to lib/sites, simwe doesn't compile, and I couldn't understand
> the code well enough to fix it, so I disabled it.

I have now backported small fixes (essentially code order to do some
computations post-parser instead of ante-parser. But that's not
relevant.

I have now compared simwe/ in 6.3.svn (after updating the code
layout there to the new rules) to 6.4.svn. Besides above mentioned
core-reorder, the only difference is:

diff -ru --exclude=.svn
/home/neteler/grass63_release/raster/simwe/simlib/output.c
simwe/simlib/output.c
--- /home/neteler/grass63_release/raster/simwe/simlib/output.c	2008-09-13
10:28:51.000000000 +0200
+++ simwe/simlib/output.c	2008-08-05 00:05:02.000000000 +0200
@@ -57,6 +57,8 @@
 	if (fdoutwalk == NULL)
 	    G_fatal_error("Cannot open %s", outwalk);
 	else {
+	    char buf[GNAME_MAX + 40];
+
 	    if (NULL == (sd = G_site_new_struct(-1, 2, 0, 1)))
 		G_fatal_error("memory allocation failed for site");

@@ -65,9 +67,8 @@
 	    else
 		walkershead.name = outwalk;

-	    walkershead.desc = G_strdup("output walkers");
-	    walkershead.desc = (char *)G_malloc(128 * sizeof(char));
-	    sprintf(walkershead.desc, "output walkers of %s [raster]", depth);
+	    sprintf(buf, "output walkers of %s [raster]", depth);
+	    walkershead.desc = G_store(buf);
 	    walkershead.time = NULL;
 	    walkershead.stime = NULL;
 	    walkershead.labels = NULL;

Could this missing update in 6.3.svn cause a crash on Windows?

A real candidate is the update to lib/sites/sites.c which isn't in GRASS 6.3.svn
yet:

--- /home/neteler/grass63_release/lib/sites/sites.c	2008-09-13
10:34:16.000000000 +0200
+++ ../lib/sites/sites.c	2008-08-05 00:05:18.000000000 +0200
@@ -50,16 +50,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)
@@ -115,14 +112,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)
@@ -156,12 +150,9 @@
  *                      -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;
@@ -184,13 +175,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);

@@ -223,7 +211,8 @@
 		    return -1;	/* added to prevent crash 5/2000 MN */
 		}
 	    }
-	    G_format_timestamp(head->time, head->stime);
+	    G_format_timestamp(head->time, buf);
+	    head->stime = G_store(buf);
 	    Vect_set_date(Map, head->stime);
 	}
     }
@@ -234,12 +223,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;
@@ -293,11 +278,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
  *
@@ -343,7 +328,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;
@@ -376,7 +361,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);
@@ -476,11 +461,11 @@
     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;

@@ -494,16 +479,13 @@

     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);
@@ -530,19 +512,19 @@
 /* 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.");
@@ -551,7 +533,8 @@
 }


-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,20 +1192,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);
@@ -1233,13 +1209,13 @@

    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;

-    char *name;
+    const char *name;
     dbDriver *driver;
     dbString stmt;
     dbCursor cursor;
@@ -1254,7 +1230,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);

On the other hand, fixing 6.3.svn is a waste of time since we'll
branch of a release branch for 6.4.svn soon. Then release
candidates will be created and hopefully a new WinGRASS package.

> [It doesn't help that there are various other problems with the code,
> e.g. each module having a private copy of waterglobs.h which doesn't
> necessarily match simlib.]

Markus


More information about the grass-windows mailing list