-
Notifications
You must be signed in to change notification settings - Fork 92
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
Create FatesConstantMod to hold global constants #136
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module FatesConstantsMod | ||
! This module is used to define global _immutable_ data. Everything in | ||
! this module must have the parameter attribute. | ||
|
||
implicit none | ||
|
||
public | ||
|
||
! kinds | ||
integer, parameter :: fates_r8 = selected_real_kind(12) ! 8 byte real | ||
|
||
! string lengths | ||
integer, parameter :: fates_avg_flag_length = 3 | ||
integer, parameter :: fates_short_string_length = 32 | ||
integer, parameter :: fates_long_string_length = 199 | ||
|
||
! various magic numbers | ||
real(fates_r8), parameter :: fates_special_value = 1.0e36_fates_r8 ! special value for real data, compatible with clm. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have something similar in clm_fates%init(). A call to set_fates_ctrlparms('hio_ignore_val',rval=spval) transfers the host model's definition of the special value to FATES. It transfers the special value to be used exclusively as a flag to initializing unset history output arrays. I was thinking it would be nice to have a special section where we house constants that are dictated by the host, I am agnostic as to where that could be located. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added spval on a whim because I that was what started this PR, even though I'm not using it. It's not immediately obvious if we need to distinguish between fates_spval and host_spval (seems useful, but maybe not). I'm removing fates specific special values until needed. |
||
integer, parameter :: fates_int_special_value = -9999 ! keep this negative to avoid conflicts with possible valid values | ||
|
||
end module FatesConstantsMod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we strip this down to something shorter like "f_r8" or "fr8"? I feel like this will be used so often that we can reduce total letter count with an abbreviation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you use it, you can still alias it to r8 with something like 'use FatesConstantsMod, only : r8 => fates_r8'. See how it is used in the history module. The actual declaration should have a meaningful, unambiguous name.
There are no bonus points in software engineering for 'reducing the total letter count'. The compiler doesn't care. Code is written once, refactored a few times, and read many, many, many times by human beings. Meaningful names without cryptic abbreviations optimize for the most common use case. In science, it is often humans with little to no training and interest in software as an end. The more clear the code is, the less time it takes to ramp up, and the fewer mistakes they will make. Plus, all modern editors have some form of autocompletion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the solution of
use FatesConstantsMod, only : r8 => fates_r8
since it only requires changing one line per module...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not seeing the alias was an over-site on my part. Try to relax a little bit @bandre-ucar. I have arguments that I can go into that validate why I made the suggestion I did, but I'm not. The way your are proposing to go forward is fine. The important thing is that we create a culture on these forums where people feel welcomed to interact and know that their input will be valued.