psmile_transform_gauss2.F90

Go to the documentation of this file.
00001 
00002        subroutine psmile_transform_gauss2 ( search, glen, map_shape,  &
00003                            map, locations, found, glocations, gfound, &
00004                            cell_based_switch, nlev, grid_valid_shape, &
00005                            ierror )
00006 !
00007 ! !USES:
00008 !
00009       use PRISM_constants
00010       use PSMILe, dummy_interface => PSMILe_Transform_gauss2
00011 #ifdef DEBUG_TRACE
00012   use psmile_debug_trace
00013 #endif
00014 
00015       Implicit none
00016 !
00017 ! !INPUT PARAMETERS:
00018 !
00019       Type (Enddef_search)                :: search
00020 
00021 !     Info's on coordinates to be searched
00022 
00023       Integer, Intent (In)                :: glen (search%npart, 2)
00024 
00025 !     Number of coords to be searched in all directions.
00026 !     glen(*,1) = Number in lonlat/GaussReduced direction
00027 !     glen(*,2) = Number in vertical direction
00028 
00029       Integer, Intent (In)                :: map_shape(ndim_3d)
00030       Integer, Intent (In)                :: map (map_shape(1), 
00031                                                   map_shape(2), 
00032                                                   map_shape(3))
00033 !
00034 !     Mapping from regular indices in lon and lat direction of regular grid
00035 !     into (sequential) lonlat directions of Gaussian Reduced Grid
00036 !     TODO: Should become indices in lon direction for current longitude
00037 !
00038       Type (integer_vector), Intent (In)  :: locations (search%npart, ndim_3d)
00039 !
00040 !     Input:  Indices of the grid cell in which the point was found
00041 !             in the auxillary grid.
00042 !             Note: The auxiliary grid is of type PRISM_Reglonlatvrt.
00043 
00044       Type (integer_vector), Intent (In)  :: found (search%npart, ndim_3d)
00045 !
00046 !     Input:  Finest level number on which a grid cell was found
00047 !             in the auxillary grid for point I mapped onto the gauss grid.
00048 !             Level number = -(nlev+1): Never found
00049 !
00050       Logical, Intent (In)                :: cell_based_switch
00051 !
00052 !     Indication that we have changed from cell-based to point-based search 
00053 !
00054       Integer, Intent (In)                :: nlev
00055 !
00056 !     Maximum number of levels in the multigrid hierarchy. Needed to set the
00057 !     gfound array to "not found" for points that were found in the auxiliary
00058 !     grid but not on the actual reduced gauss grid.
00059 !
00060       Integer, Intent (In)                :: grid_valid_shape(2)
00061 !
00062 !     Defines the valid coordinate range for the actual reduced gauss grid.
00063 !
00064 ! !INPUT/OUTPUT PARAMETERS:
00065 !
00066 !
00067 ! !OUTPUT PARAMETERS:
00068 
00069       Type (integer_vector), Intent (InOut) :: glocations (search%npart, 2)
00070 !
00071 !     Indices of the grid cell of the point that was found
00072 !     in the auxillary grid mapped onto the gauss grid.
00073 !     The latitude  values are in the range of 1:nbr_lats
00074 !     The longitude values are in the range of 1:points_per_lat(lat)
00075 !     glocations (*,1)%vector is a 1-dimensional vector in GaussReduced
00076 !     grid notation.
00077 
00078       Type (integer_vector), Intent (InOut) :: gfound (search%npart, 2)
00079 !
00080 !     Finest level number on which a grid cell was found
00081 !     in the auxillary grid for point I.
00082 !     Level number = -(nlev+1): Never found
00083 !
00084       Integer,               Intent (Out) :: ierror
00085 
00086 !     Returns the error code of PSMILe_Transform_gauss2_dble;
00087 !             ierror = 0 : No error
00088 !             ierror > 0 : Severe error
00089 !
00090 ! !LOCAL VARIABLES
00091 !
00092 ! indl = Index of LonLat/GaussReduced values in "gfound, glocations"
00093 ! indz = Index of Vert   values in "gfound, glocations"
00094 !
00095       Integer, Parameter           :: indl = 1
00096       Integer, Parameter           :: indz = 2
00097 
00098       Integer                      :: i, ipart, j, npart, n
00099       Integer                      :: ii, jlat
00100 !
00101 !     ... for error parameters
00102 !
00103       Integer, parameter           :: nerrp = 2
00104       Integer                      :: ierrp (nerrp)
00105 !
00106 ! !DESCRIPTION:
00107 !
00108 ! Subroutine "PSMILe_Transform_gauss2" transforms the locations
00109 ! and found information from the auxillary grid onto the Gauss
00110 ! grid.
00111 !
00112 ! !REVISION HISTORY:
00113 !   Date      Programmer   Description
00114 ! ----------  ----------   -----------
00115 ! 07.01.05    R. Redler    created
00116 !
00117 !EOP
00118 !----------------------------------------------------------------------
00119 !
00120 ! $Id: psmile_transform_gauss2.F90 2966 2011-02-18 09:47:30Z hanke $
00121 ! $Author: hanke $
00122 !
00123    Character(len=len_cvs_string), save :: mycvs = 
00124        '$Id: psmile_transform_gauss2.F90 2966 2011-02-18 09:47:30Z hanke $'
00125 !
00126 !----------------------------------------------------------------------
00127 !
00128 !  Initialization
00129 !
00130 #ifdef VERBOSE
00131       print 9990, trim(ch_id)
00132 
00133       call psmile_flushstd
00134 #endif /* VERBOSE */
00135 !
00136       npart = search%npart
00137 
00138 !===> Set z-coordinate (independent on supported grid types)
00139 
00140       do ipart = 1, npart
00141          gfound (ipart,indz)%vector     = found(ipart,3)%vector
00142          glocations (ipart,indz)%vector = locations(ipart,3)%vector
00143       enddo
00144 !
00145 ! Transform locations and found array depending on the target grid type
00146 !
00147       select case ( search%grid_type )
00148 
00149       case ( PRISM_irrlonlat_regvrt)
00150 !
00151 !===> ... Generate locations in gaussian reduced grid
00152 !
00153 ! Indication that we have changed from cell-based to point-based search
00154 ! old       if ( size( locations(ipart,1)%vector) /= &
00155 !                size(glocations(ipart,1)%vector) )
00156 
00157          do ipart = 1, search%npart
00158 !
00159 !===> ... Generate found vector in lonlat directon
00160 !         out of both partial found vectors in lon and lat direction
00161 !
00162             gfound (ipart, 1)%vector(:) = &
00163                min (found (ipart, 1)%vector(:), found (ipart, 2)%vector(:))
00164 
00165             ii = 1
00166             do j = search%range(1,2,ipart), search%range(2,2,ipart)
00167 !cdir vector
00168                do i = search%range(1,1,ipart), search%range(2,1,ipart)
00169 
00170                   n = psmile_transform_index_3d_to_1d ((/i, j, 1/), &
00171                                                        search%range(:,:,ipart))
00172 
00173                   if ( gfound(ipart,1)%vector(ii) == 1 ) then
00174                      glocations(ipart,1)%vector(ii) = &
00175                         map(locations(ipart,1)%vector(n),locations(ipart,2)%vector(n), 1)
00176 #ifdef DEBUG_TRACE
00177                      if ( i == ictl_ind(1) .and. j == ictl_ind(2)) then
00178                         print 8990, trim(ch_id), locations(ipart,1)%vector(n), &
00179                                                  locations(ipart,2)%vector(n)
00180                      endif
00181 8990 format (1x, a, ': psmile_transform_gauss2 ictl location on aux grid: ', 2i10)
00182 #endif
00183                   else
00184                      glocations(ipart,1)%vector(ii) = PSMILe_undef
00185                   endif
00186                   ii = ii + 1
00187                end do ! i
00188             end do ! j
00189          end do !  ipart
00190 
00191       case ( PRISM_reglonlatvrt)
00192 !
00193 !===> ... Generate found vector in lonlat directon
00194 !         out of both partial found vectors in lon and lat direction
00195 !         The partial vectors are 1d vectors.
00196 !         The generated vector is a 1d vector.
00197 !
00198          do ipart = 1, search%npart
00199             ii = 1
00200             do jlat = 1, search%range(2,2,ipart)-search%range(1,2,ipart)+1
00201 !cdir vector
00202                do i = 1, search%range(2,1,ipart)-search%range(1,1,ipart)+1
00203 
00204                   gfound(ipart,1)%vector(ii) = &
00205                      min(found(ipart,1)%vector(i), found(ipart,2)%vector(jlat))
00206 
00207                   if ( gfound(ipart,1)%vector(ii) == 1 ) then
00208                      glocations(ipart,1)%vector(ii) =        &
00209                           map(locations(ipart,1)%vector(i),  &
00210                               locations(ipart,2)%vector(jlat), 1)
00211                   else
00212                      glocations(ipart,1)%vector(ii) = PSMILe_undef
00213                   endif
00214                   ii = ii + 1
00215                end do ! i
00216             end do ! jlat
00217          end do ! ipart
00218 
00219       case ( PRISM_Gaussreduced_regvrt, PRISM_Irrlonlatvrt)
00220 
00221          do ipart = 1, search%npart
00222             gfound (ipart, 1)%vector(:) = &
00223                min (found (ipart, 1)%vector(:), found (ipart, 2)%vector(:))
00224 
00225 !cdir vector
00226             do i = 1, glen(ipart,1)
00227                if ( gfound(ipart,1)%vector(i) == 1 ) then
00228                   glocations(ipart,1)%vector(i) = &
00229                      map(locations(ipart,1)%vector(i),locations(ipart,2)%vector(i), 1)
00230                else
00231                   glocations(ipart,1)%vector(i) = PSMILe_undef
00232                endif
00233             enddo ! i
00234          enddo ! ipart
00235 
00236 !     case ( PRISM_Irrlonlatvrt)
00237 !     wuerde einen vollen 3d-vector brauchen
00238 !     wird in einer anderen Routine gemacht ?!/
00239 
00240       case default
00241 
00242          ierrp (1) = search%grid_type
00243          ierror = PRISM_Error_Internal
00244          call psmile_error ( ierror, 'unsupported search grid type', &
00245               ierrp, 1, __FILE__, __LINE__ )
00246          return
00247 
00248       end select
00249 
00250 ! there may be points, that were found on the auxiliary grid but are not on the actual
00251 ! reduced gauss grid. For these points, the gfound vector needs to be adjusted accordingly.
00252 
00253       do ipart = 1, search%npart
00254         where (glocations(ipart,1)%vector(:) < grid_valid_shape(1) .or. &
00255                 glocations(ipart,1)%vector(:) > grid_valid_shape(2))
00256 
00257                gfound(ipart,1)%vector(:) = -(nlev+1)
00258          end where
00259       enddo
00260 
00261 !
00262 !-----------------------------------------------------------------------
00263 !     All done
00264 !-----------------------------------------------------------------------
00265 !
00266 #ifdef VERBOSE
00267       print 9980, trim(ch_id), ierror
00268 
00269       call psmile_flushstd
00270 #endif /* VERBOSE */
00271 !
00272 !  Formats:
00273 !
00274 9990 format (1x, a, ': psmile_transform_gauss2')
00275 9980 format (1x, a, ': psmile_transform_gauss2: eof ierror =', i4)
00276 
00277       end subroutine psmile_transform_gauss2

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1