diff --git a/src/epanet.c b/src/epanet.c index b4027cb..7e7b994 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -1382,6 +1382,7 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value) unit = ROUND(value); if (unit < 0 || unit > METERS) return 205; if (p->parser.Unitsflag == US && unit > PSI) return 0; + if (p->parser.Unitsflag == SI && unit == PSI) return 0; p->parser.Pressflag = unit; initunits(p); break; diff --git a/tests/test_project.cpp b/tests/test_project.cpp index c1635cd..6b102d3 100644 --- a/tests/test_project.cpp +++ b/tests/test_project.cpp @@ -183,6 +183,13 @@ BOOST_FIXTURE_TEST_CASE(test_pressure_units, FixtureInitClose) BOOST_REQUIRE(error == 0); BOOST_CHECK(abs(p - 298.76035) < 1.e-5); + // Set pressure to PSI and check that it remains in kPa + error = EN_setoption(ph, EN_PRESS_UNITS, EN_PSI); + BOOST_REQUIRE(error == 0); + error = EN_getoption(ph, EN_PRESS_UNITS, &units); + BOOST_REQUIRE(error == 0); + BOOST_CHECK(units == EN_KPA); + error = EN_closeH(ph); BOOST_REQUIRE(error == 0);