NOAA-EMC / NCEPLIBS-bufr

The NCEPLIBS-bufr library contains routines and utilites for working with the WMO BUFR format.
Other
44 stars 19 forks source link

why not one module for all module vars? #430

Closed edwardhartnett closed 8 months ago

edwardhartnett commented 1 year ago

We have:

!> This module declares and initializes the BMISS variable.
!>
!> @author J. Ator @date 2021-03-24
module modv_bmiss
  !> Current placeholder value to represent "missing" data when reading
  !> from or writing to BUFR files; this value can be changed at any
  !> time via a call to subroutine setbmiss().
  real*8, public :: BMISS = 10E10_8
end module modv_bmiss

!> This module declares and initializes the IFOPBF variable.
!>
!> @author J. Ator @date 2015-03-03
module modv_ifopbf
  !> Status indicator to keep track of whether subroutine openbf() has
  !> already been called:
  !> - 0 = No
  !> - 1 = Yes
  integer, public :: IFOPBF = 0
end module modv_ifopbf

!> This module declares and initializes the IM8B variable.
!>
!> @author J. Woollen @date 2022-08-04
module modv_im8b
  !> Status indicator to keep track of whether all future calls to
  !> BUFRLIB subroutines and functions from a Fortran application
  !> program will be made using 8-byte integer arguments.
  !>
  !> The default value is .false., meaning that all future calls to
  !> BUFRLIB subroutines and functions will be made using 4-byte
  !> integer arguments.  This value can be changed at any time via a
  !> call to subroutine setim8b().
  logical, public :: IM8B = .false.
end module modv_im8b

etc.

Seems like it would be natural to have one module, moda_vars, and have all the vars in the same module. This would reduce our module count quite a bit. Also subprograms would only have to have one use statement to get all the variables, instead of one use statement for each variable, as is currently the case.

This would also simplify the documentation, which currently has a module for each of these variables, which is a bit much.

edwardhartnett commented 8 months ago

@jbathegit and @jack-woollen any comments on this issue?

jbathegit commented 8 months ago

From a library design standpoint, the idea behind this separation was for encapsulation. In other words, each variable would only be defined and accessible to the functions, subroutines, or other modules which really needed it, rather than all such variables being part of one big module that would be globally accessible everywhere, and where it would therefore be a lot easier to, e.g., inadvertently clobber the value of some global variable in an unintended place.

edwardhartnett commented 8 months ago

However this is normally achieved with "USES ONLY" right? So no need to have many modules...

jbathegit commented 8 months ago

Yeah, now that you reminded me about that, the USE <module_name>, ONLY: <var_list> option would probably work. Thanks, and I'll keep this on the "to do" list :-)