! This file: ! http://ftp.aset.psu.edu/pub/ger/fortran/hdk/PrivateModExample.f90 ! ! File: PrivateModExample ! To illustrate use of Private modules. ! by James Van Buskirk in response to question by Mike Walters. ! 23 December 2004. module constants implicit none integer, parameter :: int2 = selected_int_kind(4) end module constants 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 end module ELEVATION_MAP_LORES program public implicit none integer int2 int2 = -1 call internal contains subroutine internal use ELEVATION_MAP_LORES implicit none print *, 'int2 = ', int2 end subroutine internal !Output with LF95 5.70f: ! !int2 = -1 ! !But now suppose we comment out the PRIVATE statement: ! ! ... ! module ELEVATION_MAP_LORES ! use CONSTANTS ! implicit none ! ! private ! public:: READ_ELEVATION_MAP_LORES ! ... ! !Now the output with LF95 is: ! !int2 = 2 ! !See the difference? Another reason you might want to hide !parameters like int2 unless you were sure you needed them !is that they might be intrinsics on a given compiler, see: ! http://h18009.www1.hp.com/fortran/docs/lrm/lrm0264.htm#int_intrin end program public