Fix: the S (relative moisture content at each layer) can be negative in some extremely dry case when i < wp. So nroot should be confined between 0 and. Done by Dan