[GRASS-SVN] r73509 - grass/trunk/raster/r.resamp.bspline

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Oct 9 06:09:01 PDT 2018


Author: mmetz
Date: 2018-10-09 06:09:01 -0700 (Tue, 09 Oct 2018)
New Revision: 73509

Modified:
   grass/trunk/raster/r.resamp.bspline/main.c
Log:
r.resamp.bspline: use Segment_[open|close]()

Modified: grass/trunk/raster/r.resamp.bspline/main.c
===================================================================
--- grass/trunk/raster/r.resamp.bspline/main.c	2018-10-09 13:01:42 UTC (rev 73508)
+++ grass/trunk/raster/r.resamp.bspline/main.c	2018-10-09 13:09:01 UTC (rev 73509)
@@ -45,8 +45,7 @@
     double **N, **obsVect;	/* Interpolation and least-square matrix */
 
     SEGMENT in_seg, out_seg, mask_seg;
-    const char *in_file, *out_file, *mask_file;
-    int in_fd, out_fd, mask_fd;
+    char *in_file, *out_file, *mask_file;
     double seg_size;
     int seg_mb, segments_in_memory;
     int have_mask;
@@ -313,15 +312,10 @@
 	segments_in_memory = 1;
 
     in_file = G_tempfile();
-    in_fd = creat(in_file, 0666);
-    if (Segment_format(in_fd, nrows, ncols, SEGSIZE, SEGSIZE, sizeof(double)) != 1)
+    if (Segment_open(&in_seg, in_file, nrows, ncols, SEGSIZE, SEGSIZE,
+                     sizeof(double), segments_in_memory) != 1)
 	G_fatal_error(_("Can not create temporary file"));
-    close(in_fd);
 
-    in_fd = open(in_file, 2);
-    if (Segment_init(&in_seg, in_fd, segments_in_memory) != 1)
-    	G_fatal_error(_("Can not initialize temporary file"));
-
     /* read raster input */
     inrastfd = Rast_open_old(in_opt->answer, "");
     drastbuf = Rast_allocate_buf(DCELL_TYPE);
@@ -375,9 +369,7 @@
 
 	    G_done_msg(_("Cross validation finished for ew_step = %f and ns_step = %f"), stepE, stepN);
 
-	    Segment_release(&in_seg);	/* release memory  */
-	    close(in_fd);
-	    unlink(in_file);
+	    Segment_close(&in_seg);	/* release memory  */
 
 	    exit(EXIT_SUCCESS);
 	}
@@ -398,15 +390,10 @@
 	/* use destination window */
 
 	mask_file = G_tempfile();
-	mask_fd = creat(mask_file, 0666);
-	if (Segment_format(mask_fd, nrows, ncols, SEGSIZE, SEGSIZE, sizeof(char)) != 1)
+	if (Segment_open(&mask_seg, mask_file, nrows, ncols, SEGSIZE, SEGSIZE,
+	                 sizeof(char), segments_in_memory) != 1)
 	    G_fatal_error(_("Can not create temporary file"));
-	close(mask_fd);
 
-	mask_fd = open(mask_file, 2);
-	if (Segment_init(&mask_seg, mask_fd, segments_in_memory) != 1)
-	    G_fatal_error(_("Can not initialize temporary file"));
-
 	if (mask_opt->answer) {
 	    maskfd = Rast_open_old(mask_opt->answer, "");
 	    maskbuf = Rast_allocate_buf(CELL_TYPE);
@@ -470,15 +457,10 @@
     }
 
     out_file = G_tempfile();
-    out_fd = creat(out_file, 0666);
-    if (Segment_format(out_fd, nrows, ncols, SEGSIZE, SEGSIZE, sizeof(double)) != 1)
+    if (Segment_open(&out_seg, out_file, nrows, ncols, SEGSIZE, SEGSIZE,
+                     sizeof(double), segments_in_memory) != 1)
 	G_fatal_error(_("Can not create temporary file"));
-    close(out_fd);
 
-    out_fd = open(out_file, 2);
-    if (Segment_init(&out_seg, out_fd, segments_in_memory) != 1)
-    	G_fatal_error(_("Can not initialize temporary file"));
-
     /* initialize output */
     G_message(_("Initializing output..."));
 
@@ -735,14 +717,10 @@
 	}			/*! END WHILE; last_column = TRUE */
     }				/*! END WHILE; last_row = TRUE */
 
-    Segment_release(&in_seg);	/* release memory  */
-    close(in_fd);
-    unlink(in_file);
+    Segment_close(&in_seg);	/* release memory  */
     
     if (have_mask) {
-	Segment_release(&mask_seg);	/* release memory  */
-	close(mask_fd);
-	unlink(mask_file);
+	Segment_close(&mask_seg);	/* release memory  */
     }
 
     G_message(_("Writing output..."));
@@ -771,9 +749,7 @@
 	    G_warning("only NULL cells in output raster");
     }
 
-    Segment_release(&out_seg);	/* release memory  */
-    close(out_fd);
-    unlink(out_file);
+    Segment_close(&out_seg);	/* release memory  */
 
     Rast_close(outrastfd);
 



More information about the grass-commit mailing list