New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 8862 for branches/2015/nemo_v3_6_STABLE/NEMOGCM/TOOLS/SIREN/src/grid.f90 – NEMO

Ignore:
Timestamp:
2017-11-30T16:58:49+01:00 (6 years ago)
Author:
jpaul
Message:

Bugs fix: see tickets #1989

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2015/nemo_v3_6_STABLE/NEMOGCM/TOOLS/SIREN/src/grid.f90

    r7372 r8862  
    218218!> @date February, 2015 
    219219!> - add function grid_fill_small_msk to fill small domain inside bigger one 
    220 !> @February, 2016 
     220!> @date February, 2016 
    221221!> - improve way to check coincidence (bug fix) 
    222222!> - manage grid cases for T,U,V or F point, with even or odd refinment (bug fix) 
     223!> @date April, 2016 
     224!> - add function to get closest grid point using coarse grid coordinates strucutre  
    223225! 
    224226!> @note Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt) 
     
    271273   PRIVATE :: grid__get_coarse_index_cc ! - using coarse and fine grid array of lon,lat 
    272274 
     275                                     ! return closest coarse grid point from another point 
     276   PRIVATE :: grid__get_closest_str    ! - using coarse grid coordinates strucutre 
     277   PRIVATE :: grid__get_closest_arr    ! - using coarse grid array of lon,lat 
     278 
    273279                                     ! get offset between fine and coarse grid 
    274280   PRIVATE :: grid__get_fine_offset_ff ! - using coarse and fine grid coordinates files 
     
    333339      MODULE PROCEDURE grid__get_ghost_mpp 
    334340   END INTERFACE  grid_get_ghost 
     341 
     342   INTERFACE  grid_get_closest 
     343      MODULE PROCEDURE grid__get_closest_str 
     344      MODULE PROCEDURE grid__get_closest_arr 
     345   END INTERFACE  grid_get_closest 
    335346 
    336347   INTERFACE  grid_get_coarse_index 
     
    467478   !------------------------------------------------------------------- 
    468479   !> @brief This subroutine get information about global domain, given mpp 
    469    !> strucutre. 
     480   !> structure. 
    470481   !> 
    471482   !> @details 
     
    536547 
    537548      SELECT CASE(il_perio) 
    538       CASE(3,4) 
    539          il_pivot=1 
    540       CASE(5,6) 
    541          il_pivot=0 
    542       CASE(0,1,2) 
    543          il_pivot=1 
     549         CASE(3,4) 
     550            il_pivot=1 
     551         CASE(5,6) 
     552            il_pivot=0 
     553         CASE(0,1,2) 
     554            il_pivot=1 
    544555      END SELECT 
    545556 
     
    13651376            END SELECT 
    13661377         ELSE 
     1378            il_perio=-1 
    13671379            ! check periodicity 
    13681380            IF(ANY(td_var%d_value(   1     ,:,1,1)/=td_var%d_fill).OR.& 
     
    16561668   !> else return the size of the ovarlap band. 
    16571669   !> East-West overlap is computed comparing longitude value of the   
    1658    !> South" part of the domain, to avoid  north fold boundary. 
     1670   !> South part of the domain, to avoid  north fold boundary. 
    16591671   !> 
    16601672   ! 
     
    16631675   !> @date October, 2014 
    16641676   !> - work on mpp file structure instead of file structure 
     1677   !> @date October, 2016 
     1678   !> - check longitude as longname 
    16651679   !> 
    16661680   !> @param[in] td_lon longitude variable structure  
     
    17121726            ALLOCATE( dl_vare(il_jmax-il_jmin+1) ) 
    17131727            ALLOCATE( dl_varw(il_jmax-il_jmin+1) ) 
    1714              
     1728 
    17151729            dl_vare(:)=dl_value(il_east,il_jmin:il_jmax) 
    17161730            dl_varw(:)=dl_value(il_west,il_jmin:il_jmax) 
    1717              
    1718             IF( .NOT.(  ALL(dl_vare(:)==td_var%d_fill) .AND. & 
    1719             &           ALL(dl_varw(:)==td_var%d_fill) ) )THEN 
    1720           
    1721                IF( TRIM(td_var%c_stdname) == 'longitude' )THEN 
     1731 
     1732            IF( .NOT.( ALL(dl_vare(:)==td_var%d_fill) .AND. & 
     1733            &          ALL(dl_varw(:)==td_var%d_fill) ) )THEN 
     1734 
     1735               IF( TRIM(td_var%c_stdname) == 'longitude' .OR. & 
     1736                 & SCAN( TRIM(td_var%c_longname), 'longitude') == 0 )THEN 
    17221737                  WHERE( dl_value(:,:) > 180._dp .AND. & 
    17231738                  &      dl_value(:,:) /= td_var%d_fill )  
     
    17431758                     ELSE 
    17441759                        dl_vare(:)=dl_value(il_east-ji,il_jmin:il_jmax) 
    1745                          
     1760 
    17461761                        IF( ALL( dl_varw(:) == dl_vare(:) ) )THEN 
    17471762                           grid__get_ew_overlap_var=ji+1 
     
    17691784   !> else return the size of the ovarlap band. 
    17701785   !> East-West overlap is computed comparing longitude value of the   
    1771    !> South" part of the domain, to avoid  north fold boundary. 
     1786   !> South part of the domain, to avoid  north fold boundary. 
    17721787   !> 
    17731788   !> @author J.Paul 
    17741789   !> @date October, 2014 - Initial Version 
     1790   !> @date October, 2016 
     1791   !> - check varid for longitude_T 
    17751792   !> 
    17761793   !> @param[in] td_file file structure  
     
    17931810      !---------------------------------------------------------------- 
    17941811 
    1795       il_varid=var_get_index(td_file%t_var(:), 'longitude') 
     1812      il_varid=var_get_id(td_file%t_var(:), 'longitude', 'longitude_T') 
    17961813      IF( il_varid /= 0 )THEN 
    17971814         ! read longitude on boundary 
    1798          tl_var=iom_read_var(td_file, 'longitude') 
     1815         tl_var=iom_read_var(td_file, il_varid) 
    17991816      ELSE 
    18001817         DO ji=1,td_file%i_nvar 
     
    18191836   !> else return the size of the ovarlap band. 
    18201837   !> East-West overlap is computed comparing longitude value of the   
    1821    !> South" part of the domain, to avoid  north fold boundary. 
     1838   !> South part of the domain, to avoid  north fold boundary. 
    18221839   !> 
    18231840   ! 
     
    18261843   !> @date October, 2014 
    18271844   !> - work on mpp file structure instead of file structure 
     1845   !> @date October, 2016 
     1846   !> - check varid for longitude_T 
    18281847   !> 
    18291848   !> @param[in] td_mpp mpp structure  
     
    18501869 
    18511870      ! read longitude on boundary 
    1852       il_varid=var_get_index(td_mpp%t_proc(1)%t_var(:),'longitude') 
     1871      il_varid=var_get_id(td_mpp%t_proc(1)%t_var(:),'longitude', 'longitude_T') 
    18531872      IF( il_varid /= 0 )THEN 
    1854          tl_var=iom_mpp_read_var(td_mpp, 'longitude') 
     1873         tl_var=iom_mpp_read_var(td_mpp, il_varid) 
    18551874      ELSE 
    18561875         DO ji=1,td_mpp%t_proc(1)%i_nvar 
     
    18661885         grid__get_ew_overlap_mpp=il_ew 
    18671886      ENDIF 
    1868  
    18691887 
    18701888      ! clean 
     
    30203038   !> 
    30213039   !> @author J.Paul 
     3040   !> @date April, 2016 - Initial Version 
     3041   !> @date October, 2016 
     3042   !> - use max of zero and east-west overlap instead of east-west overlap 
     3043   !> 
     3044   !> @param[in] td_coord0 coarse grid coordinate mpp structure 
     3045   !> @param[in] dd_lon1   fine   grid longitude 
     3046   !> @param[in] dd_lat1   fine   grid latitude 
     3047   !> @param[in] cd_pos    relative position of grid point from point  
     3048   !> @param[in] dd_fill   fill value 
     3049   !> @return coarse grid indices of closest point of fine grid point 
     3050   !------------------------------------------------------------------- 
     3051   FUNCTION grid__get_closest_str( td_coord0, dd_lon1, dd_lat1, cd_pos, dd_fill ) & 
     3052   &  RESULT(id_res) 
     3053 
     3054      IMPLICIT NONE 
     3055      ! Argument 
     3056      TYPE(TMPP )     , INTENT(IN) :: td_coord0 
     3057      REAL(dp),         INTENT(IN) :: dd_lon1 
     3058      REAL(dp),         INTENT(IN) :: dd_lat1 
     3059      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_pos 
     3060      REAL(dp),         INTENT(IN), OPTIONAL :: dd_fill 
     3061 
     3062      ! function 
     3063      INTEGER(i4), DIMENSION(2) :: id_res 
     3064 
     3065      ! local variable 
     3066      CHARACTER(LEN=lc)                        :: cl_point 
     3067      CHARACTER(LEN=lc)                        :: cl_name 
     3068 
     3069      INTEGER(i4)                              :: il_ind 
     3070      INTEGER(i4)                              :: il_ew 
     3071 
     3072      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_lon0 
     3073      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_lat0 
     3074 
     3075      TYPE(TVAR)                               :: tl_lon0 
     3076      TYPE(TVAR)                               :: tl_lat0 
     3077      TYPE(TMPP)                               :: tl_coord0 
     3078      !---------------------------------------------------------------- 
     3079 
     3080      id_res(:)=-1 
     3081      cl_point='T' 
     3082 
     3083      ! copy structure 
     3084      tl_coord0=mpp_copy(td_coord0) 
     3085 
     3086      IF( .NOT. ASSOCIATED(tl_coord0%t_proc) )THEN 
     3087 
     3088         CALL logger_error("GRID GET CLOSEST: decompsition of mpp "//& 
     3089         &  "file "//TRIM(tl_coord0%c_name)//" not defined." ) 
     3090 
     3091      ELSE 
     3092 
     3093         ! open mpp files 
     3094         CALL iom_mpp_open(tl_coord0) 
     3095  
     3096         ! read coarse longitue and latitude 
     3097         WRITE(cl_name,*) 'longitude_'//TRIM(cl_point) 
     3098         il_ind=var_get_id(tl_coord0%t_proc(1)%t_var(:), cl_name) 
     3099         IF( il_ind == 0 )THEN 
     3100            CALL logger_warn("GRID GET CLOSEST: no variable "//& 
     3101            &  TRIM(cl_name)//"in file "//TRIM(tl_coord0%c_name)//". & 
     3102            &  try to use longitude.") 
     3103            WRITE(cl_name,*) 'longitude' 
     3104         ENDIF 
     3105         tl_lon0=iom_mpp_read_var(tl_coord0, TRIM(cl_name)) 
     3106  
     3107         WRITE(cl_name,*) 'latitude_'//TRIM(cl_point) 
     3108         il_ind=var_get_id(tl_coord0%t_proc(1)%t_var(:), cl_name) 
     3109         IF( il_ind == 0 )THEN 
     3110            CALL logger_warn("GRID GET CLOSEST: no variable "//& 
     3111            &  TRIM(cl_name)//"in file "//TRIM(tl_coord0%c_name)//". & 
     3112            &  try to use latitude.") 
     3113            WRITE(cl_name,*) 'latitude' 
     3114         ENDIF 
     3115         tl_lat0=iom_mpp_read_var(tl_coord0, TRIM(cl_name)) 
     3116 
     3117         ! close mpp files 
     3118         CALL iom_mpp_close(tl_coord0) 
     3119 
     3120         il_ew=MAX(0,tl_coord0%i_ew) 
     3121         ALLOCATE(dl_lon0(tl_coord0%t_dim(jp_I)%i_len-il_ew, & 
     3122            &             tl_coord0%t_dim(jp_J)%i_len) )              
     3123         ALLOCATE(dl_lat0(tl_coord0%t_dim(jp_I)%i_len-il_ew, & 
     3124            &             tl_coord0%t_dim(jp_J)%i_len) ) 
     3125 
     3126         dl_lon0(:,:)=tl_lon0%d_value(il_ew+1:,:,1,1) 
     3127         dl_lat0(:,:)=tl_lat0%d_value(il_ew+1:,:,1,1) 
     3128 
     3129         id_res(:)=grid_get_closest( dl_lon0, dl_lat0, dd_lon1, dd_lat1, cd_pos, dd_fill ) 
     3130 
     3131         DEALLOCATE(dl_lon0, dl_lat0) 
     3132         CALL var_clean(tl_lon0) 
     3133         CALL var_clean(tl_lat0) 
     3134         CALL mpp_clean(tl_coord0) 
     3135 
     3136      ENDIF 
     3137 
     3138   END FUNCTION  grid__get_closest_str 
     3139   !------------------------------------------------------------------- 
     3140   !> @brief This function return grid indices of the closest point 
     3141   !> from point (lon1,lat1)  
     3142   !>  
     3143   !> @details 
     3144   !> 
     3145   !> @note overlap band should have been already removed from coarse grid array  
     3146   !> of longitude and latitude, before running this function 
     3147   !> 
     3148   !> if you add cd_pos argument, you could choice to return closest point at 
     3149   !> - lower left  (ll) of the point 
     3150   !> - lower right (lr) of the point 
     3151   !> - upper left  (ul) of the point 
     3152   !> - upper right (ur) of the point 
     3153   !> - lower       (lo) of the point 
     3154   !> - upper       (up) of the point 
     3155   !> -       left  (le) of the point 
     3156   !> -       right (ri) of the point 
     3157   !> 
     3158   !> @author J.Paul 
    30223159   !> @date November, 2013 - Initial Version 
    30233160   !> @date February, 2015 
     
    30343171   !> @return coarse grid indices of closest point of fine grid point 
    30353172   !------------------------------------------------------------------- 
    3036    FUNCTION grid_get_closest( dd_lon0, dd_lat0, dd_lon1, dd_lat1, cd_pos, dd_fill ) 
     3173   FUNCTION grid__get_closest_arr( dd_lon0, dd_lat0, dd_lon1, dd_lat1, cd_pos, dd_fill ) 
    30373174      IMPLICIT NONE 
    30383175      ! Argument 
     
    30453182 
    30463183      ! function 
    3047       INTEGER(i4), DIMENSION(2) :: grid_get_closest 
     3184      INTEGER(i4), DIMENSION(2) :: grid__get_closest_arr 
    30483185 
    30493186      ! local variable 
     
    32613398         END SELECT 
    32623399      ENDIF 
    3263       grid_get_closest(:)=MINLOC(dl_dist(:,:),dl_dist(:,:)/=NF90_FILL_DOUBLE) 
    3264  
    3265       grid_get_closest(1)=grid_get_closest(1)+il_iinf-1 
    3266       grid_get_closest(2)=grid_get_closest(2)+il_jinf-1 
     3400      grid__get_closest_arr(:)=MINLOC(dl_dist(:,:),dl_dist(:,:)/=NF90_FILL_DOUBLE) 
     3401 
     3402      grid__get_closest_arr(1)=grid__get_closest_arr(1)+il_iinf-1 
     3403      grid__get_closest_arr(2)=grid__get_closest_arr(2)+il_jinf-1 
    32673404 
    32683405      DEALLOCATE( dl_dist ) 
    32693406      DEALLOCATE( dl_lon0 ) 
    32703407 
    3271    END FUNCTION grid_get_closest 
     3408   END FUNCTION grid__get_closest_arr 
    32723409   !------------------------------------------------------------------- 
    32733410   !> @brief This function compute the distance between a point A and grid points.   
     
    34753612         ENDIF 
    34763613         tl_lat0=iom_mpp_read_var(tl_coord0, TRIM(cl_name)) 
    3477           
     3614 
    34783615         ! close mpp files 
    34793616         CALL iom_mpp_close(tl_coord0) 
     
    46474784 
    46484785      IF( ll_even )THEN 
     4786 
    46494787         ! look for variable value on domain for F point 
    46504788         il_ind=var_get_index(tl_coord0%t_proc(1)%t_var(:), 'longitude_F') 
     
    51125250      dl_lon1 = dd_lon1(il_imin1, il_jmax1) 
    51135251      dl_lat1 = dd_lat1(il_imin1, il_jmax1) 
    5114  
    51155252 
    51165253      IF( (ABS(dl_lon1-dl_lon0)>dp_delta) .AND. (dl_lon1 < dl_lon0) .OR. & 
Note: See TracChangeset for help on using the changeset viewer.