Skip to content
Snippets Groups Projects
Commit 7e1db93c authored by Andreas Gattringer's avatar Andreas Gattringer
Browse files

reduce array access code points in overlay translation

parent 219e02dc
No related branches found
No related tags found
1 merge request!1preparations for multi-scale simulations
......@@ -110,17 +110,19 @@ struct cats_2d_array_char *translate_exclusion(const struct cats_2d_array_double
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
const int32_t val = (int32_t) round(data->data[row][col]); // converter [translate_exclusion]
const int32_t in_val = (int32_t) round(data->data[row][col]); // converter [translate_exclusion]
char out_val;
if (val == 0) {
result->data[row][col] = OL_EXCLUSION_NOT_EXCLUDED; // converter [translate_exclusion]
if (in_val == 0) {
out_val = OL_EXCLUSION_NOT_EXCLUDED;
} else if (isnan(data->data[row][col])) {
result->data[row][col] = OL_EXCLUSION_NAN; // converter [translate_exclusion]
out_val = OL_EXCLUSION_NAN;
count += 1;
} else {
result->data[row][col] = OL_EXCLUSION_EXCLUDED; // converter [translate_exclusion]
out_val = OL_EXCLUSION_EXCLUDED;
count += 1;
}
result->data[row][col] = out_val; // converter [translate_exclusion]
}
}
......
#include <assert.h>
#include <math.h>
#include "overlay_resources.h"
#include "memory/arrays.h"
......@@ -14,15 +13,15 @@ struct cats_2d_array_double *translate_resources(const struct cats_2d_array_doub
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
double value = data->data[row][col]; // converter [translate_resources]
double in_value = data->data[row][col]; // converter [translate_resources]
double out_value;
if (isnan(value)) {
result->data[row][col] = 0.0; // converter [translate_resources]
if (isnan(in_value)) {
out_value = 0.0;
} else {
if (value <0 ) value = 0;
result->data[row][col] = value; // converter [translate_resources]
}
if (in_value < 0 ) in_value = 0;
out_value = in_value;
} result->data[row][col] = out_value; // converter [translate_resources]
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment