Opened 8 years ago
Last modified 8 years ago
#726 closed defect
Fortran Integer Range — at Initial Version
Reported by: | arango | Owned by: | arango |
---|---|---|---|
Priority: | major | Milestone: | Release ROMS/TOMS 3.7 |
Component: | Nonlinear | Version: | 3.7 |
Keywords: | Cc: |
Description
- Recently, I introduced at resetting of the reporting of the time-step counter in routine diag.F after 10 billion steps. The formatted field is I10 (ten digits):
WRITE (stdout,30) MOD(iic(ng)-1,10000000000), & .... 30 FORMAT (i10, ....
Some compilers seem to have issue with this integer operation. For example gfortran gives:diag.f90:383:53: WRITE (stdout,30) MOD(iic(ng),10000000000), & 1 Error: Integer too big for its kind at (1). This check can be disabled with the option -fno-range-check
To avoid issues with different compilers, I am changing the statement to a floating-point operation:
WRITE (stdout,30) INT(MOD(REAL(iic(ng)-1,r8),1.0E+10_r8)), & ...It is more robust to use the MOD intrinsic function with floating-point values.
- Cleaned the documentation in mod_kinds.F. Both byte and bit were used and it is better to do it in bits. Notice that byte and bit are not the same and can get confusing.
- I renamed the i4b integer kind to i8b in module ran_state.F to agree with the 32-bit documentation of the random numbers and the definition in mod_kinds.F.
Be aware that SELECTED_INT_KIND and KIND are different in Fortran when declaring integers:
integer, parameter :: i8b = selected_int_kind(8) integer :: i ! default integer (i8b) :: i8 integer (KIND=8) :: j8
A simple program can be written to examine the largest integer possible using the HUGE intrinsic function:
Default, HUGE(i ) = 2147483647 SELECTED_INT_KIND(1 ), HUGE(i1 ) = 127 SELECTED_INT_KIND(2 ), HUGE(i2 ) = 127 SELECTED_INT_KIND(4 ), HUGE(i4 ) = 32767 SELECTED_INT_KIND(8 ), HUGE(i8 ) = 2147483647 SELECTED_INT_KIND(9 ), HUGE(i9 ) = 2147483647 SELECTED_INT_KIND(16), HUGE(i16) = 9223372036854775807 KIND(1 ), HUGE(j1 ) = 127 KIND(2 ), HUGE(j2 ) = 32767 KIND(4 ), HUGE(j4 ) = 2147483647 KIND(8 ), HUGE(j8 ) = 9223372036854775807
Notice that the SELECTED_iNT_KIND(8) and KIND=8 have very different values. Also notice that the default declaration have the same values as SELECTED_iNT_KIND(8) or KIND=8.
Note:
See TracTickets
for help on using tickets.