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