DrylandEcology / STEPWAT2

folder
4 stars 5 forks source link

Function `_read_soil_line` may fail on `cellToCopy` #495

Closed dschlaep closed 4 years ago

dschlaep commented 4 years ago

Error reported by @ScottCJr

Running default gridded testing project with make clean bint_testing_gridded and erroring out with "ERROR: Grid_Inputs/grid_soils.csv: cells out of order or too many layers."

Error occurs at least on master and on Seed_Dispersal branches.

On closer inspection, the function _read_soil_line reads a line, then checks cellNum > grid_Cells || layerRead > destination->num_layers (which throws the above error message), and then decides whether the input line specifies a soil layer or a soil profile copy from a cell.

If the input line specifies a soil profile copy, then the input line contains two values. In that case, the variable layerRead remains uninitialized, i.e. its value is undefined (and compiler dependent). We saw 1 and 32767 as possible values for layerRead after sscanf.

Thus, the checks cellNum > grid_Cells || layerRead > destination->num_layers should come after the copy case is handled -- instead of before.