Skip to content

Commit

Permalink
remove unnecessary conditionals in filename_for_year
Browse files Browse the repository at this point in the history
  • Loading branch information
aekiss committed Aug 29, 2019
1 parent 7dd8e15 commit 5716800
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions atm/src/forcing.F90
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,16 @@ subroutine forcing_update_field(self, fld, forcing_date)
function filename_for_year(filename, year)
character(len=*), intent(in) :: filename
integer, intent(in) :: year
character(len=1024) :: filename_for_year, filename_for_yearp1
character(len=1024) :: filename_for_year
character(len=4) :: year_str, yearp1_str

write(year_str, "(I4)") year
write(yearp1_str, "(I4)") year+1

filename_for_year = replace_text(filename, "{{ year }}", year_str)
if (trim(filename_for_year) == '') then
filename_for_year = replace_text(filename, "{{year}}", year_str)
endif
filename_for_yearp1 = replace_text(filename_for_year, "{{ year+1 }}", yearp1_str)
if (trim(filename_for_yearp1) == '') then
filename_for_yearp1 = replace_text(filename_for_year, "{{year+1}}", yearp1_str)
endif
if (trim(filename_for_yearp1) /= '') then
filename_for_year = filename_for_yearp1
endif
filename_for_year = replace_text(filename_for_year, "{{year}}", year_str)
filename_for_year = replace_text(filename_for_year, "{{ year+1 }}", yearp1_str)
filename_for_year = replace_text(filename_for_year, "{{year+1}}", yearp1_str)
endfunction filename_for_year

subroutine forcing_deinit(self)
Expand Down

1 comment on commit 5716800

@aekiss
Copy link
Contributor Author

@aekiss aekiss commented on 5716800 Aug 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nichannah - I'm not sure why this empty string check was needed - it looks like replace_text will return the original string (not an empty string) if there's no match, so these conditionals aren't needed.
There's no check for an empty string in the only other place replace_text is used.
So I've removed the empty string checks I put into my commit based on your original code.
Does that sound OK?

Please sign in to comment.