PUBLIC and PRIVATE

From: Mike Walters (walters_at_wisp_DOT_physics_DOT_wisc.edu)
Date: 12/20/04


Date: Mon, 20 Dec 2004 12:46:50 -0600

Hi,

Recently, I've been working with some modules written by someone else
and I've noticed something that seems strange to me. At the beginning
of a module, it is declared PRIVATE, but then every single member of the
module - variables and subprograms - are declared to be PUBLIC.
Wouldn't it just be easier, and more concise, to declare the whole
module PUBLIC? Am I missing something? Here is an example of what I mean:

module ELEVATION_MAP_LORES
   use CONSTANTS
   implicit none
   private
   public:: READ_ELEVATION_MAP_LORES
   integer, parameter, public:: num_lon_elev = 2160, &
                                num_lat_elev = 1080
   real, parameter, public:: first_lon_elev = 0.0, &
                             first_lat_elev = 90.0, &
                             last_lon_elev = 360.0, &
                             last_lat_elev = -90.0
   real, parameter, public:: &
       del_lon_elev = (last_lon_elev - first_lon_elev)/num_lon_elev, &
       del_lat_elev = (last_lat_elev - first_lat_elev)/num_lat_elev
   integer(kind=int2),dimension(num_lon_elev,num_lat_elev), public, save:: &
                                elev_map

   contains

   subroutine READ_ELEVATION_MAP_LORES(elev_name)
    character(len=*), intent(in):: elev_name
    integer:: ilat

    print *,"opening ", trim(elev_name)
    open(unit=7,file=trim(elev_name),access="direct",status="old", &
        action="read",recl=int(2*num_lon_elev))
    do ilat = 1, num_lat_elev
       read(unit=7,rec=ilat) elev_map(:,ilat)
    enddo

    close(unit=7)
    print *, "digital elev map read in, range (m) = ",
minval(elev_map), maxval(elev_map)

   end subroutine READ_ELEVATION_MAP_LORES

-- 
"It is enough that the people know there was an election. The people who 
cast the votes decide nothing. The people who count the votes decide 
everything."
	-- Joseph Stalin