Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
cdo
Commits
0790967b
Commit
0790967b
authored
Mar 24, 2016
by
Uwe Schulzweida
Browse files
smoothpoint: add support for unstructured grids
parent
2de9882e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Smooth.c
View file @
0790967b
...
...
@@ -35,7 +35,7 @@ void grid_search_nbr(struct gridsearch *gs, int num_neighbors, int *restrict nbr
double
intlin
(
double
x
,
double
y1
,
double
x1
,
double
y2
,
double
x2
);
double
smooth_nbr_compute_weights
(
unsigned
num_neighbors
,
const
int
*
restrict
src_grid_mask
,
int
*
restrict
nbr_mask
,
const
int
*
restrict
nbr_add
,
double
*
restrict
nbr_dist
,
double
search_radius
,
double
weight0
,
double
weight
Inf
)
double
smooth_nbr_compute_weights
(
unsigned
num_neighbors
,
const
int
*
restrict
src_grid_mask
,
int
*
restrict
nbr_mask
,
const
int
*
restrict
nbr_add
,
double
*
restrict
nbr_dist
,
double
search_radius
,
double
weight0
,
double
weight
R
)
{
// Compute weights based on inverse distance if mask is false, eliminate those points
...
...
@@ -46,7 +46,7 @@ double smooth_nbr_compute_weights(unsigned num_neighbors, const int *restrict sr
nbr_mask
[
n
]
=
FALSE
;
if
(
nbr_add
[
n
]
>=
0
&&
src_grid_mask
[
nbr_add
[
n
]]
)
{
nbr_dist
[
n
]
=
intlin
(
nbr_dist
[
n
],
weight0
,
0
,
weight
Inf
,
search_radius
);
nbr_dist
[
n
]
=
intlin
(
nbr_dist
[
n
],
weight0
,
0
,
weight
R
,
search_radius
);
dist_tot
+=
nbr_dist
[
n
];
nbr_mask
[
n
]
=
TRUE
;
}
...
...
@@ -78,7 +78,7 @@ unsigned smooth_nbr_normalize_weights(unsigned num_neighbors, double dist_tot, c
static
void
smooth
(
int
gridID
,
double
missval
,
const
double
*
restrict
array1
,
double
*
restrict
array2
,
int
*
nmiss
,
int
num_neighbors
,
double
search_radius
,
double
weight0
,
double
weight
Inf
)
int
num_neighbors
,
double
search_radius
,
double
weight0
,
double
weight
R
)
{
*
nmiss
=
0
;
int
gridID0
=
gridID
;
...
...
@@ -153,7 +153,7 @@ void smooth(int gridID, double missval, const double *restrict array1, double *r
/* Compute weights based on inverse distance if mask is false, eliminate those points */
double
dist_tot
=
smooth_nbr_compute_weights
(
num_neighbors
,
mask
,
nbr_mask
,
nbr_add
,
nbr_dist
,
search_radius
,
weight0
,
weight
Inf
);
search_radius
,
weight0
,
weight
R
);
/* Normalize weights and store the link */
unsigned
nadds
=
smooth_nbr_normalize_weights
(
num_neighbors
,
dist_tot
,
nbr_mask
,
nbr_add
,
nbr_dist
);
...
...
@@ -309,7 +309,7 @@ void *Smooth(void *argument)
int
gridtype
;
int
xnsmooth
=
1
;
int
xmax_points
=
5
;
double
xsearch_radius
=
90
,
xweight0
=
0
.
25
,
xweight
Inf
=
0
.
25
;
double
xsearch_radius
=
90
,
xweight0
=
0
.
25
,
xweight
R
=
0
.
25
;
cdoInitialize
(
argument
);
...
...
@@ -327,33 +327,33 @@ void *Smooth(void *argument)
char
**
pargv
=
operatorArgv
();
pml_t
*
pml
=
pml_create
(
"SMOOTH"
);
PML_ADD_INT
(
pml
,
nsmooth
,
1
,
"Number of smooth iterations"
);
PML_ADD_INT
(
pml
,
max_
points
,
1
,
"Maximum number of points"
);
PML_ADD_FLT
(
pml
,
search_
radius
,
1
,
"Search radius"
);
PML_ADD_FLT
(
pml
,
weight0
,
1
,
"weight0"
);
PML_ADD_FLT
(
pml
,
weight
Inf
,
1
,
"weight
Inf
"
);
PML_ADD_INT
(
pml
,
nsmooth
,
1
,
"Number of smooth iterations"
);
PML_ADD_INT
(
pml
,
n
points
,
1
,
"Maximum number of points"
);
PML_ADD_FLT
(
pml
,
radius
,
1
,
"Search radius"
);
PML_ADD_FLT
(
pml
,
weight0
,
1
,
"weight
at distrance
0"
);
PML_ADD_FLT
(
pml
,
weight
R
,
1
,
"weight
at the search radius
"
);
pml_read
(
pml
,
pargc
,
pargv
);
if
(
cdoVerbose
)
pml_print
(
pml
);
if
(
PML_NOCC
(
pml
,
nsmooth
)
)
xnsmooth
=
par_nsmooth
[
0
];
if
(
PML_NOCC
(
pml
,
max_
points
)
)
xmax_points
=
par_
max_
points
[
0
];
if
(
PML_NOCC
(
pml
,
search_
radius
)
)
xsearch_radius
=
par_
search_
radius
[
0
];
if
(
PML_NOCC
(
pml
,
n
points
)
)
xmax_points
=
par_
n
points
[
0
];
if
(
PML_NOCC
(
pml
,
radius
)
)
xsearch_radius
=
par_radius
[
0
];
if
(
PML_NOCC
(
pml
,
weight0
)
)
xweight0
=
par_weight0
[
0
];
if
(
PML_NOCC
(
pml
,
weight
Inf
)
)
xweight
Inf
=
par_weight
Inf
[
0
];
if
(
PML_NOCC
(
pml
,
weight
R
)
)
xweight
R
=
par_weight
R
[
0
];
UNUSED
(
nsmooth
);
UNUSED
(
max_
points
);
UNUSED
(
search_
radius
);
UNUSED
(
n
points
);
UNUSED
(
radius
);
UNUSED
(
weight0
);
UNUSED
(
weight
Inf
);
UNUSED
(
weight
R
);
pml_destroy
(
pml
);
}
if
(
cdoVerbose
)
cdoPrint
(
"nsmooth = %d,
max_
points = %d,
search_
radius = %g, weight0 = %g, weight
Inf
= %g"
,
xnsmooth
,
xmax_points
,
xsearch_radius
,
xweight0
,
xweight
Inf
);
cdoPrint
(
"nsmooth = %d,
n
points = %d, radius = %g, weight0 = %g, weight
R
= %g"
,
xnsmooth
,
xmax_points
,
xsearch_radius
,
xweight0
,
xweight
R
);
}
...
...
@@ -370,7 +370,7 @@ void *Smooth(void *argument)
int
nvars
=
vlistNvars
(
vlistID1
);
int
*
varIDs
=
(
int
*
)
Malloc
(
nvars
*
sizeof
(
int
));
for
(
varID
=
0
;
varID
<
nvars
;
++
varID
)
{
gridID
=
vlistInqVarGrid
(
vlistID1
,
varID
);
...
...
@@ -381,10 +381,16 @@ void *Smooth(void *argument)
{
varIDs
[
varID
]
=
1
;
}
else
if
(
gridtype
==
GRID_UNSTRUCTURED
&&
operatorID
==
SMOOTHP
)
{
varIDs
[
varID
]
=
1
;
}
else
{
char
varname
[
CDI_MAX_NAME
];
vlistInqVarName
(
vlistID1
,
varID
,
varname
);
varIDs
[
varID
]
=
0
;
cdoWarning
(
"Unsupported grid for var
ID
%
d
"
,
var
ID
);
cdoWarning
(
"Unsupported grid for var
iable
%
s
"
,
var
name
);
}
}
...
...
@@ -415,7 +421,7 @@ void *Smooth(void *argument)
for
(
int
i
=
0
;
i
<
xnsmooth
;
++
i
)
{
if
(
operatorID
==
SMOOTHP
)
smooth
(
gridID
,
missval
,
array1
,
array2
,
&
nmiss
,
xmax_points
,
xsearch_radius
,
xweight0
,
xweight
Inf
);
smooth
(
gridID
,
missval
,
array1
,
array2
,
&
nmiss
,
xmax_points
,
xsearch_radius
,
xweight0
,
xweight
R
);
else
if
(
operatorID
==
SMOOTH9
)
smooth9
(
gridID
,
missval
,
array1
,
array2
,
&
nmiss
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment