module_example 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. MODULE exampl
  2. !!======================================================================
  3. !! *** MODULE exampl ***
  4. !! Ocean physics: brief description of the purpose of the module
  5. !! (please no more than 2 lines)
  6. !!======================================================================
  7. !! History : 3.0 ! 2008-06 (Author Names) Original code
  8. !! - ! 2008-08 (Author names) brief description of modifications
  9. !! 3.3 ! 2010-11 (Author names) - -
  10. !!----------------------------------------------------------------------
  11. #if defined key_example
  12. !!----------------------------------------------------------------------
  13. !! 'key_example' : brief description of the key option
  14. !!----------------------------------------------------------------------
  15. !! exa_mpl : list of module subroutine (caution, never use the
  16. !! exa_mpl_init : name of the module for a routine)
  17. !! exa_mpl_stp : Please try to use 3 letter block for routine names
  18. !!----------------------------------------------------------------------
  19. USE module_name1 ! brief description of the used module
  20. USE module_name2 ! ....
  21. IMPLICIT NONE
  22. PRIVATE
  23. PUBLIC exa_mpl ! routine called in xxx.F90 module
  24. PUBLIC exa_mpl_init ! routine called in nemogcm.F90 module
  25. TYPE :: FLD_E !: Structure type definition
  26. CHARACTER(lc) :: clname ! clname description (default length, lc, is 256, see par_kind.F90)
  27. INTEGER :: nfreqh ! nfreqh description
  28. END TYPE FLD_E
  29. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: var1 !: var1 description. CAUTION always use !: to describe
  30. ! ! a PUBLIC variable: simplify its search :
  31. ! ! grep var1 *90 | grep '!:'
  32. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: var2, var2 !: several variable on a same line OK, but
  33. ! ! DO NOT use continuation lines in declaration
  34. ! !!* namelist nam_xxx *
  35. LOGICAL :: ln_opt = .TRUE. ! give the default value of each namelist parameter
  36. CHARACTER :: cn_tex = 'T' ! short description of the variable
  37. INTEGER :: nn_opt = 1 ! please respect the DOCTOR norm for namelist variable
  38. REAL(wp) :: rn_var = 2._wp ! (it becomes easy to identify them in the code)
  39. TYPE(FLD) :: sn_ex ! structure
  40. INTEGER :: nint ! nint description (local permanent variable)
  41. REAL(wp) :: var ! var - -
  42. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: array ! array - -
  43. !! * Substitutions
  44. # include "exampl_substitute.h90"
  45. !!----------------------------------------------------------------------
  46. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  47. !! $Id: module_example 4147 2013-11-04 11:51:55Z cetlod $
  48. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  49. !!----------------------------------------------------------------------
  50. CONTAINS
  51. INTEGER FUNCTION exa_mpl_alloc()
  52. !!----------------------------------------------------------------------
  53. !! *** FUNCTION exa_mpl_alloc ***
  54. !!----------------------------------------------------------------------
  55. ALLOCATE( array(jpi,jpj,jpk) , STAT= exa_mpl_alloc ) ! Module array
  56. !
  57. IF( lk_mpp ) CALL mpp_sum ( exa_mpl_alloc )
  58. IF( exa_mpl_alloc /= 0 ) CALL ctl_warn('exa_mpl_alloc: failed to allocate arrays')
  59. !
  60. END FUNCTION exa_mpl_alloc
  61. SUBROUTINE exa_mpl( kt, pvar1, pvar2, ptab )
  62. !!----------------------------------------------------------------------
  63. !! *** ROUTINE exa_mpl ***
  64. !!
  65. !! ** Purpose : Brief description of the routine
  66. !!
  67. !! ** Method : description of the methodoloy used to achieve the
  68. !! objectives of the routine. Be as clear as possible!
  69. !!
  70. !! ** Action : - first action (share memory array/varible modified
  71. !! in this routine
  72. !! - second action .....
  73. !! - .....
  74. !!
  75. !! References : Author et al., Short_name_review, Year
  76. !! Give references if exist otherwise suppress these lines
  77. !!----------------------------------------------------------------------
  78. USE toto_module ! description of the module
  79. USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
  80. USE wrk_nemo, ONLY: zztab => wrk_2d_5 ! 2D workspace
  81. USE wrk_nemo, ONLY: zwx => wrk_3d_12 , zwy => wrk_3d_13 ! 3D workspace
  82. !!
  83. INTEGER , INTENT(in ) :: kt ! short description
  84. INTEGER , INTENT(inout) :: pvar1 ! - -
  85. REAL(wp), INTENT( out) :: pvar2 ! - -
  86. REAL(wp), INTENT( out), DIMENSION(jpi,jpj) :: pvar2 ! - -
  87. !!
  88. INTEGER :: ji, jj, jk ! dummy loop arguments (DOCTOR : start with j, but not jp)
  89. INTEGER :: itoto, itata ! temporary integers (DOCTOR : start with i
  90. REAL(wp) :: zmlmin, zbbrau ! temporary scalars (DOCTOR : start with z)
  91. REAL(wp) :: zfact1, zfact2 ! do not use continuation lines in declaration
  92. !!--------------------------------------------------------------------
  93. IF( wrk_in_use(3, 12,13) .OR. wrk_in_use(2, 5 ) THEN
  94. CALL ctl_stop('exa_mpl: requested workspace arrays unavailable') ; RETURN
  95. ENDIF
  96. IF( kt == nit000 ) CALL exa_mpl_init ! Initialization (first time-step only)
  97. zmlmin = 1.e-8 ! Local constant initialization
  98. zbbrau = .5 * ebb / rau0
  99. zfact1 = -.5 * rdt * efave
  100. zfact2 = 1.5 * rdt * ediss
  101. SELECT CASE ( npdl ) ! short description of the action
  102. !
  103. CASE ( 0 ) ! describe case 1
  104. DO jk = 2, jpkm1
  105. DO jj = 2, jpjm1
  106. DO ji = fs_2, fs_jpim1 ! vector opt.
  107. avmv(ji,jj,jk) = ....
  108. END DO
  109. END DO
  110. END DO
  111. !
  112. CASE ( 1 ) ! describe case 2
  113. DO jk = 2, jpkm1
  114. DO jj = 2, jpjm1
  115. DO ji = fs_2, fs_jpim1 ! vector opt.
  116. avmv(ji,jj,jk) = ...
  117. END DO
  118. END DO
  119. END DO
  120. !
  121. END SELECT
  122. !
  123. CALL mpplnk2( avmu, 'U', 1. ) ! Lateral boundary conditions (unchanged sign)
  124. !
  125. IF( wrk_not_released(3, 12,13) .OR. wrk_not_released(2, 5 ) THEN
  126. CALL ctl_stop('exa_mpl: failed to release workspace arrays') ; RETURN
  127. ENDIF
  128. !
  129. END SUBROUTINE exa_mpl
  130. SUBROUTINE exa_mpl_init
  131. !!----------------------------------------------------------------------
  132. !! *** ROUTINE exa_mpl_init ***
  133. !!
  134. !! ** Purpose : initialization of ....
  135. !!
  136. !! ** Method : blah blah blah ...
  137. !!
  138. !! ** input : Namlist namexa
  139. !!
  140. !! ** Action : ...
  141. !!----------------------------------------------------------------------
  142. INTEGER :: ji, jj, jk, jit ! dummy loop indices
  143. INTEGER :: ios ! Local integer output status for namelist read
  144. !!
  145. NAMELIST/namexa/ exa_v1, exa_v2, nexa_0, sn_ex
  146. !!----------------------------------------------------------------------
  147. !
  148. REWIND( numnam_ref ) ! Namelist namexa in reference namelist : Example
  149. READ ( numnam_ref, namexa, IOSTAT = ios, ERR = 901)
  150. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namexa in reference namelist', lwp )
  151. REWIND( numnam_cfg ) ! Namelist namexa in configuration namelist : Example
  152. READ ( numnam_cfg, namexa, IOSTAT = ios, ERR = 902 )
  153. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namexa in configuration namelist', lwp )
  154. ! Output namelist for control
  155. WRITE ( numond, namexa )
  156. !
  157. IF(lwp) THEN ! Control print
  158. WRITE(numout,*)
  159. WRITE(numout,*) 'exa_mpl_init : example '
  160. WRITE(numout,*) '~~~~~~~~~~~~'
  161. WRITE(numout,*) ' Namelist namexa : set example parameters'
  162. WRITE(numout,*) ' brief desciption exa_v1 = ', exa_v1
  163. WRITE(numout,*) ' brief desciption exa_v2 = ', exa_v2
  164. WRITE(numout,*) ' brief desciption nexa_0 = ', nexa_0
  165. WRITE(numout,*) ' brief desciption sn_ex%clname = ', sn_ex%clname
  166. WRITE(numout,*) ' brief desciption sn_ex%nfreqh = ', sn_ex%nfreqh
  167. ENDIF
  168. !
  169. ! ! allocate exa_mpl arrays
  170. IF( exa_mpl_alloc() /= 0 ) CALL ctl_stop( 'STOP', 'exa_mpl_init : unable to allocate arrays' )
  171. ! ! Parameter control
  172. IF( ln_opt ) CALL ctl_stop( 'exa_mpl_init: this work and option xxx are incompatible' )
  173. IF( nn_opt == 2 ) CALL ctl_warn( 'exa_mpl_init: this work and option yyy may cause problems' )
  174. !
  175. END SUBROUTINE exa_mpl_init
  176. #else
  177. !!----------------------------------------------------------------------
  178. !! Default option : NO example
  179. !!----------------------------------------------------------------------
  180. CONTAINS
  181. SUBROUTINE exa_mpl( kt, pvar1, pvar2, ptab ) ! Empty routine
  182. REAL:: ptab(:,:)
  183. WRITE(*,*) 'exa_mpl: You should not have seen this print! error?', kt, pvar1, pvar2, ptab(1,1)
  184. END SUBROUTINE exa_mpl
  185. #endif
  186. !!======================================================================
  187. END MODULE exampl