Skip to content

Commit

Permalink
Simplify domain coordinate checking when read
Browse files Browse the repository at this point in the history
- When reading the program's domain file's coordinate values
	* We cannot test longitude due to longitude wrapping -> only check latitude values
	* We can only test geographical latitude values to be within the ranges of [90, -90] since projected values are not represented the same -> only test geographical latitude
	* Checking every latitude value is unnecessary -> only check the first and the last values if they are outside
  • Loading branch information
N1ckP3rsl3y committed Oct 20, 2024
1 parent f16ae8b commit 4d29a84
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/SW_netCDF_Input.c
Original file line number Diff line number Diff line change
Expand Up @@ -2364,11 +2364,9 @@ static void read_domain_coordinates(
) {
int index;
int varID;
size_t val;
const int numReadInDims = (primCRSIsGeo) ? 2 : 4;
const int numDims = 2;
Bool validY;
Bool validX;

char *domCoordNames[2]; /* Set later */

Expand Down Expand Up @@ -2431,27 +2429,21 @@ static void read_domain_coordinates(
return; /* Exit prematurely due to error */
}

for (val = 0; val < *domCoordSizes[index]; val++) {
/* Check latitude */
validY = (Bool) (index % 2 == 0 &&
(GE(*(domCoordArrs[index])[val], -90.0) &&
LE(*(domCoordArrs[index])[val], 90.0)));
if (primCRSIsGeo && index == 0) {
/* Check first and laste value of latitude */
validY = (Bool) ((GE(*(domCoordArrs[index])[0], -90.0) &&
LE(*(domCoordArrs[index])[0], 90.0)) ||
(GE(*(domCoordArrs[index])[*domCoordSizes[0] - 1],
-90.0) &&
LE(*(domCoordArrs[index])[*domCoordSizes[0] - 1],
90.0)));

/* Check longitude - can be [-180, 180] or [0, 360] */
validX = (Bool) (index % 2 == 1 &&
((GE(*(domCoordArrs[index])[val], -180.0) &&
LE(*(domCoordArrs[index])[val], 180.0)) ||
(GE(*(domCoordArrs[index])[val], 0.0) &&
LE(*(domCoordArrs[index])[val], 360.0))));

if ((index % 2 == 0 && !validY) || (index % 2 == 1 && !validX)) {
if (!validY) {
LogError(
LogInfo,
LOGERROR,
"Coordinate value of '%f' does not fit within the range "
"%s for the variable '%s'.",
*(domCoordArrs[index])[val],
(index % 2 == 0) ? "[-90, 90]" : "[-180, 180]/[0, 360]",
"Coordinate value(s) do not fit within the "
"range [-90, 90] for the variable '%s'.",
domCoordVarNames[index]
);
return;
Expand Down

0 comments on commit 4d29a84

Please sign in to comment.