00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 subroutine psmile_mg_control_cell_1d_real ( &
00012 chmin, chmax, midp, levdim, &
00013 ijk, xyz, nold, all, wide, found, newijk)
00014
00015
00016
00017 use PRISM_constants
00018
00019 use PSMILe, dummy_interface => PSMILe_mg_control_cell_1d_real
00020
00021 implicit none
00022
00023
00024
00025 Integer, Intent (In) :: levdim
00026
00027
00028
00029 Real, Intent (In) :: chmin (0:levdim)
00030
00031
00032
00033 Real, Intent (In) :: chmax (0:levdim)
00034
00035
00036
00037 Real, Intent (In) :: midp (0:levdim)
00038
00039
00040
00041 Integer, Intent (In) :: ijk
00042
00043
00044
00045
00046 Real, Intent (In) :: xyz
00047
00048
00049
00050 Integer, Intent (In) :: nold
00051
00052
00053
00054 logical, Intent (In) :: all
00055
00056
00057
00058 logical, Intent (In) :: wide
00059
00060
00061
00062
00063
00064 integer, Intent (Out) :: found
00065
00066
00067
00068
00069
00070 integer, Intent (Out) :: newijk
00071
00072
00073
00074
00075
00076 Real, Parameter :: remax = 1.0e20
00077
00078 Integer, Parameter :: ndtry = 4
00079
00080
00081
00082 Real :: dist (ndtry)
00083 Integer :: i, ibeg, iend, n, ntry
00084 Integer :: nmin (1)
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 Character(len=len_cvs_string), save :: mycvs =
00112 '$Id: psmile_mg_control_cell_1d_real.F90 2325 2010-04-21 15:00:07Z valcke $'
00113
00114
00115
00116
00117
00118 #ifdef VERBOSE
00119 print 9990, trim(ch_id)
00120
00121 call psmile_flushstd
00122 #endif /* VERBOSE */
00123
00124 #ifdef PRISM_ASSERTION
00125 if (.not. all) then
00126 if (nold < 1 .or. nold > ndtry) then
00127 call psmile_assert (__FILE__, __LINE__, &
00128 'wrong nold')
00129 endif
00130 endif
00131
00132 if (min(ijk, levdim-ijk) < 0) then
00133 call psmile_assert (__FILE__, __LINE__, 'wrong ijk')
00134 endif
00135 #endif
00136
00137 #ifdef HUHU
00138 if (all) then
00139 if (nold .gt. 1) then
00140 print *, 'cell', nold, ijk
00141 endif
00142 endif
00143 #endif /* HUHU */
00144
00145
00146
00147 if (wide) then
00148 ibeg = max (ijk - 1, 0)
00149 iend = min (ijk + 2, levdim)
00150 else
00151 ibeg = max (ijk - 1, 0)
00152 iend = min (ijk + 1, levdim)
00153 endif
00154
00155
00156
00157 do i = ibeg, iend
00158 if (xyz >= chmin (i) .and. xyz <= chmax(i)) then
00159 dist (i-ibeg+1) = abs (xyz - midp (i))
00160 else
00161 dist (i-ibeg+1) = remax
00162 endif
00163 end do
00164
00165 dist (ijk-ibeg+1) = remax
00166 ntry = iend - ibeg + 1
00167
00168
00169
00170 if (nold .gt. 0) then
00171 #ifdef CLIC_ASSERTION
00172 if (dist(nold) .eq. remax) then
00173 write (*, 9980) xyz
00174 9980 format (1x, 1p, 3e18.9)
00175
00176 call psmile_assert (__FILE__, __LINE__,
00177 & 'incorrect nold')
00178 endif
00179 #endif /* CLIC_ASSERT */
00180
00181
00182
00183 if (all) then
00184 do n = 1, nold-1
00185 if (dist(n) <= dist(nold)) dist (n) = remax
00186 end do
00187
00188 do n = nold+1, ntry
00189 if (dist(n) < dist(nold)) dist (n) = remax
00190 end do
00191
00192 endif
00193
00194 dist (nold) = remax
00195 endif
00196
00197
00198
00199 nmin = MINLOC (dist(1:ntry))
00200 #ifdef MINLOCFIX
00201 if (nmin(1).eq.0) nmin=1
00202 #endif /* MINLOCFIX */
00203
00204
00205
00206 if (dist(nmin(1)) == remax) then
00207 found = 0
00208 else
00209 found = nmin (1)
00210
00211 newijk = ibeg + nmin (1) - 1
00212 endif
00213
00214
00215
00216 #ifdef VERBOSE
00217 print 9980, trim(ch_id)
00218
00219 call psmile_flushstd
00220 #endif /* VERBOSE */
00221
00222
00223
00224 9990 format (1x, a, ': psmile_mg_control_cell_1d_real:')
00225 9980 format (1x, a, ': psmile_mg_control_cell_1d_real: eof')
00226
00227 end subroutine PSMILe_mg_control_cell_1d_real