Skip to content

Commit

Permalink
Unify N-deposition input reading
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaerz committed Sep 12, 2024
1 parent 96089fa commit 61961c8
Showing 1 changed file with 24 additions and 38 deletions.
62 changes: 24 additions & 38 deletions hamocc/mo_read_ndep.F90
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ module mo_read_ndep
public :: ndepfile

character(len=512) :: ndepfile=''
real, allocatable :: ndepread(:,:)
real, allocatable :: noydepread(:,:)
real, allocatable :: nhxdepread(:,:)
integer :: startyear,endyear
Expand Down Expand Up @@ -96,7 +95,7 @@ subroutine ini_read_ndep(kpie,kpje)
endif
return
endif
if (do_ndep_coupled) then
if (do_ndep_coupled .and. use_extNcycle) then
if (mnproc.eq.1) then
write(io_stdo_bgc,*) ''
write(io_stdo_bgc,*) 'ini_read_ndep: N deposition in interactive mode.'
Expand All @@ -123,36 +122,24 @@ subroutine ini_read_ndep(kpie,kpje)
stop '(ini_read_ndep)'
endif

if (use_extNcycle) then
! Allocate field to hold N-deposition fluxes
if (mnproc.eq.1) then
write(io_stdo_bgc,*)'Memory allocation for variable nhxdepread ...'
write(io_stdo_bgc,*)'First dimension : ',kpie
write(io_stdo_bgc,*)'Second dimension : ',kpje
endif
allocate (nhxdepread(kpie,kpje),stat=errstat)
if(errstat.ne.0) stop 'not enough memory nhxdepread'
nhxdepread(:,:) = 0.0
! Allocate fields to hold N-deposition fluxes
if (mnproc.eq.1) then
write(io_stdo_bgc,*)'Memory allocation for variable nhxdepread ...'
write(io_stdo_bgc,*)'First dimension : ',kpie
write(io_stdo_bgc,*)'Second dimension : ',kpje
endif
allocate (nhxdepread(kpie,kpje),stat=errstat)
if(errstat.ne.0) stop 'not enough memory nhxdepread'
nhxdepread(:,:) = 0.0

if (mnproc.eq.1) then
write(io_stdo_bgc,*)'Memory allocation for variable noydepread ...'
write(io_stdo_bgc,*)'First dimension : ',kpie
write(io_stdo_bgc,*)'Second dimension : ',kpje
endif
allocate (noydepread(kpie,kpje),stat=errstat)
if(errstat.ne.0) stop 'not enough memory noydepread'
noydepread(:,:) = 0.0
else
! Allocate field to hold N-deposition fluxes
if (mnproc.eq.1) then
write(io_stdo_bgc,*)'Memory allocation for variable ndepread ...'
write(io_stdo_bgc,*)'First dimension : ',kpie
write(io_stdo_bgc,*)'Second dimension : ',kpje
endif
allocate (ndepread(kpie,kpje),stat=errstat)
if(errstat.ne.0) stop 'not enough memory ndep'
ndepread(:,:) = 0.0
if (mnproc.eq.1) then
write(io_stdo_bgc,*)'Memory allocation for variable noydepread ...'
write(io_stdo_bgc,*)'First dimension : ',kpie
write(io_stdo_bgc,*)'Second dimension : ',kpje
endif
allocate (noydepread(kpie,kpje),stat=errstat)
if(errstat.ne.0) stop 'not enough memory noydepread'
noydepread(:,:) = 0.0

! read start and end year of n-deposition file
call ncfopn(trim(ndepfile),'r',' ',1,iotype)
Expand Down Expand Up @@ -237,15 +224,12 @@ subroutine get_ndep(kpie,kpje,kbnd,kplyear,kplmon,omask,ndep,patmnhxdep,patmnoyd
if (kplmon.ne.oldmonth) then
month_in_file=(max(startyear,min(endyear,kplyear))-startyear)*12+kplmon
if (mnproc.eq.1) then
write(io_stdo_bgc,*) 'Read N deposition month ',month_in_file,' from file ',trim(ndepfile)
write(io_stdo_bgc,*) 'Read NHx and NOy deposition month ', &
& month_in_file,' from file ',trim(ndepfile)
endif
ncstat=nf90_open(trim(ndepfile),nf90_nowrite,ncid)
if (use_extNcycle) then
call read_netcdf_var(ncid,'nhxdep',nhxdepread,1,month_in_file,0)
call read_netcdf_var(ncid,'noydep',noydepread,1,month_in_file,0)
else
call read_netcdf_var(ncid,'ndep',ndepread,1,month_in_file,0)
endif
call read_netcdf_var(ncid,'nhxdep',nhxdepread,1,month_in_file,0)
call read_netcdf_var(ncid,'noydep',noydepread,1,month_in_file,0)
ncstat=nf90_close(ncid)
oldmonth=kplmon
endif
Expand All @@ -255,10 +239,12 @@ subroutine get_ndep(kpie,kpje,kbnd,kplyear,kplmon,omask,ndep,patmnhxdep,patmnoyd
do j=1,kpje
do i=1,kpie
if (use_extNcycle) then
! Separation between reduced and oxidized N species (NHx and NOy)
ndep(i,j,idepnoy) = noydepread(i,j)
ndep(i,j,idepnhx) = nhxdepread(i,j)
else
ndep(i,j,idepnoy) = ndepread(i,j)
! Reduced and oxidized forms will all enter the NO3 pool
ndep(i,j,idepnoy) = nhxdepread(i,j) + noydepread(i,j)
endif
enddo
enddo
Expand Down

0 comments on commit 61961c8

Please sign in to comment.