[GRASS-SVN] r66776 - grass-addons/grass7/vector/v.kriging

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 10 08:14:53 PST 2015


Author: marisn
Date: 2015-11-10 08:14:53 -0800 (Tue, 10 Nov 2015)
New Revision: 66776

Modified:
   grass-addons/grass7/vector/v.kriging/geostat.c
   grass-addons/grass7/vector/v.kriging/main.c
   grass-addons/grass7/vector/v.kriging/utils.c
   grass-addons/grass7/vector/v.kriging/utils_kriging.c
Log:
v.kriging cleanup:
* reorder guisection to be more logical (initial, middle, final);
* do not truncate report file on subsequent runs;
* do not open report file twice;
* do not crash if no crossvalidation is requested;
* do not use uninitialized nLag.


Modified: grass-addons/grass7/vector/v.kriging/geostat.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/geostat.c	2015-11-09 14:10:23 UTC (rev 66775)
+++ grass-addons/grass7/vector/v.kriging/geostat.c	2015-11-10 16:14:53 UTC (rev 66776)
@@ -522,12 +522,11 @@
     // Cell/voxel center coords (location of interpolated value)
     r0 = (double *)G_malloc(3 * sizeof(double));
 
-    if (report->name) {         // report file available:
-        report->write2file = TRUE;
-        report->fp = fopen(report->name, "a");
+    if (report->write2file) {         // report file available:
         time(&report->now);
         fprintf(report->fp, "Interpolating values started on %s\n\n",
                 ctime(&report->now));
+        fflush(report->fp);
     }
 
     G_message(_("Interpolating unknown values..."));
@@ -545,7 +544,7 @@
     var_par->GM = G_matrix_copy(GM);    // copy matrix because of cross validation
 
     // perform cross validation...
-    if (crossvalid->name) {     // ... if desired
+    if (crossvalid->write2file) {     // ... if desired
         crossvalidation(xD, pnts, var_par);
     }
 
@@ -603,7 +602,7 @@
                     rslt_OK = vals[list->value[0] - 1]; // Estimated cell/voxel value rslt_OK = w x inputs
                 }
                 else if (list->n_values == 0) {
-                    if (report->name) { // report file available:
+                    if (report->write2file) { // report file available:
                         fprintf(report->fp,
                                 "Error (see standard output). Process killed...");
                         fclose(report->fp);
@@ -621,7 +620,7 @@
 
                 // write output to the (3D) raster layer
                 if (write2layer(xD, reg, out, col, row, dep, rslt_OK) == 0) {
-                    if (report->name) { // report file available
+                    if (report->write2file) { // report file available
                         fprintf(report->fp,
                                 "Error (see standard output). Process killed...");
                         fclose(report->fp);     // close report file
@@ -632,7 +631,7 @@
         }                       // end row 
     }                           // end dep
 
-    if (report->name) {
+    if (report->write2file) {
         fprintf(report->fp,
                 "\n************************************************\n\n");
         time(&report->now);

Modified: grass-addons/grass7/vector/v.kriging/main.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/main.c	2015-11-09 14:10:23 UTC (rev 66775)
+++ grass-addons/grass7/vector/v.kriging/main.c	2015-11-10 16:14:53 UTC (rev 66776)
@@ -77,17 +77,24 @@
         _("Phase of interpolation. In the initial phase, there is empirical variogram computed. In the middle phase, function of theoretical variogram is chosen by the user and its coefficients are estimated empirically. In the final phase, unknown values are interpolated using theoretical variogram from previous phase.");
     opt.phase->required = YES;
 
-    opt.output = G_define_option();     // Output layer
-    opt.output->key = "output";
-    opt.output->description = _("Name for output 2D/3D raster map");
-    opt.output->guisection = _("Final");
-
     opt.report = G_define_standard_option(G_OPT_F_OUTPUT);      // Report file
     opt.report->key = "report";
     opt.report->description = _("File to write the report");
     opt.report->required = NO;
     opt.report->guisection = _("Initial");
 
+    opt.function_var_hz = G_define_option();    // Variogram type
+    opt.function_var_hz->key = "hz_function";
+    opt.function_var_hz->options =
+        "linear, exponential, spherical, gaussian, bivariate";
+    opt.function_var_hz->description = _("Horizontal variogram function");
+    opt.function_var_hz->guisection = _("Middle");
+
+    opt.output = G_define_option();     // Output layer
+    opt.output->key = "output";
+    opt.output->description = _("Name for output 2D/3D raster map");
+    opt.output->guisection = _("Final");
+
     opt.crossvalid = G_define_standard_option(G_OPT_F_OUTPUT);  // Report file
     opt.crossvalid->key = "crossvalid";
     opt.crossvalid->description =
@@ -107,13 +114,6 @@
         _("Compute univariate variogram (3D interpolation only)");
     flg.univariate->guisection = _("Middle");
 
-    opt.function_var_hz = G_define_option();    // Variogram type
-    opt.function_var_hz->key = "hz_function";
-    opt.function_var_hz->options =
-        "linear, exponential, spherical, gaussian, bivariate";
-    opt.function_var_hz->description = _("Horizontal variogram function");
-    opt.function_var_hz->guisection = _("Middle");
-
     opt.function_var_vert = G_define_option();  // Variogram type
     opt.function_var_vert->key = "vert_function";
     opt.function_var_vert->options =
@@ -319,7 +319,10 @@
     if (opt.report->answer) {
         xD.report.write2file = TRUE;
         xD.report.name = opt.report->answer;
-        xD.report.fp = fopen(xD.report.name, "w");
+        // Do not truncate existing report files
+        // Some users might not change report file name after initial run
+        // thus leading to loss of report content of initial run.
+        xD.report.fp = fopen(xD.report.name, "a");
         time(&xD.report.now);
         fprintf(xD.report.fp, "v.kriging started on %s\n\n",
                 ctime(&xD.report.now));
@@ -345,10 +348,10 @@
     var_pars.hz.td = DEG2RAD(atof(opt.td_hz->answer));  // Angle of variogram processing
 
     if (opt.nL->answer) {       // Test if nL have been set up (optional)
-        if (var_pars.hz.nLag < 1)       // Invalid value
+        var_pars.hz.nLag = atoi(opt.nL->answer);
+        if (var_pars.hz.nLag < 1) {       // Invalid value
             G_message(_("Number of horizontal pieces must be at least 1. Default value will be used..."));
-        else {
-            var_pars.hz.nLag = atof(opt.nL->answer);
+            var_pars.hz.nLag = 20;
         }
     }
 
@@ -474,11 +477,6 @@
         read_tmp_vals("variogram_hz_tmp.txt", &var_pars.hz, &xD);       // read properties of horizontal variogram from temp file
         read_tmp_vals("variogram_vert_tmp.txt", &var_pars.vert, &xD);   // read properties of vertical variogram from temp file
 
-        if (xD.report.name) {   // report file available: 
-            xD.report.write2file = TRUE;
-            xD.report.fp = fopen(xD.report.name, "a");
-        }
-
         T_variogram(0, TRUE, opt, &var_pars.hz, &xD.report);    // compute theoretical variogram - hz
         T_variogram(1, TRUE, opt, &var_pars.vert, &xD.report);  // compute theoretical variogram - vert
 
@@ -515,13 +513,6 @@
             read_tmp_vals("variogram_hz_tmp.txt", &var_pars.fin, &xD);
         }
 
-        if (xD.report.name) {   // if report name available:
-            xD.report.write2file = TRUE;
-            xD.report.fp = fopen(xD.report.name, "a");
-            if (xD.report.fp == NULL)   // ... the file does not exist:
-                G_fatal_error(_("Cannot open the file..."));
-        }
-
         // check variogram settings
         if (var_pars.fin.type == 2 && strcmp(opt.function_var_final->answer, "linear") != 0) {  // bivariate nonlinear variogram:
             // just one function type is set up (none or both should be)

Modified: grass-addons/grass7/vector/v.kriging/utils.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/utils.c	2015-11-09 14:10:23 UTC (rev 66775)
+++ grass-addons/grass7/vector/v.kriging/utils.c	2015-11-10 16:14:53 UTC (rev 66776)
@@ -792,7 +792,7 @@
         G_message(_("Unable to plot variogram"));
     }
 
-    if (strcmp(var_pars->term, " ") != 0) {
+    if (strcmp(var_pars->term, "") != 0) {
         fprintf(gp, "set terminal %s size 750,450\n", var_pars->term);
 
         switch (var_pars->type) {

Modified: grass-addons/grass7/vector/v.kriging/utils_kriging.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/utils_kriging.c	2015-11-09 14:10:23 UTC (rev 66775)
+++ grass-addons/grass7/vector/v.kriging/utils_kriging.c	2015-11-10 16:14:53 UTC (rev 66776)
@@ -632,9 +632,7 @@
 
     FILE *fp;
 
-    if (crossvalid->name) {     // CV report file available:
-        fp = fopen(crossvalid->name, "w");
-    }
+    fp = fopen(crossvalid->name, "w");
 
     for (i = 0; i < n; i++) {   // for each input point [r0]:
         list = G_new_ilist();   // create list of overlapping rectangles



More information about the grass-commit mailing list