Skip to content

Commit

Permalink
Place the read of the model grid dimensions in its own
Browse files Browse the repository at this point in the history
routine.

Fixes ufs-community#944.
  • Loading branch information
George Gayno committed Oct 18, 2024
1 parent e1c0e34 commit b4d6651
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
10 changes: 3 additions & 7 deletions sorc/ocean_merge.fd/merge_lake_ocnmsk.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,18 @@ program merge_lake_ocnmsk
integer :: binary_lake

character(len=250) :: flnm
integer :: ncid,ndims,nvars,natts,lat,lon,v1id,start(2),count(2),latid,lonid,tile
integer :: ncid,lat,lon,v1id,start(2),count(2),tile
real, allocatable :: lake_frac(:,:),lake_depth(:,:),land_frac(:,:),ocn_frac(:,:),slmsk(:,:),lat2d(:,:)

call read_nml(pth1, pth2, atmres, ocnres, pth3,binary_lake)

print *, pth1

do tile=1,6
call read_grid_dims(pth1, atmres, ocnres, tile, lon, lat)

write(flnm,'(5a,i1,a)') trim(pth1),trim(atmres),'.',trim(ocnres),'.tile',tile,'.nc'
call handle_err (nf90_open (flnm, NF90_NOWRITE, ncid))
call handle_err (nf90_inquire (ncid, ndimensions=ndims, nvariables=nvars, nattributes=natts))
write(6,*) 'flnm_ocn=',flnm,' ncid=',ncid, ' ndims=',ndims, 'nvars=',nvars,' natts=',natts
call handle_err (nf90_inq_dimid (ncid, 'grid_xt', latid)) ! RM: lon is no longer in this file; try grid_xt
call handle_err (nf90_inq_dimid (ncid, 'grid_yt', lonid)) ! RM: lat is no longer in this file; try grid_tyt
call handle_err (nf90_inquire_dimension (ncid, latid, len=lat))
call handle_err (nf90_inquire_dimension (ncid, lonid, len=lon))
if (tile==1) then
write(6,*) 'lat=',lat,'lon=',lon
allocate (lake_frac(lon,lat),lake_depth(lon,lat),land_frac(lon,lat),ocn_frac(lon,lat),slmsk(lon,lat),lat2d(lon,lat))
Expand Down
34 changes: 34 additions & 0 deletions sorc/ocean_merge.fd/read_write.F90
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
subroutine read_grid_dims(pth1, atmres, ocnres, tile, lon, lat)

use netcdf

implicit none

character(len=*), intent(in) :: pth1
character(len=*), intent(in) :: atmres
character(len=*), intent(in) :: ocnres

integer, intent(in) :: tile
integer, intent(out) :: lon, lat

character(len=250) :: flnm

integer :: ncid, ndims, nvars, natts
integer :: latid, lonid

write(flnm,'(5a,i1,a)') trim(pth1),trim(atmres),'.',trim(ocnres),'.tile',tile,'.nc'

call handle_err (nf90_open (flnm, NF90_NOWRITE, ncid))
call handle_err (nf90_inquire (ncid, ndimensions=ndims, nvariables=nvars, nattributes=natts))
call handle_err (nf90_inquire (ncid, ndimensions=ndims, nvariables=nvars, nattributes=natts))
write(6,*) 'flnm_ocn=',flnm,' ncid=',ncid, ' ndims=',ndims, 'nvars=',nvars,' natts=',natts
call handle_err (nf90_inq_dimid (ncid, 'grid_xt', latid)) ! RM: lon is no longer in this file; try grid_xt
call handle_err (nf90_inq_dimid (ncid, 'grid_yt', lonid)) ! RM: lat is no longer in this file; try grid_yt
call handle_err (nf90_inquire_dimension (ncid, latid, len=lat))
call handle_err (nf90_inquire_dimension (ncid, lonid, len=lon))
call handle_err (nf90_close (ncid))

print*,'- in new routine ',lon, lat

end subroutine read_grid_dims

subroutine read_lake_mask(pth2,atmres,tile,lon,lat,lake_frac, &
lake_depth,lat2d)

Expand Down

0 comments on commit b4d6651

Please sign in to comment.