Unexpected behaviour with a global variable

Hi !
I am trying to solve a toy problem I found here. As explained in the original article the idea is to solve the ODE
image which represents the temperature of an air conditioned room. The switch S(T) in the ODE is supposed to flip between 0 and 1 based on the temperature of the room and whether the air conditioner is on/off. The correct solution is supposed to oscillate between 67F and 73F (starting from 78F and air conditioning on), however I get a continuously decreasing solution. It could be a mistake in implementing the logic but I do not believe that is the case.
I am solving this problem using Fortran (RK ode solver) and a working example can be found here.
Any help would be appreciated!

Try replacing the statements in subroutine dfdx by

     IF ( AC) THEN
        dy(1) = 0.05*( 90 - y(1) ) + 0.2*( 60 - y(1) )
        dy(1) = 0.05*( 90 - y(1) )
     END IF

In your version, AC=.true. initially, and the .OR. clause in the subroutine keeps the AC unit on continuously.

Thanx a lot! That seems to have fixed it. So it was an error in implementing the logic after all.

Here is the link of the RK solver I used in case anyone is interested. Seems to work on mildly stiff problems as well.