GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
point2d_parallel.c
Go to the documentation of this file.
1 /*!
2  * \file point2d_parallel.c
3  *
4  * \author
5  * Lubos Mitas (original program and various modifications)
6  *
7  * \author
8  * C.Y. Liang,
9  * H. Mitasova,
10  * I. Kosinovsky,
11  * D. Gerdes,
12  * D. McCauley
13  * (GRASS4.1 version of the program and GRASS4.2 modifications)
14  *
15  * \author modified by Liang in May 2024
16  * \author modified by McCauley in August 1995
17  * \author modified by Mitasova in August 1995, Nov. 1996
18  *
19  * \copyright
20  * (C) 1993-2006 by Helena Mitasova and the GRASS Development Team
21  *
22  * \copyright
23  * This program is free software under the
24  * GNU General Public License (>=v2).
25  * Read the file COPYING that comes with GRASS for details.
26  */
27 
28 #include <stdio.h>
29 #include <math.h>
30 #include <unistd.h>
31 #include <grass/gis.h>
32 #include <grass/vector.h>
33 #include <grass/dbmi.h>
34 #include <grass/interpf.h>
35 
36 /* needed for AIX */
37 #ifdef hz
38 #undef hz
39 #endif
40 
41 /*!
42  * \brief A parallel version of IL_check_at_points_2d.
43  * Sperate the cross-validation/deviation computing part
44  * and the database writing part.
45  *
46  * \param params interpolation parameters
47  * \param data data in the segment for computing, NULL for writing out
48  * \param b solution of linear equations for computing, NULL for writing out
49  * \param ertot total error for computing, point at single point for writing out
50  * \param zmin min z-value for computing
51  * \param dnorm normalization factor for computing
52  * \param target_point point for computing or writing out
53  *
54  * \return 1
55  *
56  * \todo
57  * Alternative description:
58  * ...calculate the maximum and RMS deviation caused by smoothing.
59  */
60 
62  struct quaddata *data, /*!< current region */
63  double *b, /*!< solution of linear equations */
64  double *ertot, /*!< total error */
65  double zmin, /*!< min z-value */
66  double dnorm, struct triple *target_point)
67 {
68  if ((data != NULL) && (b != NULL)) {
69  int n_points = data->n_points; /* number of points */
70  struct triple *points = data->points; /* points for interpolation */
71  double west = data->x_orig;
72  double south = data->y_orig;
73  double /* rfsta2, errmax, */ h, xx, yy, r2, hz, zz, err, xmm, ymm, r;
74  int /* n1, */ m;
75 
76  if (params->cv) { /* one point is skipped for cross-validation*/
77  n_points -= 1;
78  }
79 
80  h = b[0];
81  for (m = 1; m <= n_points; m++) {
82  xx = target_point->x - points[m - 1].x;
83  yy = target_point->y - points[m - 1].y;
84  r2 = yy * yy + xx * xx;
85  if (r2 != 0.) {
86  /* rfsta2 = fstar2 * r2; */
87  r = r2;
88  h = h + b[m] * params->interp(r, params->fi);
89  }
90  }
91  /* modified by helena january 1997 - normalization of z was
92  removed from segm2d.c and interp2d.c
93  hz = (h * dnorm) + zmin;
94  zz = (points[mm - 1].z * dnorm) + zmin;
95  */
96  hz = h + zmin;
97  zz = target_point->z + zmin;
98  err = hz - zz;
99  xmm = target_point->x * dnorm + params->x_orig + west;
100  ymm = target_point->y * dnorm + params->y_orig + south;
101  (*ertot) += err * err;
102 
103  /* take the values out*/
104  target_point->x = xmm;
105  target_point->y = ymm;
106  target_point->z = err;
107  }
108  else {
109  IL_write_point_2d(*target_point, *ertot);
110  }
111  return 1;
112 }
#define NULL
Definition: ccmath.h:32
int IL_write_point_2d(struct triple, double)
A function to write out point and deviation at point to database.
Definition: point2d.c:164
int IL_check_at_points_2d_cvdev(struct interp_params *params, struct quaddata *data, double *b, double *ertot, double zmin, double dnorm, struct triple *target_point)
A parallel version of IL_check_at_points_2d. Sperate the cross-validation/deviation computing part an...
double b
Definition: r_raster.c:39
double r
Definition: r_raster.c:39
interp_fn * interp
Definition: interpf.h:131
double fi
Definition: interpf.h:92
double x_orig
Definition: interpf.h:107
double y_orig
Definition: interpf.h:107
double y_orig
Definition: dataquad.h:47
double x_orig
Definition: dataquad.h:46
struct triple * points
Definition: dataquad.h:53
int n_points
Definition: dataquad.h:52
double z
Definition: dataquad.h:41
double x
Definition: dataquad.h:39
double y
Definition: dataquad.h:40
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
Definition: symbol/read.c:216