psmile_mg_control_cell_1d_real.F90

Go to the documentation of this file.
00001 !-----------------------------------------------------------------------
00002 ! Copyright 2006-2010, NEC Europe Ltd., London, UK.
00003 ! All rights reserved. Use is subject to OASIS4 license terms.
00004 !-----------------------------------------------------------------------
00005 !BOP
00006 !
00007 ! !ROUTINE: PSMILe_MG_Control_cell_1d_real
00008 !
00009 ! !INTERFACE:
00010 
00011       subroutine psmile_mg_control_cell_1d_real (     &
00012                            chmin, chmax, midp, levdim,     &
00013                            ijk, xyz, nold, all, wide, found, newijk)
00014 !
00015 ! !USES:
00016 !
00017       use PRISM_constants
00018 !
00019       use PSMILe, dummy_interface => PSMILe_mg_control_cell_1d_real
00020 
00021       implicit none
00022 !
00023 ! !INPUT PARAMETERS:
00024 !
00025       Integer, Intent (In)            :: levdim
00026 !
00027 !     Dimension of chmin, chmax and midp
00028 !
00029       Real, Intent (In)               :: chmin (0:levdim)
00030 !
00031 !     Minimum of grid coordinates per grid cell
00032 !
00033       Real, Intent (In)               :: chmax (0:levdim)
00034 !
00035 !     Maximum of grid coordinates per grid cell
00036 !
00037       Real, Intent (In)               :: midp (0:levdim)
00038 !
00039 !     Mid point of the cell
00040 !
00041       Integer, Intent (In)            :: ijk
00042 !
00043 !     Index of the cell for which the cell parts should be
00044 !     controlled.
00045 !
00046       Real, Intent (In)               :: xyz
00047 !
00048 !     Corrdinates of the point for which is searched
00049 !
00050       Integer, Intent (In)            :: nold
00051 !
00052 !     Old number of the cell part were the point XYZ was found
00053 !
00054       logical, Intent (In)            :: all
00055 !
00056 !     Were all cells i with DIST(i) < DIST(NOLD) already controlled ?
00057 !
00058       logical, Intent (In)            :: wide
00059 !
00060 !     Wide control ?
00061 !
00062 ! !OUTPUT PARAMETERS:
00063 !
00064       integer, Intent (Out)           :: found
00065 !
00066 !     Was the point xyz found ?
00067 !     found = 0: Not found
00068 !     found > 0: Part of the cell where point XYZ was found.
00069 !
00070       integer, Intent (Out)           :: newijk
00071 !
00072 !     Indices on level LEV if found > 0 is returned.
00073 !
00074 ! DEFINED PARAMETERS:
00075 
00076       Real, Parameter                :: remax = 1.0e20
00077 !
00078       Integer, Parameter             :: ndtry = 4
00079 !
00080 ! !LOCAL VARIABLES
00081 !
00082       Real                           :: dist (ndtry)
00083       Integer                        :: i, ibeg, iend, n, ntry
00084       Integer                        :: nmin (1)
00085 !
00086 ! !DESCRIPTION:
00087 !
00088 ! Subroutine "PSMILe_mg_control_cell_1d_real" searches the point XYZ
00089 ! in the n the neihbourhood of a cell. The cell which is controlled
00090 ! starts in IJK. All cells with (i) in
00091 !      (ijk-1:ijk+2) if wide is true.
00092 !      (ijk-1:ijk+1) otherwise
00093 ! are controlled.
00094 !
00095 ! ?!? Vielleicht koennte man alle Punkte zurueckgeben, die man
00096 !     gefunden hat.
00097 !
00098 !
00099 ! !REVISION HISTORY:
00100 !
00101 !   Date      Programmer   Description
00102 ! ----------  ----------   -----------
00103 ! 03.07.21    H. Ritzdorf  created
00104 !
00105 !EOP
00106 !----------------------------------------------------------------------
00107 !
00108 !  $Id: psmile_mg_control_cell_1d_real.F90 2325 2010-04-21 15:00:07Z valcke $
00109 !  $Author: valcke $
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 !  Initialization
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 !===> Compute indices to be controlled
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 !===> Control location of point XYZ in the boxes
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 !===> Set old values to remax
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 !===> Exclude all old distances
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 !===> Look for the minimum distance
00198 !
00199       nmin = MINLOC (dist(1:ntry))
00200 #ifdef MINLOCFIX
00201       if (nmin(1).eq.0) nmin=1
00202 #endif /* MINLOCFIX */
00203 !
00204 !===> Was a valid cell found ?
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 !===> All done
00215 !
00216 #ifdef VERBOSE
00217       print 9980, trim(ch_id)
00218 
00219       call psmile_flushstd
00220 #endif /* VERBOSE */
00221 !
00222 !  Formats:
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

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1