psmile_mg_found_loc_to_3d.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_found_loc_to_3d
00008 !
00009 ! !INTERFACE:
00010 
00011       subroutine psmile_mg_found_loc_to_3d (search, nlev,  &
00012                       source_grid_type,                    &
00013                       found, locations, len,               &
00014                       virtual, virtual_cell_required,      &
00015                       found_3d, locations_3d, virtual_3d, ierror)
00016 !
00017 ! !USES:
00018 !
00019       use PRISM_constants
00020 !
00021       use PSMILe, dummy_interface => PSMILe_MG_found_loc_to_3d
00022 
00023       implicit none
00024 !
00025 ! !INPUT PARAMETERS:
00026 !
00027       Type (Enddef_search), Intent (In)  :: search
00028 
00029 !     Info's on coordinates to be searched
00030 !
00031       Integer, Intent (In)               :: nlev
00032 
00033 !     Number of coords to be searched in first 2 irregular directions.
00034 !
00035       Integer, Intent (In)               :: source_grid_type
00036 
00037 !     Grid type of source grid (i.e. on which the points are searched)
00038 
00039       Integer, Intent (In)               :: len (search%npart, *)
00040 
00041 !     Number of coords to be searched in all directions.
00042 !     The second dimension depends on the grid type of
00043 !     the source grid "source_grid_type". The second dimension is:
00044 !     1 for a source grid of type "PRISM_Irrlonlatvrt"
00045 !           len (*)    = Number of coordinates to be searched
00046 !     2 for a source grid of type "PRISM_Irrlonlat_Regvrt"
00047 !           len (*, 1) = Number of coords to be searched in first 2 irregular
00048 !                        directions.
00049 !           len (*, 2) = Number of coords to be searched in regular z- direction.
00050 !     3 for a source grid of type "PRISM_Reglonlatvrt"
00051 !           len (*, i) = Number of coordinates to be searched in "i-th" direction
00052 ! |TODO
00053 !     ! Unschoen ! Vereinheitlichen
00054 !
00055       Type (integer_vector), Intent (In) :: found (search%npart, ndim_3d)
00056 !
00057 !     Finest level number on which a grid cell was found in the
00058 !     method grid for point I.
00059 !     found()%vector (i) =  1 = val_direct :
00060 !                               Point was found on a point of the method grid.
00061 !     found()%vector (i) = -1 = val_coupler:
00062 !                               Point was found in a cell  of the method grid
00063 !     Level number < -1       : Last level number on which point was found.
00064 !     Level number = -(nlev+1): Never found (input value)
00065 !
00066       Type (integer_vector), Intent (In) :: locations (search%npart, ndim_3d)
00067 !
00068 !     Indices of the grid cell 
00069 !     in which the point was found in the method (corner) grid.
00070 !
00071       Type (integer_vector), Intent (In) :: virtual (search%npart)
00072 
00073 !     Code for virtual cells if point was found in virtual method cell
00074 !     Currently available only for grids of
00075 !     type "PRISM_Gaussreduced_regvrt".
00076 !
00077       Logical,               Intent (In) :: virtual_cell_required
00078 !
00079 !     Is the virtual cell info available and is it required to 
00080 !     generate the 3d virtual cell info ?
00081 !
00082 ! !OUTPUT PARAMETERS:
00083 !
00084       Type (integer_vector), Intent(Out) :: found_3d     (search%npart)
00085 
00086 !     Finest level number on which a grid cell was found in the
00087 !     method grid for point I stored as 3d arrays.
00088 
00089       Type (integer_vector), Intent(Out) :: locations_3d (search%npart)
00090 !
00091 !     Indices of the grid cell 
00092 !     in which the point was found in the method (corner) grid stored
00093 !     as 3d arrays.
00094 !
00095       Type (integer_vector), Intent(Out) :: virtual_3d (search%npart)
00096 !
00097 !     Code for the virtual cell
00098 !     in which the point was found in the method (corner) grid stored
00099 !     as 3d arrays. Only set if "virtual_cell_required" == .true.
00100 !
00101       Integer, Intent (Out)              :: ierror
00102 
00103 !     Returns the error code of PSMILe_MG_found_loc_to_3d;
00104 !             ierror = 0 : No error
00105 !             ierror > 0 : Severe error
00106 !
00107 ! !LOCAL VARIABLES
00108 !
00109 ! indl = Index of LonLat values in "found, locations"
00110 ! indz = Index of Vert   values in "found, locations"
00111 !
00112       Integer, Parameter           :: indl = 1
00113       Integer, Parameter           :: indz = 2
00114 !
00115       Integer                      :: i, j, k, ipart, npart
00116       Integer                      :: search_grid_type
00117       Integer                      :: not_found
00118 !
00119 !     ... for 
00120 !
00121       Integer                      :: len2, len3, nprev
00122       Integer                      :: leni, lenj, lenk
00123       Integer                      :: leni_mask, lenj_mask, lenk_mask
00124       Integer                      :: ii, jj
00125 !
00126 !     ... for error parameters
00127 !
00128       Integer, parameter           :: nerrp = 2
00129       Integer                      :: ierrp (nerrp)
00130 !
00131 ! !DESCRIPTION:
00132 !
00133 ! Subroutine "PSMILe_MG_found_loc_to_3d" transforms the input fields
00134 ! "found" and "locations" (containing the results of the MG search)
00135 ! into the fully 3d versions of that fields.
00136 ! Additionally, the mask "search_mask" of the points to be searched
00137 ! is applied if required.
00138 !
00139 ! TODO: irrlonlat_regvrt and gauss_reduced should be handled
00140 !       identically
00141 !
00142 ! !REVISION HISTORY:
00143 !   Date      Programmer   Description
00144 ! ----------  ----------   -----------
00145 ! 03.07.05    H. Ritzdorf  created
00146 !
00147 !EOP
00148 !----------------------------------------------------------------------
00149 !
00150 ! $Id: psmile_mg_found_loc_to_3d.F90 2788 2010-11-30 14:34:07Z hanke $
00151 ! $Author: hanke $
00152 !
00153    Character(len=len_cvs_string), save :: mycvs = 
00154      '$Id: psmile_mg_found_loc_to_3d.F90 2788 2010-11-30 14:34:07Z hanke $'
00155 !
00156 !----------------------------------------------------------------------
00157 !
00158 !  Initialization
00159 !
00160 #ifdef VERBOSE
00161       print 9990, trim(ch_id)
00162 
00163       call psmile_flushstd
00164 #endif /* VERBOSE */
00165 
00166       npart = search%npart
00167       search_grid_type = search%grid_type
00168 !
00169 !===>  Allocate full 3d vectors of "found" and "location"
00170 !      locations_3d koennte man sich sparen, wenn man die locations fuer
00171 !      jeden Index einzeln als vector abspeichert.
00172 !
00173          do ipart = 1, npart
00174 
00175          len3 = (search%range(2,1,ipart)-search%range(1,1,ipart)+1) * &
00176                 (search%range(2,2,ipart)-search%range(1,2,ipart)+1) * &
00177                 (search%range(2,3,ipart)-search%range(1,3,ipart)+1)
00178 
00179 #ifdef PRISM_ASSERTION
00180          if (source_grid_type == PRISM_Reglonlatvrt) then
00181             if (search_grid_type == PRISM_Irrlonlatvrt) then
00182                   do i = 1, ndim_3d
00183                   if (len3 /= len (ipart,i)) then
00184                      call psmile_assert (__FILE__, __LINE__, &
00185                                          "len3 /= len(ipart,i)")
00186                   endif 
00187                   end do
00188             else if (search_grid_type == PRISM_Irrlonlat_Regvrt) then
00189                   if (len3 /= len (ipart,1)*len(ipart,3)) then
00190                      print *, 'len3, len', len3, len (ipart,1:ndim_3d)
00191                      call psmile_assert (__FILE__, __LINE__, &
00192                                     "len3 /= len(ipart,1)*len(ipart,3)")
00193                   endif 
00194             else if (search_grid_type == PRISM_Reglonlatvrt) then
00195                   if (len3 /= len (ipart,1)*len(ipart,2)*len(ipart,3)) then
00196                      print *, 'len3, len', len3, len (ipart,1:ndim_3d)
00197                      call psmile_assert (__FILE__, __LINE__, &
00198                                  "len3 /= Product(len(ipart,1:ndim3d))")
00199                   endif 
00200             else if (search_grid_type == PRISM_Gaussreduced_regvrt) then
00201                   if (len3 /= len (ipart,1)*len(ipart,3)) then
00202                      print *, 'len3, len', len3, len (ipart,1:ndim_3d)
00203                      call psmile_assert (__FILE__, __LINE__, &
00204                                     "len3 /= len(ipart,1)*len(ipart,3)")
00205                   endif 
00206            endif
00207 !
00208          else if (source_grid_type == PRISM_Irrlonlat_Regvrt) then
00209             if (search_grid_type == PRISM_Irrlonlatvrt) then
00210                   do i = 1, 2
00211                   if (len3 /= len (ipart,i)) then
00212                      call psmile_assert (__FILE__, __LINE__, &
00213                                          "len3 /= len(ipart,i)")
00214                   endif 
00215                   end do
00216             else if (search_grid_type == PRISM_Gaussreduced_regvrt) then
00217                   if (len3 /= len (ipart,1)*len(ipart,2)) then
00218                      print *, 'len3, len', len3, len (ipart,1:2)
00219                      call psmile_assert (__FILE__, __LINE__, &
00220                                   "len3 /= len(ipart,1)*len(ipart,2)")
00221                   endif 
00222             else ! if (search_grid_type == PRISM_Irrlonlat_Regvrt .or.
00223                  !     search_grid_type == PRISM_Reglonlatvrt) then
00224                   if (len3 /= len (ipart,1)*len(ipart,2)) then
00225                      print *, 'len3, len', len3, len (ipart,1:2)
00226                      call psmile_assert (__FILE__, __LINE__, &
00227                                   "len3 /= len(ipart,1)*len(ipart,2)")
00228                   endif 
00229             endif
00230 !
00231          else if (source_grid_type == PRISM_Gaussreduced_Regvrt) then
00232             if (search_grid_type == PRISM_Irrlonlatvrt) then
00233                   do i = 1, 2
00234                   if (len3 /= len (ipart,i)) then
00235                      call psmile_assert (__FILE__, __LINE__, &
00236                                                 "len3 /= len(ipart,i)")
00237                   endif 
00238                   end do
00239             else if (search_grid_type == PRISM_Gaussreduced_regvrt) then
00240                   if (len3 /= len (ipart,1)*len(ipart,2)) then
00241                      print *, 'len3, len', len3, len (ipart,1:2)
00242                      call psmile_assert (__FILE__, __LINE__, &
00243                                   "len3 /= len(ipart,1)*len(ipart,3)")
00244                   endif 
00245             else ! if (search_grid_type == PRISM_Irrlonlat_Regvrt .or.
00246                  !     search_grid_type == PRISM_Reglonlatvrt) then
00247                   if (len3 /= len (ipart,1)*len(ipart,2) ) then
00248                      call psmile_assert (__FILE__, __LINE__, &
00249                                    "len3 /= len(ipart,1)*len(ipart,2)")
00250                   endif
00251             endif
00252 !
00253          else if (source_grid_type == PRISM_Irrlonlatvrt) then
00254             if (len3 /= len (ipart,1)) then
00255                call psmile_assert (__FILE__, __LINE__, &
00256                                    "len3 /= len(ipart,1)")
00257             endif 
00258          endif
00259 !
00260          if (virtual_cell_required .and. &
00261              source_grid_type /= PRISM_Gaussreduced_regvrt) then
00262 
00263             call psmile_assert (__FILE__, __LINE__, &
00264                "virtual_cell_required only available for PRISM_Gaussreduced_regvrt")
00265          endif
00266 #endif
00267 
00268          Allocate (found_3d(ipart)%vector(len3), STAT = ierror)
00269          if ( ierror > 0 ) then
00270             ierrp (1) = ierror
00271             ierrp (2) = len3
00272             ierror = PRISM_Error_Alloc
00273             call psmile_error ( ierror, 'found_3d(ipart)%vector', &
00274                                 ierrp, 2, __FILE__, __LINE__ )
00275             return
00276          endif
00277 !
00278          Allocate (locations_3d(ipart)%vector(ndim_3d*len3), STAT = ierror)
00279          if ( ierror > 0 ) then
00280             ierrp (1) = ierror
00281             ierrp (2) = len3 * ndim_3d
00282             ierror = PRISM_Error_Alloc
00283             call psmile_error ( ierror, 'locations_3d(ipart)%vector', &
00284                                 ierrp, 2, __FILE__, __LINE__ )
00285             return
00286          endif
00287 !
00288          if (virtual_cell_required) then
00289             Allocate (virtual_3d(ipart)%vector(len3), STAT = ierror)
00290             if ( ierror > 0 ) then
00291                ierrp (1) = ierror
00292                ierrp (2) = len3
00293                ierror = PRISM_Error_Alloc
00294                call psmile_error ( ierror, 'virtual(ipart)%vector', &
00295                                    ierrp, 2, __FILE__, __LINE__ )
00296                return
00297             endif
00298          endif
00299          end do ! ipart
00300 !
00301 !-----------------------------------------------------------------------
00302 !      Source grid is regular in all directions;
00303 !      i.e. all target points are searched for all directions
00304 !      separately.
00305 !-----------------------------------------------------------------------
00306 !
00307       if (source_grid_type == PRISM_Reglonlatvrt) then
00308 !
00309          if (search_grid_type == PRISM_Irrlonlatvrt) then
00310 !
00311 !===> ... Target grid is of type PRISM_Irrlonlatvrt;
00312 !         i.e. target grid is fully irregular in all directions and
00313 !              points to be searched are stored as 3d array.
00314 !         len(ipart,1) == len(ipart,2) == len(ipart,3)
00315 !
00316                do ipart = 1, npart
00317 !cdir vector
00318                   do i = 1, len(ipart,1)
00319                   found_3d(ipart)%vector(i) = &
00320                      min (found(ipart,1)%vector(i), &
00321                           found(ipart,2)%vector(i), &
00322                           found(ipart,3)%vector(i))
00323                   end do ! i
00324                end do ! ipart
00325 !
00326                do ipart = 1, npart
00327 !cdir vector
00328                   do i = 1, len(ipart,1)
00329                   locations_3d(ipart)%vector((i-1)*ndim_3d+1) = &
00330                      locations(ipart,1)%vector(i)
00331                   locations_3d(ipart)%vector((i-1)*ndim_3d+2) = &
00332                      locations(ipart,2)%vector(i)
00333                   locations_3d(ipart)%vector((i-1)*ndim_3d+3) = &
00334                      locations(ipart,3)%vector(i)
00335                   end do ! i
00336 
00337                end do ! ipart
00338 
00339          else if (search_grid_type == PRISM_Irrlonlat_Regvrt) then
00340 !
00341 !===> ... Target grid is of type PRISM_Irrlonlat_Regvrt;
00342 !         i.e. target grid is irregular in LonLat directions and
00343 !              regular in z-direction.
00344 !              Points to be searched are stored as 2d array and 1d
00345 !              array.
00346 !         len(ipart,1) = Number of points in Lon and Lat direction (2d)
00347 !         len(ipart,2) = Number of points in Lon and Lat direction (2d)
00348 !         len(ipart,3) = Number of points in z-direction (1d)
00349 !
00350                do ipart = 1, npart
00351                   do k = 1, len(ipart,3)
00352                   nprev = (k-1)*len(ipart,1)
00353 !cdir vector
00354                      do i = 1, len(ipart,1)
00355                      found_3d(ipart)%vector(nprev+i) = &
00356                         min (found(ipart,1)%vector(i), &
00357                              found(ipart,2)%vector(i), &
00358                              found(ipart,3)%vector(k))
00359                      end do ! i
00360                   end do ! k
00361                end do ! ipart
00362 !
00363                do ipart = 1, npart
00364                   do k = 1, len(ipart,3)
00365                   nprev = (k-1)*len(ipart,1) * ndim_3d
00366 !cdir vector
00367                      do i = 1, len(ipart,1)
00368                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+1) = &
00369                         locations(ipart,1)%vector(i)
00370                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+2) = &
00371                         locations(ipart,2)%vector(i)
00372                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+3) = &
00373                         locations(ipart,3)%vector(k)
00374                      end do ! i
00375 
00376                   end do ! k
00377                end do ! ipart
00378 !
00379          else if (search_grid_type == PRISM_Gaussreduced_Regvrt) then
00380 !
00381 !===> ... Target grid is of type PRISM_Gaussreduced_Regvrt;
00382 !         i.e. target grid is irregular in LonLat directions and
00383 !              regular in z-direction.
00384 !              Points to be searched are stored as 2d array and 1d
00385 !              array.
00386 !         len(ipart,1) = Number of points in Lon and Lat direction (2d)
00387 !         len(ipart,2) = Number of points in Lon and Lat direction (2d)
00388 !         len(ipart,3) = Number of points in z-direction (1d)
00389 !
00390                do ipart = 1, npart
00391 
00392                   do k = 1, len(ipart,3)
00393                   nprev = (k-1)*len(ipart,1)
00394 !cdir vector
00395                      do i = 1, len(ipart,1)
00396                      found_3d(ipart)%vector(nprev+i) = &
00397                         min (found(ipart,1)%vector(i), &
00398                              found(ipart,2)%vector(i), &
00399                              found(ipart,3)%vector(k))
00400                      end do ! i
00401                   end do ! k
00402                end do ! ipart
00403 !
00404                do ipart = 1, npart
00405                   do k = 1, len(ipart,3)
00406                   nprev = (k-1)*len(ipart,1) * ndim_3d
00407 !cdir vector
00408                      do i = 1, len(ipart,1)
00409                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+1) = &
00410                         locations(ipart,1)%vector(i)
00411                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+2) = &
00412                         locations(ipart,2)%vector(i)
00413                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+3) = &
00414                         locations(ipart,3)%vector(k)
00415                      end do ! i
00416 
00417                   end do ! k
00418                end do ! ipart
00419 !
00420          else if (search_grid_type == PRISM_Reglonlatvrt) then
00421 !
00422 !===> ... Target grid is of type PRISM_Reglonlatvrt;
00423 !         i.e. target grid is regular in all directions.
00424 !              Points to be searched are stored as 1d arrays.
00425 !
00426 ! ? Loops splitten und konstante Teile einzeln zuweisen ?
00427 !
00428                do ipart = 1, npart
00429                len2 = len(ipart,1) * len(ipart,2)
00430 !
00431                   do k = 1, len(ipart,3)
00432                      do j = 1, len(ipart,2)
00433                      nprev = (k-1)*len2 + (j-1)*len(ipart,1)
00434 !                    min1 = min (found(ipart,2)%vector(j), &
00435 !                                found(ipart,3)%vector(k))
00436 !cdir vector
00437                         do i = 1, len(ipart,1)
00438                         found_3d(ipart)%vector(nprev+i) = &
00439                            min (found(ipart,1)%vector(i), &
00440                                 found(ipart,2)%vector(j), &
00441                                 found(ipart,3)%vector(k))
00442                         end do ! i
00443                      end do ! j
00444                   end do ! k
00445                end do ! ipart
00446 !
00447                do ipart = 1, npart
00448                len2 = len(ipart,1) * len(ipart,2)
00449 !
00450                   do k = 1, len(ipart,3)
00451                      do j = 1, len(ipart,2)
00452                      nprev = ((k-1)*len2 + (j-1)*len(ipart,1)) * ndim_3d
00453 !cdir vector
00454                         do i = 1, len(ipart,1)
00455                         locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+1) = &
00456                            locations(ipart,1)%vector(i)
00457                         locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+2) = &
00458                            locations(ipart,2)%vector(j)
00459                         locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+3) = &
00460                            locations(ipart,3)%vector(k)
00461                         end do ! i
00462 
00463                      end do ! j
00464                   end do ! k
00465                end do ! ipart
00466          else
00467 !
00468 !===> ... Unknown target grid type
00469 !
00470             ierrp (1) = search_grid_type
00471             ierror = PRISM_Error_Internal
00472 
00473             call psmile_error ( ierror, 'Unknown search grid type', &
00474                                 ierrp, 1, __FILE__, __LINE__ )
00475             return
00476          endif
00477 !
00478 !-----------------------------------------------------------------------
00479 !      Source grid is irregular in LonLat direction and
00480 !      regular in z direction.
00481 !      i.e. all target points are searched for lonlat direction
00482 !      and z direction separately.
00483 !-----------------------------------------------------------------------
00484 !
00485       else if ( source_grid_type == PRISM_Irrlonlat_Regvrt ) then
00486 !
00487          if (search_grid_type == PRISM_Irrlonlatvrt) then
00488 !
00489 !===> ... Target grid is of type PRISM_Irrlonlatvrt;
00490 !         i.e. target grid is fully irregular in all directions and
00491 !              points to be searched are stored as 3d array.
00492 !         len(ipart,1) == len(ipart,2)
00493 !
00494                do ipart = 1, npart
00495 !cdir vector
00496                   do i = 1, len(ipart,1)
00497                   found_3d(ipart)%vector(i) = &
00498                      min (found(ipart,indl)%vector(i), &
00499                           found(ipart,indz)%vector(i))
00500                   end do ! i
00501                end do ! ipart
00502 !
00503                do ipart = 1, npart
00504 !cdir vector
00505                   do i = 1, len(ipart,1)
00506                   locations_3d(ipart)%vector((i-1)*ndim_3d+1) = &
00507                      locations(ipart,indl)%vector((i-1)*ndim_2d+1)
00508                   locations_3d(ipart)%vector((i-1)*ndim_3d+2) = &
00509                      locations(ipart,indl)%vector((i-1)*ndim_2d+2)
00510                   locations_3d(ipart)%vector((i-1)*ndim_3d+3) = &
00511                      locations(ipart,indz)%vector(i)
00512                   end do ! i
00513 
00514                end do ! ipart
00515 
00516          else if (search_grid_type == PRISM_Irrlonlat_Regvrt .or. &
00517                   search_grid_type == PRISM_Reglonlatvrt) then
00518 !
00519 !===> ... Target grid is of type PRISM_Irrlonlat_Regvrt;
00520 !         i.e. target grid is irregular in LonLat directions and
00521 !              regular in z-direction.
00522 !              Points to be searched are stored as 2d array and 1d
00523 !              array.
00524 !         or Target grid is of type PRISM_Reglonlatvrt;
00525 !         i.e. target grid is regular in all directions.
00526 !              Points to be searched were generated as 2d array and
00527 !              1d array.
00528 !         len(ipart,1) = Number of points in Lon and Lat direction (2d)
00529 !         len(ipart,2) = Number of points in z-direction (1d)
00530 !
00531                do ipart = 1, npart
00532                   do k = 1, len(ipart,2)
00533                   nprev = (k-1)*len(ipart,1)
00534 !cdir vector
00535                      do i = 1, len(ipart,1)
00536                      found_3d(ipart)%vector(nprev+i) =    &
00537                         min (found(ipart,indl)%vector(i), &
00538                              found(ipart,indz)%vector(k))
00539                      end do ! i
00540                   end do ! k
00541                end do ! ipart
00542 
00543 !
00544                do ipart = 1, npart
00545                   do k = 1, len(ipart,2)
00546                   nprev = (k-1)*len(ipart,1) * ndim_3d
00547 !cdir vector
00548                      do i = 1, len(ipart,1)
00549                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+1) = &
00550                         locations(ipart,indl)%vector( (i-1)*ndim_2d+1)
00551                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+2) = &
00552                         locations(ipart,indl)%vector( (i-1)*ndim_2d+2)
00553                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+3) = &
00554                         locations(ipart,indz)%vector(k)
00555                      end do ! i
00556 
00557                   end do ! k
00558                end do ! ipart
00559 
00560          else if (search_grid_type == PRISM_Gaussreduced_Regvrt) then
00561 !
00562 !===> ... Target grid is of type PRISM_Gaussreduced_Regvrt;
00563 !         i.e. target grid is irregular in LonLat directions and
00564 !              regular in z-direction.
00565 !              Points to be searched are stored as 2d array and 1d
00566 !              array.
00567 !         len(ipart,1) = Number of points in Lon and Lat direction (2d)
00568 !         len(ipart,2) = Number of points in Lon and Lat direction (2d)
00569 !         len(ipart,3) = Number of points in z-direction (1d)
00570 !
00571                do ipart = 1, npart
00572                   do k = 1, len(ipart,2)
00573                   nprev = (k-1)*len(ipart,1)
00574 !cdir vector
00575                      do i = 1, len(ipart,1)
00576                      if ( found(ipart,indl)%vector(i) > 1 .or. &
00577                           found(ipart,indz)%vector(k) > 1 ) then
00578                         found_3d(ipart)%vector(nprev+i) = -(nlev+1)
00579                      else
00580                         found_3d(ipart)%vector(nprev+i) = &
00581                            min (found(ipart,indl)%vector(i), &
00582                                 found(ipart,indz)%vector(k))
00583                      endif
00584                      end do ! i
00585                   end do ! k
00586                end do ! ipart
00587 !
00588                do ipart = 1, npart
00589                   do k = 1, len(ipart,2)
00590                   nprev = (k-1)*len(ipart,1) * ndim_3d
00591 !cdir vector
00592                      do i = 1, len(ipart,1)
00593                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+1) = &
00594                         locations(ipart,indl)%vector( (i-1)*ndim_2d+1)
00595                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+2) = &
00596                         locations(ipart,indl)%vector( (i-1)*ndim_2d+2)
00597                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+3) = &
00598                         locations(ipart,indz)%vector(k)
00599                      end do ! i
00600 
00601                   end do ! k
00602                end do ! ipart
00603 
00604          else
00605 !
00606 !===> ... Unknown target grid type
00607 !
00608             ierrp (1) = search_grid_type
00609             ierror = PRISM_Error_Internal
00610 
00611             call psmile_error ( ierror, 'Unknown search grid type', &
00612                                 ierrp, 1, __FILE__, __LINE__ )
00613             return
00614          endif
00615 !
00616 !-----------------------------------------------------------------------
00617 !     Source grid is GaussReduced grid
00618 !-----------------------------------------------------------------------
00619 !
00620       else if (source_grid_type == PRISM_Gaussreduced_Regvrt ) then
00621 !
00622          if (search_grid_type == PRISM_Irrlonlatvrt) then
00623 !
00624 !===> ... Target grid is of type PRISM_Irrlonlatvrt;
00625 !         i.e. target grid is fully irregular in all directions and
00626 !              points to be searched are stored as 3d array.
00627 !         len(ipart,1) == len(ipart,2)
00628 !
00629                do ipart = 1, npart
00630 !cdir vector
00631                   do i = 1, len(ipart,1)
00632                   found_3d(ipart)%vector(i) = &
00633                      min (found(ipart,indl)%vector(i), &
00634                           found(ipart,indz)%vector(i))
00635                   end do ! i
00636                end do ! ipart
00637 !
00638                do ipart = 1, npart
00639 !cdir vector
00640                   do i = 1, len(ipart,1)
00641 #ifdef STORE_LOCATION_AS_2D
00642                   locations_3d(ipart)%vector((i-1)*ndim_3d+1) = &
00643                      locations(ipart,indl)%vector((i-1)*ndim_2d+1)
00644                   locations_3d(ipart)%vector((i-1)*ndim_3d+2) = &
00645                      locations(ipart,indl)%vector((i-1)*ndim_2d+2)
00646 #else
00647                   locations_3d(ipart)%vector((i-1)*ndim_3d+1) = &
00648                      locations(ipart,indl)%vector(i)
00649                   locations_3d(ipart)%vector((i-1)*ndim_3d+2) = 1
00650 #endif
00651                   locations_3d(ipart)%vector((i-1)*ndim_3d+3) = &
00652                      locations(ipart,indz)%vector(i)
00653                   end do ! i
00654 
00655                end do ! ipart
00656 !
00657                if (virtual_cell_required) then
00658 !                 Currently virtual cell info only available for LonLat
00659 !                 part of GaussReduce Grid
00660 !
00661                   do ipart = 1, npart
00662                   virtual_3d(ipart)%vector(:) = virtual(ipart)%vector(:)
00663                   end do ! ipart
00664                endif
00665 
00666          else if (search_grid_type == PRISM_Irrlonlat_Regvrt .or. &
00667                   search_grid_type == PRISM_Reglonlatvrt     .or. &
00668                   search_grid_type == PRISM_Gaussreduced_Regvrt ) then
00669 !
00670 !===> ... Target grid is of type PRISM_Irrlonlat_Regvrt;
00671 !         i.e. target grid is irregular in LonLat directions and
00672 !              regular in z-direction.
00673 !              Points to be searched are stored as 2d array and 1d
00674 !              array.
00675 !         or Target grid is of type PRISM_Reglonlatvrt;
00676 !         i.e. target grid is regular in all directions.
00677 !              Points to be searched were generated as 2d array and
00678 !              1d array.
00679 !         len(ipart,1) = Number of points in Lon and Lat direction (2d)
00680 !         len(ipart,2) = Number of points in z-direction (1d)
00681 !
00682                do ipart = 1, npart
00683                   do k = 1, len(ipart,2)
00684                   nprev = (k-1)*len(ipart,1)
00685 !cdir vector
00686                      do i = 1, len(ipart,1)
00687                      found_3d(ipart)%vector(nprev+i) = &
00688                         min (found(ipart,indl)%vector(i), &
00689                              found(ipart,indz)%vector(k))
00690                      end do ! i
00691                   end do ! k
00692                end do ! ipart
00693 !
00694                do ipart = 1, npart
00695                   do k = 1, len(ipart,2)
00696                   nprev = (k-1)*len(ipart,1) * ndim_3d
00697 !cdir vector
00698                      do i = 1, len(ipart,1)
00699 #ifdef STORE_LOCATION_AS_2D
00700                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+1) = &
00701                         locations(ipart,indl)%vector( (i-1)*ndim_2d+1)
00702                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+2) = &
00703                         locations(ipart,indl)%vector( (i-1)*ndim_2d+2)
00704 #else
00705                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+1) = &
00706                         locations(ipart,indl)%vector(i)
00707                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+2) = 1
00708 #endif
00709 
00710                      locations_3d(ipart)%vector(nprev+(i-1)*ndim_3d+3) = &
00711                         locations(ipart,indz)%vector(k)
00712                      end do ! i
00713 
00714                   end do ! k
00715                end do ! ipart
00716 !
00717                if (virtual_cell_required) then
00718 !                 Currently virtual cell info only available for LonLat
00719 !                 part of GaussReduce Grid
00720 !
00721                   do ipart = 1, npart
00722                      do k = 1, len(ipart,2)
00723                      nprev = (k-1)*len(ipart,1)
00724                      virtual_3d(ipart)%vector(nprev+1:nprev+len(ipart,1)) = &
00725                         virtual(ipart)%vector(      1:      len(ipart,1))
00726                      end do ! k
00727                   end do ! ipart
00728                endif
00729 !
00730          else
00731 !
00732 !===> ... Unknown target grid type
00733 !
00734             ierrp (1) = search_grid_type
00735             ierror = PRISM_Error_Internal
00736 
00737             call psmile_error ( ierror, 'Unknown search grid type', &
00738                                 ierrp, 1, __FILE__, __LINE__ )
00739             return
00740          endif
00741 !
00742 !-----------------------------------------------------------------------
00743 !      Source grid is irregular in all directions
00744 !      i.e. all target points are searched in all 3 directions.
00745 !      Routine is not necessary
00746 !-----------------------------------------------------------------------
00747 !
00748       else if (source_grid_type == PRISM_Irrlonlatvrt) then
00749 !
00750          print 9970, trim(ch_id)
00751 !
00752             do ipart = 1, npart
00753             found_3d(ipart)%vector(:) = found(ipart,1)%vector(:)
00754             end do
00755 !
00756             do ipart = 1, npart
00757             locations_3d(ipart)%vector(:) = locations(ipart,1)%vector(:)
00758             end do
00759 !
00760 !-----------------------------------------------------------------------
00761 !     Unknown source grid type
00762 !-----------------------------------------------------------------------
00763 !
00764       else
00765          ierrp (1) = source_grid_type
00766          ierror = PRISM_Error_Internal
00767 
00768          call psmile_error ( ierror, 'Unknown source grid type', &
00769                              ierrp, 1, __FILE__, __LINE__ )
00770          return
00771 
00772       endif
00773 !
00774 !-----------------------------------------------------------------------
00775 !     Apply mask on points to be searched if required;
00776 !     i.e. set "found_3d" to -(nlev+1) ("not found")
00777 !          if search mask is not true.
00778 !-----------------------------------------------------------------------
00779 !
00780       if (Associated(search%search_mask)) then
00781 
00782          not_found = - (nlev+1)
00783          do ipart = 1, npart
00784 
00785             if ( search%msg_intersections%requires_conserv_remap /= PSMILe_conserv2D .and. &
00786                  search%msg_intersections%requires_conserv_remap /= PSMILe_conserv3D ) then
00787 
00788                len3 = (search%range(2,1,ipart)-search%range(1,1,ipart)+1) * &
00789                       (search%range(2,2,ipart)-search%range(1,2,ipart)+1) * &
00790                       (search%range(2,3,ipart)-search%range(1,3,ipart)+1)
00791 !cdir vector
00792                do i = 1, len3
00793                   if (.not. search%search_mask(ipart)%vector(i)) then
00794                      found_3d(ipart)%vector(i) = not_found
00795                   endif
00796                end do
00797 
00798             else
00799 
00800                leni =  search%range(2,1,ipart)-search%range(1,1,ipart)+1
00801                lenj =  search%range(2,2,ipart)-search%range(1,2,ipart)+1
00802                lenk =  search%range(2,3,ipart)-search%range(1,3,ipart)+1
00803 
00804                if ( search_grid_type == PRISM_Gaussreduced_Regvrt ) then
00805 
00806                   if ( search%msg_intersections%requires_conserv_remap == PSMILe_conserv2D ) then
00807                      leni_mask = (search%range(2,1,ipart)-search%range(1,1,ipart))/2 + 1
00808                      lenj_mask = 1
00809                      lenk_mask = search%range(2,3,ipart)-search%range(1,3,ipart)+1
00810                   else
00811                      leni_mask = (search%range(2,1,ipart)-search%range(1,1,ipart))/2 + 1
00812                      lenj_mask = 1
00813                      lenk_mask = search%range(2,3,ipart)-search%range(1,3,ipart)
00814                   endif
00815  
00816                   do k = 1, lenk_mask
00817                      do j = 1, lenj_mask
00818                         do i = 1, leni_mask
00819                            ii = (k-1)*lenj_mask*leni_mask+(j-1)*leni_mask+i
00820                            if (.not. search%search_mask(ipart)%vector(ii)) then
00821                               jj = (k-1)*lenj*leni+(j-1)*leni+i
00822                               found_3d(ipart)%vector(jj) = not_found
00823                            endif
00824                         enddo
00825                      enddo
00826                   enddo
00827 
00828                else
00829 
00830                   if ( search%msg_intersections%requires_conserv_remap == PSMILe_conserv2D ) then
00831                      leni_mask = search%range(2,1,ipart)-search%range(1,1,ipart)
00832                      lenj_mask = search%range(2,2,ipart)-search%range(1,2,ipart)
00833                      lenk_mask = search%range(2,3,ipart)-search%range(1,3,ipart)+1
00834                   else
00835                      leni_mask = search%range(2,1,ipart)-search%range(1,1,ipart)
00836                      lenj_mask = search%range(2,2,ipart)-search%range(1,2,ipart)
00837                      lenk_mask = search%range(2,3,ipart)-search%range(1,3,ipart)
00838                   endif
00839 
00840                   do k = 1, lenk_mask
00841                      do j = 1, lenj_mask
00842                         do i = 1, leni_mask
00843                            ii = (k-1)*lenj_mask*leni_mask+(j-1)*leni_mask+i
00844                            if (.not. search%search_mask(ipart)%vector(ii)) then
00845                               jj = (k-1)*lenj*leni+(j-1)*leni+i
00846                               found_3d(ipart)%vector(jj) = not_found
00847                            endif
00848                         enddo
00849                      enddo
00850                   enddo
00851 
00852                endif
00853 
00854             endif
00855 
00856          end do
00857       endif
00858 !
00859 !-----------------------------------------------------------------------
00860 !     All done
00861 !-----------------------------------------------------------------------
00862 !
00863 #ifdef VERBOSE
00864       print 9980, trim(ch_id), ierror
00865 
00866       call psmile_flushstd
00867 #endif /* VERBOSE */
00868 !
00869 !  Formats:
00870 !
00871 9990  format (1x, a, ': psmile_mg_found_loc_to_3d:')
00872 9980  format (1x, a, ': psmile_mg_found_loc_to_3d: eof ierror =', i4)
00873 !
00874 9970  format (/1x, a, ': ### WARNING PSMILe_MG_found_loc_to_3d called ', &
00875                       'for 3d arrays !!!',                               &
00876               /1x)
00877 
00878       end subroutine PSMILe_MG_found_loc_to_3d

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1