UW-SASWE/RAT

Routing fails when end date is in the month of February of a leap year.

Closed this issue · 0 comments

VIC-Routing fails to work when end date is in the month of February of a leap year. It is due to the wrong calculation of number of days for which a user wants to run routing using start and end date. This is the below mentioned lines of the routing fortran code:

c     calculate number of days & months in simulation
      M=START_MO
      Y=START_YEAR
      NMONTHS = 0
      NDAY=0
      DO J=START_MO,12*(STOP_YEAR-START_YEAR)+STOP_MO
        IF(M.EQ.2) THEN
           LP=isaleap(Y)
        ELSE 
           LP=0
        ENDIF
        NDAY = NDAY+DAYS_IN_MONTH(M)+LP
        NMONTHS = NMONTHS + 1
        MO(NMONTHS) = M
        YR(NMONTHS) = Y
        M = M + 1
        IF (M .GT. 12) THEN
            M = 1
            Y  = Y + 1
        ENDIF
      END DO
      IF(NDAY.GT.DAYS) THEN
         PRINT*, 'IN ROUT.F RESET DAYS TO ', NDAY
         STOP
      ENDIF
	  NDAY = NDAY-(START_DAY-1)-(DAYS_IN_MONTH(STOP_MO)-STOP_DAY)
      PRINT*,'NDAY = ',NDAY, ' NMONTHS = ',NMONTHS

You can see that DAYS_IN_MONTH(STOP_MO) in second last line of the above snippet should be 29 for leap year of February but it is a constant 28 in the code.