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 7025 for branches/2016/dev_r6999_CONFIGMAN_1/NEMOGCM/TOOLS/SIREN/src/grid.f90 – NEMO

Ignore:
Timestamp:
2016-10-13T11:08:38+02:00 (8 years ago)
Author:
jpaul
Message:

see ticket #1781

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2016/dev_r6999_CONFIGMAN_1/NEMOGCM/TOOLS/SIREN/src/grid.f90

    r6393 r7025  
    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 
     
    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.& 
     
    30203032   !> 
    30213033   !> @author J.Paul 
     3034   !> @date April, 2016 - Initial Version 
     3035   ! 
     3036   !> @param[in] td_coord0 coarse grid coordinate mpp structure 
     3037   !> @param[in] dd_lon1   fine   grid longitude 
     3038   !> @param[in] dd_lat1   fine   grid latitude 
     3039   !> @param[in] cd_pos    relative position of grid point from point  
     3040   !> @param[in] dd_fill   fill value 
     3041   !> @return coarse grid indices of closest point of fine grid point 
     3042   !------------------------------------------------------------------- 
     3043   FUNCTION grid__get_closest_str( td_coord0, dd_lon1, dd_lat1, cd_pos, dd_fill ) & 
     3044   &  RESULT(id_res) 
     3045 
     3046      IMPLICIT NONE 
     3047      ! Argument 
     3048      TYPE(TMPP )     , INTENT(IN) :: td_coord0 
     3049      REAL(dp),         INTENT(IN) :: dd_lon1 
     3050      REAL(dp),         INTENT(IN) :: dd_lat1 
     3051      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: cd_pos 
     3052      REAL(dp),         INTENT(IN), OPTIONAL :: dd_fill 
     3053 
     3054      ! function 
     3055      INTEGER(i4), DIMENSION(2) :: id_res 
     3056 
     3057      ! local variable 
     3058      CHARACTER(LEN=lc)                        :: cl_point 
     3059      CHARACTER(LEN=lc)                        :: cl_name 
     3060 
     3061      INTEGER(i4)                              :: il_ind 
     3062 
     3063      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_lon0 
     3064      REAL(dp)   , DIMENSION(:,:), ALLOCATABLE :: dl_lat0 
     3065 
     3066      TYPE(TVAR)                               :: tl_lon0 
     3067      TYPE(TVAR)                               :: tl_lat0 
     3068      TYPE(TMPP)                               :: tl_coord0 
     3069      !---------------------------------------------------------------- 
     3070 
     3071      id_res(:)=-1 
     3072      cl_point='T' 
     3073 
     3074      ! copy structure 
     3075      tl_coord0=mpp_copy(td_coord0) 
     3076 
     3077      IF( .NOT. ASSOCIATED(tl_coord0%t_proc) )THEN 
     3078 
     3079         CALL logger_error("GRID GET CLOSEST: decompsition of mpp "//& 
     3080         &  "file "//TRIM(tl_coord0%c_name)//" not defined." ) 
     3081 
     3082      ELSE 
     3083 
     3084         ! open mpp files 
     3085         CALL iom_mpp_open(tl_coord0) 
     3086  
     3087         ! read coarse longitue and latitude 
     3088         WRITE(cl_name,*) 'longitude_'//TRIM(cl_point) 
     3089         il_ind=var_get_id(tl_coord0%t_proc(1)%t_var(:), cl_name) 
     3090         IF( il_ind == 0 )THEN 
     3091            CALL logger_warn("GRID GET CLOSEST: no variable "//& 
     3092            &  TRIM(cl_name)//"in file "//TRIM(tl_coord0%c_name)//". & 
     3093            &  try to use longitude.") 
     3094            WRITE(cl_name,*) 'longitude' 
     3095         ENDIF 
     3096         tl_lon0=iom_mpp_read_var(tl_coord0, TRIM(cl_name)) 
     3097  
     3098         WRITE(cl_name,*) 'latitude_'//TRIM(cl_point) 
     3099         il_ind=var_get_id(tl_coord0%t_proc(1)%t_var(:), cl_name) 
     3100         IF( il_ind == 0 )THEN 
     3101            CALL logger_warn("GRID GET CLOSEST: no variable "//& 
     3102            &  TRIM(cl_name)//"in file "//TRIM(tl_coord0%c_name)//". & 
     3103            &  try to use latitude.") 
     3104            WRITE(cl_name,*) 'latitude' 
     3105         ENDIF 
     3106         tl_lat0=iom_mpp_read_var(tl_coord0, TRIM(cl_name)) 
     3107 
     3108         ! close mpp files 
     3109         CALL iom_mpp_close(tl_coord0) 
     3110 
     3111         ALLOCATE(dl_lon0(tl_coord0%t_dim(jp_I)%i_len-tl_coord0%i_ew, & 
     3112            &             tl_coord0%t_dim(jp_J)%i_len) )              
     3113         ALLOCATE(dl_lat0(tl_coord0%t_dim(jp_I)%i_len-tl_coord0%i_ew, & 
     3114            &             tl_coord0%t_dim(jp_J)%i_len) ) 
     3115 
     3116         dl_lon0(:,:)=tl_lon0%d_value(tl_coord0%i_ew+1:,:,1,1) 
     3117         dl_lat0(:,:)=tl_lat0%d_value(tl_coord0%i_ew+1:,:,1,1) 
     3118 
     3119         id_res(:)=grid_get_closest( dl_lon0, dl_lat0, dd_lon1, dd_lat1, cd_pos, dd_fill ) 
     3120 
     3121         DEALLOCATE(dl_lon0, dl_lat0) 
     3122         CALL var_clean(tl_lon0) 
     3123         CALL var_clean(tl_lat0) 
     3124         CALL mpp_clean(tl_coord0) 
     3125 
     3126      ENDIF 
     3127 
     3128   END FUNCTION  grid__get_closest_str 
     3129   !------------------------------------------------------------------- 
     3130   !> @brief This function return grid indices of the closest point 
     3131   !> from point (lon1,lat1)  
     3132   !>  
     3133   !> @details 
     3134   !> 
     3135   !> @note overlap band should have been already removed from coarse grid array  
     3136   !> of longitude and latitude, before running this function 
     3137   !> 
     3138   !> if you add cd_pos argument, you could choice to return closest point at 
     3139   !> - lower left  (ll) of the point 
     3140   !> - lower right (lr) of the point 
     3141   !> - upper left  (ul) of the point 
     3142   !> - upper right (ur) of the point 
     3143   !> - lower       (lo) of the point 
     3144   !> - upper       (up) of the point 
     3145   !> -       left  (le) of the point 
     3146   !> -       right (ri) of the point 
     3147   !> 
     3148   !> @author J.Paul 
    30223149   !> @date November, 2013 - Initial Version 
    30233150   !> @date February, 2015 
     
    30343161   !> @return coarse grid indices of closest point of fine grid point 
    30353162   !------------------------------------------------------------------- 
    3036    FUNCTION grid_get_closest( dd_lon0, dd_lat0, dd_lon1, dd_lat1, cd_pos, dd_fill ) 
     3163   FUNCTION grid__get_closest_arr( dd_lon0, dd_lat0, dd_lon1, dd_lat1, cd_pos, dd_fill ) 
    30373164      IMPLICIT NONE 
    30383165      ! Argument 
     
    30453172 
    30463173      ! function 
    3047       INTEGER(i4), DIMENSION(2) :: grid_get_closest 
     3174      INTEGER(i4), DIMENSION(2) :: grid__get_closest_arr 
    30483175 
    30493176      ! local variable 
     
    32613388         END SELECT 
    32623389      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 
     3390      grid__get_closest_arr(:)=MINLOC(dl_dist(:,:),dl_dist(:,:)/=NF90_FILL_DOUBLE) 
     3391 
     3392      grid__get_closest_arr(1)=grid__get_closest_arr(1)+il_iinf-1 
     3393      grid__get_closest_arr(2)=grid__get_closest_arr(2)+il_jinf-1 
    32673394 
    32683395      DEALLOCATE( dl_dist ) 
    32693396      DEALLOCATE( dl_lon0 ) 
    32703397 
    3271    END FUNCTION grid_get_closest 
     3398   END FUNCTION grid__get_closest_arr 
    32723399   !------------------------------------------------------------------- 
    32733400   !> @brief This function compute the distance between a point A and grid points.   
     
    46474774 
    46484775      IF( ll_even )THEN 
     4776 
    46494777         ! look for variable value on domain for F point 
    46504778         il_ind=var_get_index(tl_coord0%t_proc(1)%t_var(:), 'longitude_F') 
Note: See TracChangeset for help on using the changeset viewer.