From 2f677539d7241b9d617ff9e89f15825b0c2f29f8 Mon Sep 17 00:00:00 2001 From: Micael Oliveira Date: Thu, 7 Apr 2022 15:30:08 +1000 Subject: [PATCH] Fix end_day for February in 'filename_from_date' when the year is a leap year. --- libutil/src/util.F90 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libutil/src/util.F90 b/libutil/src/util.F90 index e387193..2cdfa3b 100644 --- a/libutil/src/util.F90 +++ b/libutil/src/util.F90 @@ -1,7 +1,7 @@ module util_mod use netcdf -use datetime_module, only : datetime +use datetime_module, only : datetime, isLeapYear use error_handler, only : assert use, intrinsic :: iso_fortran_env, only : stderr=>error_unit @@ -206,7 +206,11 @@ function filename_for_date(filename_template, date) write(month_str, "(I2.2)") month start_day = 1 - end_day = DAYS_IN_MONTH(month) + if (isLeapYear(year) .and. month == 2) then + end_day = 29 + else + end_day = DAYS_IN_MONTH(month) + end if write(start_day_str, "(I2.2)") start_day write(end_day_str, "(I2.2)") end_day