24 #include <grass/gis.h>
25 #include <grass/interpf.h>
26 #include <grass/gmath.h>
30 double,
double,
double);
34 double zmin,
double zmax,
35 double *zminac,
double *zmaxac,
36 double *gmin,
double *gmax,
37 double *c1min,
double *c1max,
double *c2min,
double *c2max,
49 double inp_ew_res,
int dtens)
52 int i, j, k,
l, m, m1, i1;
55 int n_rows, n_cols, inp_r, inp_c;
56 double x_or, y_or, xm, ym;
57 static int first = 1, new_first = 1;
61 int inp_check_rows, inp_check_cols,
62 out_check_rows, out_check_cols;
63 int first_row, last_row;
64 int first_col, last_col;
67 int rem_out_row, rem_out_col;
68 int inp_seg_r, inp_seg_c,
86 xmax = xmin + ew_res * params->
nsizc;
87 ymax = ymin + ns_res * params->
nsizr;
88 prev = inp_rows * inp_cols;
89 if (prev <= params->kmax)
97 if (num < params->kmin) {
98 if (((params->
kmin - num) > (prev + 1 - params->
kmax)) &&
99 (prev + 1 < params->
KMAX2)) {
108 if ((num > params->
kmin) && (num + 1 < params->
kmax)) {
115 out_seg_r = params->
nsizr / div;
116 out_seg_c = params->
nsizc / div;
117 inp_seg_r = inp_rows / div;
118 inp_seg_c = inp_cols / div;
119 rem_out_col = params->
nsizc % div;
120 rem_out_row = params->
nsizr % div;
121 overlap1 =
min1(overlap, inp_seg_c - 1);
122 overlap1 =
min1(overlap1, inp_seg_r - 1);
129 p_size = inp_seg_c * inp_seg_r;
132 p_size = (overlap1 * 2 + inp_seg_c) * (overlap1 * 2 + inp_seg_r);
139 fprintf(stderr,
"Cannot allocate memory for in_points\n");
145 sqrt(((xmax - xmin) * (ymax -
146 ymin) * p_size) / (inp_rows * inp_cols));
149 params->
fi = params->
fi * (*dnorm) / 1000.;
150 fprintf(stderr,
"dnorm = %f, rescaled tension = %f\n", *dnorm,
158 input_data(params, 1, inp_rows, in_points, fdsmooth, fdinp, inp_rows,
159 inp_cols, zmin, inp_ns_res, inp_ew_res);
163 xm = params->
nsizc * ew_res;
164 ym = params->
nsizr * ns_res;
170 for (k = 1; k <= p_size; k++) {
172 data->
points[m1].
x = in_points[k - 1].
x / (*dnorm);
173 data->
points[m1].
y = in_points[k - 1].
y / (*dnorm);
175 data->
points[m1].
z = (double)(in_points[k - 1].z);
183 fprintf(stderr,
"Cannot allocate memory for indx\n");
187 fprintf(stderr,
"Cannot allocate memory for matrix\n");
191 fprintf(stderr,
"Cannot allocate memory for b\n");
197 for (i = 0; i < m1; i++) {
203 params->
check_points(params, data, b, ertot, zmin, *dnorm);
205 if (params->
grid_calc(params, data, bitmask,
206 zmin, zmax, zminac, zmaxac, gmin, gmax,
207 c1min, c1max, c2min, c2max, ertot, b, offset1,
209 fprintf(stderr,
"interpolation failed\n");
220 fprintf(stderr,
"dnorm in ressegm after grid before out= %f \n",
226 out_seg_r = params->
nsizr / div;
227 out_seg_c = params->
nsizc / div;
228 inp_seg_r = inp_rows / div;
229 inp_seg_c = inp_cols / div;
230 rem_out_col = params->
nsizc % div;
231 rem_out_row = params->
nsizr % div;
232 overlap1 =
min1(overlap, inp_seg_c - 1);
233 overlap1 =
min1(overlap1, inp_seg_r - 1);
242 for (i = 1; i <= div; i++) {
243 if (i <= div - rem_out_row)
246 n_rows = out_seg_r + 1;
250 ngstr = out_check_rows + 1;
251 nszr = ngstr + n_rows - 1;
252 y_or = (ngstr - 1) * ns_res;
257 first_row = (
int)(y_or / inp_ns_res) + 1;
258 if (first_row > overlap1) {
259 first_row -= overlap1;
260 last_row = first_row + inp_seg_r + overlap1 * 2 - 1;
261 if (last_row > inp_rows) {
262 first_row -= (last_row - inp_rows);
268 last_row = first_row + inp_seg_r + overlap1 * 2 - 1;
270 if ((last_row > inp_rows) || (first_row < 1)) {
271 fprintf(stderr,
"Row overlap too large!\n");
274 input_data(params, first_row, last_row, in_points, fdsmooth, fdinp,
275 inp_rows, inp_cols, zmin, inp_ns_res, inp_ew_res);
277 for (j = 1; j <= div; j++) {
278 if (j <= div - rem_out_col)
281 n_cols = out_seg_c + 1;
284 ngstc = out_check_cols + 1;
285 nszc = ngstc + n_cols - 1;
286 x_or = (ngstc - 1) * ew_res;
288 first_col = (
int)(x_or / inp_ew_res) + 1;
289 if (first_col > overlap1) {
290 first_col -= overlap1;
291 last_col = first_col + inp_seg_c + overlap1 * 2 - 1;
292 if (last_col > inp_cols) {
293 first_col -= (last_col - inp_cols);
299 last_col = first_col + inp_seg_c + overlap1 * 2 - 1;
301 if ((last_col > inp_cols) || (first_col < 1)) {
302 fprintf(stderr,
"Column overlap too large!\n");
316 for (k = 0; k <= last_row - first_row; k++) {
317 for (l = first_col - 1; l < last_col; l++) {
318 index = k * inp_cols +
l;
321 if ((in_points[index].x - x_or >= 0) &&
322 (in_points[index].
y - y_or >= 0) &&
323 ((nszc - 1) * ew_res - in_points[index].
x >= 0) &&
324 ((nszr - 1) * ns_res - in_points[index].
y >= 0))
327 (in_points[index].
x - x_or) / (*dnorm);
329 (in_points[index].
y - y_or) / (*dnorm);
331 data->
points[m].
z = (double)(in_points[index].z);
344 if (m <= params->KMAX2)
349 inp_check_cols += inp_c;
350 cursegm = (i - 1) * div + j - 1;
361 write_zeros(params, data, offset1);
370 "Cannot allocate memory for b\n");
376 "Cannot allocate memory for new_indx\n");
382 params->
KMAX2 + 1))) {
384 "Cannot allocate memory for new_matrix\n");
390 new_matrix, new_indx) < 0)
393 for (i1 = 0; i1 < m; i1++) {
394 b[i1 + 1] = data->
points[i1].
z;
402 if (params->
grid_calc(params, data, bitmask,
403 zmin, zmax, zminac, zmaxac, gmin,
404 gmax, c1min, c1max, c2min, c2max,
405 ertot, b, offset1, *dnorm) < 0) {
407 fprintf(stderr,
"interpolate() failed\n");
417 "Cannot allocate memory for b\n");
423 "Cannot allocate memory for indx\n");
429 params->
KMAX2 + 1))) {
431 "Cannot allocate memory for matrix\n");
440 for (i1 = 0; i1 < m; i1++)
441 b[i1 + 1] = data->
points[i1].
z;
448 if (params->
grid_calc(params, data, bitmask,
449 zmin, zmax, zminac, zmaxac, gmin,
450 gmax, c1min, c1max, c2min, c2max,
451 ertot, b, offset1, *dnorm) < 0) {
453 fprintf(stderr,
"interpolate() failed\n");
467 inp_check_rows += inp_r;
479 fprintf(stderr,
"dnorm in ressegm after grid before out2= %f \n", *dnorm);
486 int first_row,
int last_row,
488 int fdsmooth,
int fdinp,
489 int inp_rows,
int inp_cols,
490 double zmin,
double inp_ns_res,
double inp_ew_res)
494 int ret_val, ret_val1;
495 static FCELL *cellinp =
NULL;
496 static FCELL *cellsmooth =
NULL;
504 for (m1 = 0; m1 <= last_row - first_row; m1++) {
508 fprintf(stderr,
"Cannot get row %d (return value = %d)\n", m1,
515 inp_rows - m1 - first_row);
517 fprintf(stderr,
"Cannot get smoothing row\n");
520 y = params->
y_orig + (m1 + first_row - 1 + 0.5) * inp_ns_res;
521 for (m2 = 0; m2 < inp_cols; m2++) {
522 x = params->
x_orig + (m2 + 0.5) * inp_ew_res;
527 sm = (double)cellsmooth[m2];
531 points[m1 * inp_cols + m2].
x = x - params->
x_orig;
532 points[m1 * inp_cols + m2].
y = y - params->
y_orig;
534 points[m1 * inp_cols + m2].
z =
535 cellinp[m2] * params->
zmult - zmin;
543 points[m1 * inp_cols + m2].
smooth = sm;
558 double x_or = data->
x_orig;
559 double y_or = data->
y_orig;
564 int ngstc, nszc, ngstr, nszr;
566 double ns_res, ew_res;
575 cond1 = ((params->
adx !=
NULL) || (params->
ady !=
NULL) || cond2);
577 ngstc = (
int)(x_or / ew_res + 0.5) + 1;
578 nszc = ngstc + n_cols - 1;
579 ngstr = (
int)(y_or / ns_res + 0.5) + 1;
580 nszr = ngstr + n_rows - 1;
582 for (k = ngstr; k <= nszr; k++) {
583 offset = offset1 * (k - 1);
584 for (l = ngstc; l <= nszc; l++) {
606 offset2 = (offset + ngstc - 1) *
sizeof(FCELL);
607 if (params->
wr_temp(params, ngstc, nszc, offset2) < 0)
void G_free(void *buf)
Free allocated memory.
FCELL * G_allocate_f_raster_buf(void)
Allocates memory for a raster map of type FCELL.
void G_set_d_null_value(DCELL *dcellVals, int numVals)
double ** G_alloc_matrix(int rows, int cols)
Matrix memory allocation.
int G_get_f_raster_row(int fd, FCELL *buf, int row)
Get raster row (FCELL type)
int G_percent(long n, long d, int s)
Print percent complete messages.
struct quaddata * quad_data_new(double x_or, double y_or, double xmax, double ymax, int rows, int cols, int n_points, int kmax)
void G_lubksb(double **a, int n, int *indx, double b[])
int G_is_f_null_value(const FCELL *fcellVal)
Returns 1 if fcell is NULL, 0 otherwise. This will test if the value fcell is a NaN. It isn't good enough to test for a particular NaN bit pattern since the machine code may change this bit pattern to a different NaN. The test will be.
void G_set_f_null_value(FCELL *fcellVals, int numVals)
int IL_resample_interp_segments_2d(struct interp_params *, struct BM *, double, double, double *, double *, double *, double *, double *, double *, double *, double *, double *, int, double *, int, int, int, int, int, double, double, double, double, int)
int * G_alloc_ivector(size_t n)
Vector matrix memory allocation.
double * G_alloc_vector(size_t n)
Vector matrix memory allocation.