Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(inout), | DIMENSION(12) | :: | Weekdays | ||
integer, | intent(in) | :: | LeapYearAdd | |||
integer, | intent(in) | :: | StartMonth | |||
integer, | intent(in) | :: | StartMonthDay | |||
integer, | intent(in) | :: | EndMonth | |||
integer, | intent(in) | :: | EndMonthDay | |||
logical, | intent(in) | :: | Rollover | |||
logical, | intent(in), | optional | :: | MidSimReset |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
SUBROUTINE ResetWeekDaysByMonth(WeekDays,LeapYearAdd,StartMonth,StartMonthDay,EndMonth,EndMonthDay,Rollover,MidSimReset)
! SUBROUTINE INFORMATION:
! AUTHOR Linda Lawrie
! DATE WRITTEN March 2012
! MODIFIED na
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! This subroutine resets the weekday for each month based on the current weekday
! and previous weekdays per month.
! METHODOLOGY EMPLOYED:
! NA
! REFERENCES:
! na
! USE STATEMENTS:
! na
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! SUBROUTINE ARGUMENT DEFINITIONS:
INTEGER, INTENT(INOUT), DIMENSION(12) :: Weekdays
INTEGER, INTENT(IN) :: LeapYearAdd
INTEGER, INTENT(IN) :: StartMonth
INTEGER, INTENT(IN) :: StartMonthDay
INTEGER, INTENT(IN) :: EndMonth
INTEGER, INTENT(IN) :: EndMonthDay
LOGICAL, INTENT(IN) :: Rollover
LOGICAL, INTENT(IN),OPTIONAL :: MidSimReset
! SUBROUTINE PARAMETER DEFINITIONS:
! na
! INTERFACE BLOCK SPECIFICATIONS:
! na
! DERIVED TYPE DEFINITIONS:
! na
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
INTEGER, DIMENSION(12) :: WeekdaysCopy
INTEGER Loop
INTEGER CurWeekDay
LOGICAL ResetMidSimulation
ResetMidSimulation=.false.
IF (PRESENT(MidSimReset)) ResetMidSimulation=MidSimReset
WeekdaysCopy=WeekDays
IF (.not. ResetMidSimulation) THEN
IF (Rollover) THEN
IF (StartMonth == 1) THEN
CurWeekDay=Weekdays(12)+EndDayOfMonth(12)+StartMonthDay-1
ELSE
CurWeekDay=WeekDays(EndMonth)+EndMonthDay
ENDIF
ELSE ! restart at same as before
CurWeekDay=Weekdays(StartMonth)
ENDIF
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
Weekdays=0
Weekdays(StartMonth)=CurWeekDay
DO Loop=StartMonth+1,12
SELECT CASE(Loop)
CASE(2)
CurWeekDay=CurWeekDay+EndDayOfMonth(1)
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(Loop)=CurWeekDay
CASE(3)
CurWeekDay=CurWeekDay+EndDayOfMonth(Loop-1)+LeapYearAdd
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(Loop)=CurWeekDay
CASE(4:12)
CurWeekDay=CurWeekDay+EndDayOfMonth(Loop-1)
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(Loop)=CurWeekDay
END SELECT
ENDDO
IF (ANY(WeekDays == 0)) THEN
! need to start at StMon and go backwards.
! EndDayOfMonth is also "days" in month. (without leapyear day in February)
CurWeekDay=WeekDays(StartMonth)
DO Loop=1,StartMonthDay-1
CurWeekDay=CurWeekDay-1
IF (CurWeekDay == 0) CurWeekDay=7
ENDDO
DO Loop=StartMonth-1,1,-1
SELECT CASE(Loop)
CASE(1)
CurWeekDay=CurWeekDay-EndDayOfMonth(1)
DO WHILE (CurWeekDay <= 0)
CurWeekDay=CurWeekDay+7
ENDDO
WeekDays(Loop)=CurWeekDay
CASE(2)
CurWeekDay=CurWeekDay-EndDayOfMonth(2)+LeapYearAdd
DO WHILE (CurWeekDay <= 0)
CurWeekDay=CurWeekDay+7
ENDDO
WeekDays(Loop)=CurWeekDay
CASE(3:12)
CurWeekDay=CurWeekDay-EndDayOfMonth(Loop)
DO WHILE (CurWeekDay <= 0)
CurWeekDay=CurWeekDay+7
ENDDO
WeekDays(Loop)=CurWeekDay
END SELECT
ENDDO
ENDIF
ELSE
IF (Rollover) THEN
IF (StartMonth == 1) THEN
CurWeekDay=Weekdays(12)+EndDayOfMonth(12)+StartMonthDay-1
ELSE
CurWeekDay=WeekDays(EndMonth)+EndMonthDay
ENDIF
ELSE ! restart at same as before
CurWeekDay=Weekdays(StartMonth)
ENDIF
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays=0
IF (StartMonth /= 1) THEN
CurWeekDay=WeekDaysCopy(12)+EndDayOfMonth(12)
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(1)=CurWeekDay
CurWeekDay=CurWeekDay+EndDayOfMonth(1)
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(2)=CurWeekDay
CurWeekDay=CurWeekDay+EndDayOfMonth(2)+LeapYearAdd
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(3)=CurWeekDay
DO Loop=4,12
CurWeekDay=CurWeekDay+EndDayOfMonth(Loop-1)
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(Loop)=CurWeekDay
ENDDO
ELSE
Weekdays=0
Weekdays(StartMonth)=CurWeekDay
DO Loop=StartMonth+1,12
SELECT CASE(Loop)
CASE(2)
CurWeekDay=CurWeekDay+EndDayOfMonth(1)
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(Loop)=CurWeekDay
CASE(3)
CurWeekDay=CurWeekDay+EndDayOfMonth(Loop-1)+LeapYearAdd
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(Loop)=CurWeekDay
CASE(4:12)
CurWeekDay=CurWeekDay+EndDayOfMonth(Loop-1)
DO WHILE (CurWeekDay > 7)
CurWeekDay=CurWeekDay-7
ENDDO
WeekDays(Loop)=CurWeekDay
END SELECT
ENDDO
IF (ANY(WeekDays == 0)) THEN
! need to start at StMon and go backwards.
! EndDayOfMonth is also "days" in month. (without leapyear day in February)
CurWeekDay=WeekDays(StartMonth)
DO Loop=1,StartMonthDay-1
CurWeekDay=CurWeekDay-1
IF (CurWeekDay == 0) CurWeekDay=7
ENDDO
DO Loop=StartMonth-1,1,-1
SELECT CASE(Loop)
CASE(1)
CurWeekDay=CurWeekDay-EndDayOfMonth(1)
DO WHILE (CurWeekDay <= 0)
CurWeekDay=CurWeekDay+7
ENDDO
WeekDays(Loop)=CurWeekDay
CASE(2)
CurWeekDay=CurWeekDay-EndDayOfMonth(2)+LeapYearAdd
DO WHILE (CurWeekDay <= 0)
CurWeekDay=CurWeekDay+7
ENDDO
WeekDays(Loop)=CurWeekDay
CASE(3:12)
CurWeekDay=CurWeekDay-EndDayOfMonth(Loop)
DO WHILE (CurWeekDay <= 0)
CurWeekDay=CurWeekDay+7
ENDDO
WeekDays(Loop)=CurWeekDay
END SELECT
ENDDO
ENDIF
ENDIF
ENDIF
RETURN
END SUBROUTINE ResetWeekDaysByMonth