[GRASS-SVN] r63216 - in grass/trunk/raster/simwe: r.sim.sediment r.sim.water simlib

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 27 19:39:00 PST 2014


Author: annakrat
Date: 2014-11-27 19:39:00 -0800 (Thu, 27 Nov 2014)
New Revision: 63216

Modified:
   grass/trunk/raster/simwe/r.sim.sediment/main.c
   grass/trunk/raster/simwe/r.sim.water/main.c
   grass/trunk/raster/simwe/simlib/hydro.c
   grass/trunk/raster/simwe/simlib/random.c
   grass/trunk/raster/simwe/simlib/waterglobs.h
Log:
simwe: change random number generator to the standard one, #2272

Modified: grass/trunk/raster/simwe/r.sim.sediment/main.c
===================================================================
--- grass/trunk/raster/simwe/r.sim.sediment/main.c	2014-11-28 02:33:39 UTC (rev 63215)
+++ grass/trunk/raster/simwe/r.sim.sediment/main.c	2014-11-28 03:39:00 UTC (rev 63216)
@@ -102,7 +102,6 @@
     int ii;
     int ret_val;
     static int rand1 = 12345;
-    static int rand2 = 67891;
 
     G_gisinit(argv[0]);
 
@@ -367,7 +366,7 @@
     if (erdep != NULL || et != NULL)
 	er = G_alloc_fmatrix(my, mx);
 
-    seeds(rand1, rand2);
+    G_srand48(rand1);
     grad_check();
 
     if (et != NULL)

Modified: grass/trunk/raster/simwe/r.sim.water/main.c
===================================================================
--- grass/trunk/raster/simwe/r.sim.water/main.c	2014-11-28 02:33:39 UTC (rev 63215)
+++ grass/trunk/raster/simwe/r.sim.water/main.c	2014-11-28 03:39:00 UTC (rev 63216)
@@ -101,7 +101,6 @@
     int ret_val;
     double x_orig, y_orig;
     static int rand1 = 12345;
-    static int rand2 = 67891;
     struct GModule *module;
 
     G_gisinit(argv[0]);
@@ -464,7 +463,7 @@
     dif = G_alloc_fmatrix(my, mx);
 
     G_debug(1, "seeding randoms");
-    seeds(rand1, rand2);
+    G_srand48(rand1);
     grad_check();
     main_loop();
 

Modified: grass/trunk/raster/simwe/simlib/hydro.c
===================================================================
--- grass/trunk/raster/simwe/simlib/hydro.c	2014-11-28 02:33:39 UTC (rev 63215)
+++ grass/trunk/raster/simwe/simlib/hydro.c	2014-11-28 03:39:00 UTC (rev 63216)
@@ -204,8 +204,8 @@
 			if (lw >= MAXW)  /* max valid value is MAXW - 1, not MAXW */
 			    G_fatal_error(_("nwalk (%d) > maxw (%d)!"), lw, MAXW);
 
-			w[lw][0] = x + stepx * (ulec() - 0.5);
-			w[lw][1] = y + stepy * (ulec() - 0.5);
+			w[lw][0] = x + stepx * (simwe_rand() - 0.5);
+			w[lw][1] = y + stepy * (simwe_rand() - 0.5);
 			w[lw][2] = wei;
 
 			walkwe += w[lw][2];
@@ -323,7 +323,7 @@
 
 			if (traps != NULL && trap[k][l] != 0.) {	/* traps */
 
-			    eff = ulec();	/* random generator */
+			    eff = simwe_rand();	/* random generator */
 
 			    if (eff <= trap[k][l]) {
 				velx = -0.1 * v1[k][l];	/* move it slightly back */

Modified: grass/trunk/raster/simwe/simlib/random.c
===================================================================
--- grass/trunk/raster/simwe/simlib/random.c	2014-11-28 02:33:39 UTC (rev 63215)
+++ grass/trunk/raster/simwe/simlib/random.c	2014-11-28 03:39:00 UTC (rev 63216)
@@ -9,59 +9,9 @@
 
 #include <grass/waterglobs.h>
 
-int seeds(long int irand1, long int irand2)
+double simwe_rand(void)
 {
-    seed.is1 = irand1;
-    seed.is2 = irand2;
-    return 0;
-}
-
-
-int seedg(long int irand1, long int irand2)
-{
-    irand1 = seed.is1;
-    irand2 = seed.is2;
-    return 0;
-}
-
-
-double ulec(void)
-{
-    /* System generated locals */
-    double ret_val;
-
-    /* Local variables */
-    long int k, iz;
-
-
-    /*      uniform random number generator (combined type) */
-    /*      P. L'Ecuyer, Commun. ACM, 31(1988)742 */
-    /*      portable (32 bits arithmetics) */
-
-
-    k = seed.is1 / 53668;
-    seed.is1 -= k * 53668;
-    seed.is1 = seed.is1 * 40014 - k * 12211;
-    /*      is1=40014*(is1-k*53668)-k*12211 */
-    if (seed.is1 < 0) {
-	seed.is1 += 2147483563;
-    }
-
-    k = seed.is2 / 52774;
-    seed.is2 -= k * 52774;
-    seed.is2 = seed.is2 * 40692 - k * 3791;
-    /*      is2=40692*(is2-k*52774)-k*3791 */
-    if (seed.is2 < 0) {
-	seed.is2 += 2147483399;
-    }
-
-    iz = seed.is1 - seed.is2;
-    if (iz < 0) {
-	iz += 2147483562;
-    }
-    ret_val = (double)iz *4.656613e-10;
-
-    return ret_val;
+    return G_drand48();
 }				/* ulec */
 
 
@@ -80,8 +30,8 @@
 
     if (iset == 0) {
 	while (r >= 1. || r == 0.) {
-	    vv1 = ulec() * 2. - 1.;
-	    vv2 = ulec() * 2. - 1.;
+	    vv1 = simwe_rand() * 2. - 1.;
+	    vv2 = simwe_rand() * 2. - 1.;
 	    r = vv1 * vv1 + vv2 * vv2;
 	}
 	fac = sqrt(log(r) * -2. / r);

Modified: grass/trunk/raster/simwe/simlib/waterglobs.h
===================================================================
--- grass/trunk/raster/simwe/simlib/waterglobs.h	2014-11-28 02:33:39 UTC (rev 63215)
+++ grass/trunk/raster/simwe/simlib/waterglobs.h	2014-11-28 03:39:00 UTC (rev 63216)
@@ -78,14 +78,12 @@
 
 extern struct _points points;
 extern int input_data(void);
-extern int seeds(long int, long int);
-extern int seedg(long int, long int);
 extern int grad_check(void);
 extern void erod(double **);
 extern void main_loop(void);
 extern int output_data(int, double);
 extern int output_et(void);
-extern double ulec(void);
+extern double simwe_rand(void);
 extern double gasdev(void);
 extern double amax1(double, double);
 extern double amin1(double, double);



More information about the grass-commit mailing list