@@ -32,7 +32,7 @@ module model_mod
3232 nc_begin_define_mode, nc_end_define_mode, &
3333 nc_open_file_readonly, nc_close_file, &
3434 nc_get_variable, nc_get_variable_size, &
35- NF90_MAX_NAME
35+ NF90_MAX_NAME, nc_get_attribute_from_variable
3636
3737use quad_utils_mod, only : quad_interp_handle, init_quad_interp, &
3838 set_quad_coords, quad_lon_lat_locate, &
@@ -97,6 +97,7 @@ module model_mod
9797real (r8 ), allocatable :: geolon(:,:), geolat(:,:), & ! T
9898 geolon_u(:,:), geolat_u(:,:), & ! U
9999 geolon_v(:,:), geolat_v(:,:) ! V
100+ logical , allocatable :: mask(:,:), mask_u(:,:), mask_v(:,:) ! geolat/lon/u/v has missing values
100101type (quad_interp_handle) :: interp_t_grid, &
101102 interp_u_grid, &
102103 interp_v_grid
@@ -595,6 +596,7 @@ subroutine read_horizontal_grid()
595596
596597integer :: ncid
597598integer :: nxy(2 ) ! (nx,ny)
599+ real (r8 ) :: fillval
598600
599601character (len=* ), parameter :: routine = ' read_horizontal_grid'
600602
@@ -606,22 +608,48 @@ subroutine read_horizontal_grid()
606608allocate (geolon(nx,ny), geolat(nx,ny)) ! T grid
607609allocate (geolon_u(nx,ny), geolat_u(nx,ny)) ! U grid
608610allocate (geolon_v(nx,ny), geolat_v(nx,ny)) ! V grid
611+ allocate (mask(nx,ny)) ! missing values
612+ allocate (mask_u(nx,ny)) ! missing values
613+ allocate (mask_v(nx,ny)) ! missing values
609614
610615call nc_get_variable(ncid, ' geolon' , geolon, routine)
611616call nc_get_variable(ncid, ' geolon_u' , geolon_u, routine)
612617call nc_get_variable(ncid, ' geolon_v' , geolon_v, routine)
613618
614-
615- ! mom6 example file has longitude > 360
616- ! DART uses [0,360]
617- where (geolon > 360.0_r8 ) geolon = geolon - 360.0_r8
618- where (geolon_u > 360.0_r8 ) geolon_u = geolon_u - 360.0_r8
619- where (geolon_v > 360.0_r8 ) geolon_v = geolon_v - 360.0_r8
620-
621619call nc_get_variable(ncid, ' geolat' , geolat, routine)
622620call nc_get_variable(ncid, ' geolat_u' , geolat_u, routine)
623621call nc_get_variable(ncid, ' geolat_v' , geolat_v, routine)
624622
623+ ! mom6 has missing values in the grid
624+ ! and set missing value to a land point to prevent set_location erroring
625+ mask(:,:) = .false.
626+ mask_u(:,:) = .false.
627+ mask_v(:,:) = .false.
628+ call nc_get_attribute_from_variable(ncid, ' geolon' , ' _FillValue' , fillval)
629+ where (geolon == fillval) mask = .true.
630+ where (geolon == fillval) geolon = 72.51
631+ where (geolat == fillval) geolat = 42.56
632+
633+ call nc_get_attribute_from_variable(ncid, ' geolon_u' , ' _FillValue' , fillval)
634+ where (geolon_u == fillval) mask_u = .true.
635+ where (geolon_u == fillval) geolon_u = 72.51
636+ where (geolat_u == fillval) geolat_u = 42.56
637+
638+ call nc_get_attribute_from_variable(ncid, ' geolon_v' , ' _FillValue' , fillval)
639+ where (geolon_v == fillval) mask_v = .true.
640+ where (geolon_v == fillval) geolon_v = 72.51
641+ where (geolat_v == fillval) geolat_v = 42.56
642+
643+ ! mom6 example files have longitude > 360 and longitudes < 0
644+ ! DART uses [0,360]
645+ geolon = mod (geolon, 360.0 )
646+ geolon_u = mod (geolon_u, 360.0 )
647+ geolon_v = mod (geolon_v, 360.0 )
648+
649+ where (geolon < 0.0 ) geolon = geolon + 360
650+ where (geolon_u < 0.0 ) geolon_u = geolon_u + 360
651+ where (geolon_v < 0.0 ) geolon_v = geolon_v + 360
652+
625653call nc_close_file(ncid)
626654
627655end subroutine read_horizontal_grid
@@ -831,15 +859,15 @@ subroutine setup_interpolation()
831859 global= .true. , spans_lon_zero= .true. , pole_wrap= .true. , &
832860 interp_handle= interp_t_grid)
833861
834- call set_quad_coords(interp_t_grid, geolon, geolat)
862+ call set_quad_coords(interp_t_grid, geolon, geolat, mask )
835863
836864! U
837865call init_quad_interp(GRID_QUAD_FULLY_IRREGULAR, nx, ny, &
838866 QUAD_LOCATED_CELL_CENTERS, &
839867 global= .true. , spans_lon_zero= .true. , pole_wrap= .true. , &
840868 interp_handle= interp_u_grid)
841869
842- call set_quad_coords(interp_u_grid, geolon_u, geolat_u)
870+ call set_quad_coords(interp_u_grid, geolon_u, geolat_u, mask_u )
843871
844872
845873! V
@@ -848,7 +876,7 @@ subroutine setup_interpolation()
848876 global= .true. , spans_lon_zero= .true. , pole_wrap= .true. , &
849877 interp_handle= interp_v_grid)
850878
851- call set_quad_coords(interp_v_grid, geolon_v, geolat_v)
879+ call set_quad_coords(interp_v_grid, geolon_v, geolat_v, mask_v )
852880
853881end subroutine setup_interpolation
854882
0 commit comments