Skip to content

Commit

Permalink
Merge pull request #429 from WardF/gh427.wif
Browse files Browse the repository at this point in the history
Attempt to fix a pernicious issue where some systems complain about no implicit type.
  • Loading branch information
WardF authored Jan 12, 2024
2 parents c792395 + 58420c9 commit a8e09f6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 13 deletions.
1 change: 1 addition & 0 deletions fortran/module_netcdf_nc_data.F90
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ Module netcdf_nc_data
Integer(C_INT), Parameter :: NC_FATAL = 1
Integer(C_INT), Parameter :: NC_VERBOSE = 2

#define USE_NETCDF4
#ifdef USE_NETCDF4

! NETCDF4 data
Expand Down
65 changes: 65 additions & 0 deletions fortran/module_typesizes.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
! Description:
! Provide named kind parameters for use in declarations of real and integer
! variables with specific byte sizes (i.e. one, two, four, and eight byte
! integers; four and eight byte reals). The parameters can then be used
! in (KIND = XX) modifiers in declarations.
! A single function (byteSizesOK()) is provided to ensure that the selected
! kind parameters are correct.
!
! Input Parameters:
! None.
!
! Output Parameters:
! Public parameters, fixed at compile time:
! OneByteInt, TwoByteInt, FourByteInt, EightByteInt
! FourByteReal, EightByteRadl
!
! References and Credits:
! Written by
! Robert Pincus
! Cooperative Institue for Meteorological Satellite Studies
! University of Wisconsin - Madison
! 1225 W. Dayton St.
! Madison, Wisconsin 53706
! [email protected]
!
! Design Notes:
! Fortran 90 doesn't allow one to check the number of bytes in a real variable;
! we check only that four byte and eight byte reals have different kind parameters.
!
module typesizes
implicit none
public
integer, parameter :: OneByteInt = selected_int_kind(2), &
TwoByteInt = selected_int_kind(4), &
FourByteInt = selected_int_kind(9), &
EightByteInt = selected_int_kind(18)

integer, parameter :: &
FourByteReal = selected_real_kind(P = 6, R = 37), &
EightByteReal = selected_real_kind(P = 13, R = 307)
contains
logical function byteSizesOK()
! Users may call this function once to ensure that the kind parameters
! the module defines are available with the current compiler.
! We can't ensure that the two REAL kinds are actually four and
! eight bytes long, but we can ensure that they are distinct.
! Early Fortran 90 compilers would sometimes report incorrect results for
! the bit_size intrinsic, but I haven't seen this in a long time.

! Local variables
integer (kind = OneByteInt) :: One
integer (kind = TwoByteInt) :: Two
integer (kind = FourByteInt) :: Four
integer (kind = EightByteInt) :: Eight

if (bit_size( One) == 8 .and. bit_size( Two) == 16 .and. &
bit_size(Four) == 32 .and. bit_size( Eight) == 64 .and. &
FourByteReal > 0 .and. EightByteReal > 0 .and. &
FourByteReal /= EightByteReal) then
byteSizesOK = .true.
else
byteSizesOK = .false.
end if
end function byteSizesOK
end module typeSizes
26 changes: 13 additions & 13 deletions fortran/netcdf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ module netcdf
!
! Update the dependencies in the Makefile.am when modifying the list of
! included files.
#include "netcdf_constants.f90"
#include "netcdf_externals.f90"
#include "netcdf_overloads.f90"
#include "netcdf_visibility.f90"
#include "netcdf_constants.F90"
#include "netcdf_externals.F90"
#include "netcdf_overloads.F90"
#include "netcdf_visibility.F90"
contains
#include "netcdf_file.f90"
#include "netcdf3_file.f90"
#include "netcdf_dims.f90"
#include "netcdf_attributes.f90"
#include "netcdf_variables.f90"
#include "netcdf_text_variables.f90"
#include "netcdf_expanded_subset.f90"
#include "netcdf_get_nd_expanded.f90"
#include "netcdf_eightbyte_subset.f90"
#include "netcdf_file.F90"
#include "netcdf3_file.F90"
#include "netcdf_dims.F90"
#include "netcdf_attributes.F90"
#include "netcdf_variables.F90"
#include "netcdf_text_variables.F90"
#include "netcdf_expanded_subset.F90"
#include "netcdf_get_nd_expanded.F90"
#include "netcdf_eightbyte_subset.F90"
end module netcdf

0 comments on commit a8e09f6

Please sign in to comment.