Skip to content

Commit

Permalink
Calendar attribute independent from leap years (#195)
Browse files Browse the repository at this point in the history
# CABLE

Thank you for submitting a pull request to the CABLE Project.

## Description

Removes the dependency of the calendar attribute on the fact we are
running a leap year or not. So output files from a same configuration
will have the same calendar attribute for all years.
Fixes #187 

## Testing
**Setup:** ran a global simulation with CRU JRA forcing (using gswp3
namelist settings) with both this branch and the main branch for 2
years: normal and leap year.

**Results:** `cdo diffn` indicates the variables in the cable_out.nc
files are identical. But the calendar attribute for `time` is different
in the non-leap year: `noleap` with the code from the main branch,
`standard` with the code from this branch.

## Type of change

Please delete options that are not relevant.

- [X] Bug fix

## Documentation

No changes to the documentation are required for this change.

Please add a reviewer when ready for review.


<!-- readthedocs-preview cable start -->
----
📚 Documentation preview 📚:
https://cable--195.org.readthedocs.build/en/195/

<!-- readthedocs-preview cable end -->

---------

Co-authored-by: ccc561 <ccc561@b483b3d9-cc7d-4f55-9e4c-b4562452379e>
Co-authored-by: C. Carouge <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2023
1 parent 8ba8c9e commit 1c8a2cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
32 changes: 11 additions & 21 deletions src/offline/cable_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,18 @@ PROGRAM cable_offline_driver

YEAR: DO YYYY= CABLE_USER%YearStart, CABLE_USER%YearEnd
CurYear = YYYY
IF ( leaps .AND. IS_LEAPYEAR( YYYY ) ) THEN
LOY = 366

!ccc Set "calendar" for netcdf time attribute and
! number of days in the year
calendar = "noleap"
LOY = 365
IF ( leaps ) THEN
calendar = "standard"
ELSE
LOY = 365
calendar = "noleap"
ENDIF
END IF
IF ( IS_LEAPYEAR( YYYY ) ) THEN
LOY = 366
END IF

! Check for gswp run
IF ( TRIM(cable_user%MetType) .EQ. 'gswp' ) THEN
ncciy = CurYear
Expand Down Expand Up @@ -503,12 +508,6 @@ PROGRAM cable_offline_driver
kend = ktauday * LOY
ENDIF

IF (leaps) THEN
calendar = "standard"
ELSE
calendar = "noleap"
ENDIF

ELSE IF ( TRIM(cable_user%MetType) .EQ. 'plum' ) THEN
! PLUME experiment setup using WATCH
IF ( CALL1 ) THEN
Expand All @@ -530,12 +529,6 @@ PROGRAM cable_offline_driver
str3 = ADJUSTL(str3)
timeunits="seconds since "//TRIM(str1)//"-"//TRIM(str2)//"-"//TRIM(str3)//" &
00:00"
IF (leaps) THEN
calendar = "standard"
ELSE
calendar = "noleap"
ENDIF

ENDIF
IF ( .NOT. PLUME%LeapYears ) LOY = 365
kend = NINT(24.0*3600.0/dels) * LOY
Expand Down Expand Up @@ -582,9 +575,6 @@ PROGRAM cable_offline_driver
calendar = 'standard'

ENDIF
LOY = 365

IF (IS_LEAPYEAR(CurYear)) LOY = 366
kend = NINT(24.0*3600.0/dels) * LOY
! get koffset to add to time-step of sitemet
IF (TRIM(site%RunType)=='historical') THEN
Expand Down
3 changes: 2 additions & 1 deletion src/offline/cable_iovars.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ MODULE cable_IO_vars_module

CHARACTER(LEN=200) :: timeunits ! timing info read from nc file

CHARACTER(LEN=10) :: calendar ! 'noleap' for no leap years, 'standard' for leap years
CHARACTER(LEN=10) :: calendar ! 'standard' if using leap years (set by
! leaps namelist option), else 'noleap'

CHARACTER(LEN=3) :: time_coord ! GMT or LOCal time variables

Expand Down
16 changes: 9 additions & 7 deletions src/offline/cable_mpimaster.F90
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,9 @@ SUBROUTINE mpidrv_master (comm)

CurYear = YYYY

LOY = 365
IF ( leaps .AND. IS_LEAPYEAR( YYYY ) ) THEN
LOY = 366
ELSE
LOY = 365
ENDIF

IF ( TRIM(cable_user%MetType) .EQ. 'plum' ) THEN
Expand Down Expand Up @@ -562,11 +561,6 @@ SUBROUTINE mpidrv_master (comm)
WRITE(*,*) 'Looking for global offline run info.'
CALL open_met_file( dels, koffset, kend, spinup, CTFRZ )

IF ( leaps .AND. IS_LEAPYEAR( YYYY ) ) THEN
calendar = "standard"
ELSE
calendar = "noleap"
ENDIF

ELSE IF ( globalMetfile%l_gpcc ) THEN
ncciy = CurYear
Expand All @@ -575,6 +569,14 @@ SUBROUTINE mpidrv_master (comm)

ENDIF

!ccc Set calendar attribute: dependant on the value of `leaps`
! that is set in the MetType if conditions above.
calendar = "noleap"
IF ( leaps ) THEN
calendar = "standard"
ENDIF


! somethings (e.g. CASA-CNP) only need to be done once per day
ktauday=INT(24.0*3600.0/dels)

Expand Down

0 comments on commit 1c8a2cb

Please sign in to comment.