22 character(len=120) :: pth1
23 character(len=120) :: pth2,pth3
24 character(len=10) :: atmres,ocnres
25 real,
parameter :: min_land=1.e-4, def_lakedp=10.
30 integer :: binary_lake
32 character(len=250) :: flnm
33 integer :: ncid,ndims,nvars,natts,lat,lon,v1id,v2id,v3id,v4id,start(2),count(2),i,j,latid,lonid,ncid4, dims(2),tile,nodp_pt
34 integer :: lake_pt,vlat
35 real,
allocatable :: lake_frac(:,:),lake_depth(:,:),land_frac(:,:),ocn_frac(:,:),slmsk(:,:),lat2d(:,:)
38 call
read_nml(pth1, pth2, atmres, ocnres, pth3,binary_lake)
44 write(flnm,
'(5a,i1,a)') trim(pth1),trim(atmres),
'.',trim(ocnres),
'.tile',tile,
'.nc'
45 call
handle_err(nf90_open(flnm, nf90_nowrite, ncid))
46 call
handle_err(nf90_inquire(ncid, ndimensions=ndims, nvariables=nvars, nattributes=natts))
47 write(6,*)
'flnm_ocn=',flnm,
' ncid=',ncid,
' ndims=',ndims,
'nvars=',nvars,
' natts=',natts
48 call
handle_err(nf90_inq_dimid(ncid,
'grid_xt', latid))
49 call
handle_err(nf90_inq_dimid(ncid,
'grid_yt', lonid))
50 call
handle_err(nf90_inquire_dimension(ncid, latid, len=lat))
51 call
handle_err(nf90_inquire_dimension(ncid, lonid, len=lon))
53 write(6,*)
'lat=',lat,
'lon=',lon
54 allocate (lake_frac(lon,lat),lake_depth(lon,lat),land_frac(lon,lat),ocn_frac(lon,lat),slmsk(lon,lat),lat2d(lon,lat))
56 count(1:2) = (/lon,lat/)
58 call
handle_err(nf90_inq_varid(ncid,
'land_frac', v1id))
59 call
handle_err(nf90_get_var(ncid, v1id, ocn_frac, start=start, count=count))
62 write(flnm,
'(4a,i1,a)') trim(pth2),
'oro.',trim(atmres),
'.tile',tile,
'.nc'
63 print *,
' flnm2=',trim(flnm)
64 call
handle_err(nf90_open(flnm, nf90_nowrite, ncid))
65 call
handle_err(nf90_inquire(ncid, ndimensions=ndims, nvariables=nvars, nattributes=natts))
66 write(6,*)
'flnm_lake=',flnm,
' ncid=',ncid,
' ndims=',ndims,
'nvars=',nvars,
' natts=',natts
76 call
handle_err(nf90_inq_varid(ncid,
'lake_frac', v2id))
77 call
handle_err(nf90_inq_varid(ncid,
'lake_depth',v3id))
78 call
handle_err(nf90_inq_varid(ncid,
'geolat' ,vlat))
79 call
handle_err(nf90_get_var(ncid, v2id, lake_frac, start=start, count=count))
80 call
handle_err(nf90_get_var(ncid, v3id, lake_depth,start=start, count=count))
81 call
handle_err(nf90_get_var(ncid, vlat, lat2d, start=start, count=count))
85 if (binary_lake.eq.1) lake_frac(i,j)=nint(lake_frac(i,j))
86 if (lat2d(i,j).le.-60.) lake_frac(i,j)=0.
87 land_frac(i,j)=1.-ocn_frac(i,j)
88 if (land_frac(i,j) < min_land) land_frac(i,j)=0.
89 if (land_frac(i,j) > 1.-min_land) land_frac(i,j)=1.
90 if (1.-land_frac(i,j) > 0.) lake_frac(i,j)=0.
92 if (lake_frac(i,j) > 0.)
then
94 if (binary_lake.eq.1)
then
97 land_frac(i,j)=1.-lake_frac(i,j)
99 if (lake_depth(i,j) <= 0.)
then
100 lake_depth(i,j)=def_lakedp
107 slmsk(i,j) = nint(land_frac(i,j))
111 write(flnm,
'(4a,i1,a)') trim(atmres),
'.',trim(ocnres),
'.tile',tile,
'.nc'
112 print *,
'output=',trim(flnm)
113 call
handle_err(nf90_create(path=trim(pth3)//trim(flnm), &
114 cmode=or(nf90_clobber, nf90_64bit_offset), ncid=ncid4))
116 call
handle_err(nf90_def_dim(ncid4,
'lon', lon, dims(1)))
117 call
handle_err(nf90_def_dim(ncid4,
'lat', lat, dims(2)))
118 call
handle_err(nf90_def_var(ncid4,
'land_frac', nf90_float, dims(1:2), v1id))
119 call
handle_err(nf90_def_var(ncid4,
'lake_frac', nf90_float, dims(1:2), v2id))
120 call
handle_err(nf90_def_var(ncid4,
'lake_depth',nf90_float, dims(1:2), v3id))
121 call
handle_err(nf90_def_var(ncid4,
'slmsk', nf90_float, dims(1:2), v4id))
125 call
handle_err(nf90_put_var(ncid4, v1id,land_frac))
126 call
handle_err(nf90_put_var(ncid4, v2id,lake_frac))
127 call
handle_err(nf90_put_var(ncid4, v3id,lake_depth))
128 call
handle_err(nf90_put_var(ncid4, v4id,slmsk))
138 write(*,
'(a,i8,a,i8,a)')
'total lake point ',lake_pt,
' where ',nodp_pt,
' has no depth'
148 integer,
intent(in) :: ret
150 if (ret /= nf90_noerr)
then
151 write(6,*) nf90_strerror(ret)
166 subroutine read_nml(ocean_mask_dir, lake_mask_dir, atmres,ocnres,out_dir,binary_lake)
168 integer :: unit=7, io_status
170 character(len=120),
intent(out) :: ocean_mask_dir
171 character(len=120),
intent(out) :: lake_mask_dir
172 character(len=120),
intent(out) :: out_dir
173 character(len=10),
intent(out) :: atmres,ocnres
174 integer,
intent(out):: binary_lake
176 namelist/mask_nml/ocean_mask_dir, lake_mask_dir, atmres, ocnres,out_dir,binary_lake
177 open(unit=unit, file=
'input.nml', iostat=io_status )
178 read(unit,mask_nml, iostat=io_status )
180 if (io_status > 0)
then
181 print *,
'Error reading input.nml'
subroutine handle_err(ret)
Handle netCDF errors.
program merge_lake_ocnmsk
Determine the water mask by merging the lake mask with the mapped ocean mask from MOM6...
subroutine read_nml(ocean_mask_dir, lake_mask_dir, atmres, ocnres, out_dir, binary_lake)
Read program namelist.