Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove loops over calendar types where not needed #767

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 32 additions & 60 deletions assimilation_code/modules/utilities/time_manager_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@ end function repeat_alarm
!=========================================================================

subroutine set_calendar_type_integer(mytype)

!------------------------------------------------------------------------
!
! Selects calendar for default mapping from time to date - if you know
! the magic integer for the calendar of interest.

Expand All @@ -684,7 +685,8 @@ end subroutine set_calendar_type_integer


subroutine set_calendar_type_string(calstring)

!------------------------------------------------------------------------
!
! Selects calendar for default mapping from time to date - given a string.

character(len=*), intent(in) :: calstring
Expand All @@ -693,8 +695,6 @@ subroutine set_calendar_type_string(calstring)

character(len=len(calstring)) :: str1
character(len=max_calendar_string_length) :: cstring
logical :: found_calendar = .false.
integer :: i

if ( .not. module_initialized ) call time_manager_init

Expand All @@ -714,49 +714,25 @@ subroutine set_calendar_type_string(calstring)
! We must check for the gregorian_mars calendar before
! the gregorian calendar for similar reasons.

WhichCalendar : do i = 0, max_type

if ( cstring == 'NO_CALENDAR' ) then
calendar_type = NO_CALENDAR
found_calendar = .true.
exit WhichCalendar
elseif ( cstring == 'NO CALENDAR' ) then ! allow this as a synonym
calendar_type = NO_CALENDAR
found_calendar = .true.
exit WhichCalendar
elseif ( cstring == 'NONE' ) then ! also allow this
calendar_type = NO_CALENDAR
found_calendar = .true.
exit WhichCalendar
elseif ( cstring == 'THIRTY_DAY_MONTHS' ) then
calendar_type = THIRTY_DAY_MONTHS
found_calendar = .true.
exit WhichCalendar
elseif ( cstring == 'JULIAN' ) then
calendar_type = JULIAN
found_calendar = .true.
exit WhichCalendar
elseif ( cstring == 'NOLEAP' ) then
calendar_type = NOLEAP
found_calendar = .true.
exit WhichCalendar
elseif ( cstring == 'GREGORIAN_MARS' ) then
calendar_type = GREGORIAN_MARS
found_calendar = .true.
exit WhichCalendar
elseif ( cstring == 'SOLAR_MARS' ) then
calendar_type = SOLAR_MARS
found_calendar = .true.
exit WhichCalendar
elseif ( cstring == 'GREGORIAN' ) then
calendar_type = GREGORIAN
found_calendar = .true.
exit WhichCalendar
endif

enddo WhichCalendar

if( .not. found_calendar ) then
if ( cstring == 'NO_CALENDAR' ) then
calendar_type = NO_CALENDAR
elseif ( cstring == 'NO CALENDAR' ) then ! allow this as a synonym
calendar_type = NO_CALENDAR
elseif ( cstring == 'NONE' ) then ! also allow this
calendar_type = NO_CALENDAR
elseif ( cstring == 'THIRTY_DAY_MONTHS' ) then
calendar_type = THIRTY_DAY_MONTHS
elseif ( cstring == 'JULIAN' ) then
calendar_type = JULIAN
elseif ( cstring == 'NOLEAP' ) then
calendar_type = NOLEAP
elseif ( cstring == 'GREGORIAN_MARS' ) then
calendar_type = GREGORIAN_MARS
elseif ( cstring == 'SOLAR_MARS' ) then
calendar_type = SOLAR_MARS
elseif ( cstring == 'GREGORIAN' ) then
calendar_type = GREGORIAN
else
write(errstring,*)'Unknown calendar ',calstring
call error_handler(E_ERR,'set_calendar_type_string',errstring,source)
endif
Expand Down Expand Up @@ -785,23 +761,19 @@ subroutine get_calendar_string(mystring)
!
! Returns default calendar type for mapping from time to date.

character(len=*), intent(OUT) :: mystring

integer :: i
character(len=*), intent(out) :: mystring

if ( .not. module_initialized ) call time_manager_init

mystring = ' '
mystring = ''

do i = 0,max_type
if (calendar_type == JULIAN) mystring = 'JULIAN'
if (calendar_type == NOLEAP) mystring = 'NOLEAP'
if (calendar_type == GREGORIAN) mystring = 'GREGORIAN'
if (calendar_type == NO_CALENDAR) mystring = 'NO_CALENDAR'
if (calendar_type == GREGORIAN_MARS) mystring = 'GREGORIAN_MARS'
if (calendar_type == SOLAR_MARS) mystring = 'SOLAR_MARS'
if (calendar_type == THIRTY_DAY_MONTHS) mystring = 'THIRTY_DAY_MONTHS'
enddo
if (calendar_type == JULIAN) mystring = 'JULIAN'
if (calendar_type == NOLEAP) mystring = 'NOLEAP'
if (calendar_type == GREGORIAN) mystring = 'GREGORIAN'
if (calendar_type == NO_CALENDAR) mystring = 'NO_CALENDAR'
if (calendar_type == GREGORIAN_MARS) mystring = 'GREGORIAN_MARS'
if (calendar_type == SOLAR_MARS) mystring = 'SOLAR_MARS'
if (calendar_type == THIRTY_DAY_MONTHS) mystring = 'THIRTY_DAY_MONTHS'

if (len_trim(mystring) < 3) then
write(errstring,*)'unknown calendar type ', calendar_type
Expand Down