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

add a logical function to determine if year is leap year #35

Merged
merged 3 commits into from
Sep 23, 2022

Conversation

jedwards4b
Copy link
Contributor

Add a test to see if the current year is a leap year.

@billsacks
Copy link
Member

Thanks a lot for your work on this, @jedwards4b . What would you think about replacing the equality logic in shr_cal_leapyear with the use of 'mod', checking if mod(yr, 4) == 0, etc.? It seems like the equality comparisons could be prone to roundoff error with some compilers, at least for large years. I'm not sure if mod or modulo is the right function to use here: their behavior differs for negative numbers, which may be irrelevant since I don't think we can have a negative year in CESM(???).

@jedwards4b
Copy link
Contributor Author

@billsacks after considerable thought I realized that no new logic that we can introduce will handle all of the possible edge cases that I have documented here.

@billsacks
Copy link
Member

@jedwards4b - I really appreciate you carefully thinking through these edge cases. I'm not seeing how that relates to the comment I made, though. I'm just suggesting replacing conditionals like if (real(yr)/4.0 == yr/4) – which seem like you're effectively trying to check if yr mod 4 == 0 – with the actual mod operator, which seems equivalent but not prone to roundoff errors. Maybe I'm missing something here, though.

@jedwards4b
Copy link
Contributor Author

I see now, sorry.

@billsacks
Copy link
Member

Looks good, thanks!

@jedwards4b jedwards4b merged commit 7c0c445 into ESCOMP:main Sep 23, 2022
jedwards4b added a commit to ESCOMP/CDEPS that referenced this pull request Sep 29, 2022
correct mismatch of leap year
### Description of changes
Handle a number of special cases in matching inputdata dates to model dates.
These cases are:

-   Model is no_leap, data is Gregorian and leapyear date 2/29 is encountered in data - skip date
-   Model is Gregorian, data is no_leap and leapyear date 2/29 is encountered in model - repeat 2/28 data
-   Model is Gregorian, data is gregorian but leapyears do not align.
-       if in model leap year repeat data from 2/28 
-       if in data leap year skip date 2/29


### Specific notes

Contributors other than yourself, if any:  @mvertens 

CDEPS Issues Fixed (include github issue #): #190 

Are there dependencies on other component PRs (if so list): ESCOMP/CESM_share#35

Are changes expected to change answers (bfb, different to roundoff, more substantial): bfb

Any User Interface Changes (namelist or namelist defaults changes):

Testing performed (e.g. aux_cdeps, CESM prealpha, etc):  Neon spinup of over 100 years

Hashes used for testing:

sM  ./ccs_config
        modified sandbox, ccs_config_cesm0.0.44 (branch main) --> ccs_config_cesm0.0.38
    ./cime
        clean sandbox, on cime6.0.45
s   ./components/cdeps
        clean sandbox, 0f3f707 (branch leap_year_corrections) --> cdeps0.12.63
    ./components/cdeps/fox
        clean sandbox, on 4.1.2.1
    ./components/cdeps/share/genf90
        clean sandbox, on genf90_200608
    ./components/cism
        clean sandbox, on cismwrap_2_1_95
    ./components/cism/source_cism
        clean sandbox, on cism_main_2.01.011
 M  ./components/cmeps
        modified sandbox, on cmeps0.13.71
    ./components/cpl7
        clean sandbox, on cpl7.0.14
    ./components/mizuRoute
        clean sandbox, on 34723c2e4df7caa16812770f8d53ebc83fa22360
    ./components/mosart
        clean sandbox, on mosart1_0_45
    ./components/rtm
        clean sandbox, on rtm1_0_78
e-o ./doc/doc-builder
        -, not checked out --> v1.0.8
    ./libraries/mct
        clean sandbox, on MCT_2.11.0
    ./libraries/parallelio
        clean sandbox, on pio2_5_7
s   ./share
        clean sandbox, bfa2b5d0a9de06153f2ac94a95818568a1f5cf11 (branch shr_cal_leapyear) --> share1.0.12
    ./src/fates
        clean sandbox, on sci.1.58.1_api.24.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants