Skip to content

Commit 5193c6b

Browse files
jswhitjswhit2
andauthored
fix for 4diau with iau_filter_increments=T (#167)
* fix for 4diau with iau_filter_increments=T * fix time interval for 3DIAU * fix typo in comment * fix bug found in review by @MingjingTong-NOAA * change tnext to integer variable itnext Co-authored-by: jswhit2 <Jeffrey.S.Whitaker@noaa.gov>
1 parent fa86482 commit 5193c6b

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

tools/fv_iau_mod.F90

+22-15
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ subroutine IAU_initialize (IPD_Control, IAU_Data,Init_parm)
253253
allocate (iau_state%inc1%tracer_inc(is:ie, js:je, km,ntracers))
254254
iau_state%hr1=IPD_Control%iaufhrs(1)
255255
iau_state%wt = 1.0 ! IAU increment filter weights (default 1.0)
256+
iau_state%wt_normfact = 1.0
256257
if (IPD_Control%iau_filter_increments) then
257258
! compute increment filter weights, sum to obtain normalization factor
258259
dtp=IPD_control%dtp
@@ -298,26 +299,31 @@ subroutine getiauforcing(IPD_Control,IAU_Data)
298299
type (IPD_control_type), intent(in) :: IPD_Control
299300
type(IAU_external_data_type), intent(inout) :: IAU_Data
300301
real(kind=kind_phys) t1,t2,sx,wx,wt,dtp
301-
integer n,i,j,k,sphum,kstep,nstep
302+
integer n,i,j,k,sphum,kstep,nstep,itnext
302303

303304
IAU_Data%in_interval=.false.
304305
if (nfiles.LE.0) then
305306
return
306307
endif
307308

308-
t1=iau_state%hr1 - IPD_Control%iau_delthrs*0.5
309-
t2=iau_state%hr1 + IPD_Control%iau_delthrs*0.5
309+
if (nfiles .eq. 1) then
310+
t1 = IPD_Control%iaufhrs(1)-0.5*IPD_Control%iau_delthrs
311+
t2 = IPD_Control%iaufhrs(1)+0.5*IPD_Control%iau_delthrs
312+
else
313+
t1 = IPD_Control%iaufhrs(1)
314+
t2 = IPD_Control%iaufhrs(nfiles)
315+
endif
310316
if (IPD_Control%iau_filter_increments) then
311317
! compute increment filter weight
312-
! t1 beginning of window, t2 end of window
318+
! t1 is beginning of window, t2 end of window
313319
! IPD_Control%fhour current time
314320
! in window kstep=-nstep,nstep (2*nstep+1 total)
315321
! time step IPD_control%dtp
316322
dtp=IPD_control%dtp
317323
nstep = 0.5*IPD_Control%iau_delthrs*3600/dtp
318324
! compute normalized filter weight
319-
kstep = (IPD_Control%fhour-(t1+IPD_Control%iau_delthrs*0.5))*3600./dtp
320-
if (kstep .ge. -nstep .and. kstep .le. nstep) then
325+
kstep = ((IPD_Control%fhour-t1) - 0.5*IPD_Control%iau_delthrs)*3600./dtp
326+
if (IPD_Control%fhour >= t1 .and. IPD_Control%fhour < t2) then
321327
sx = acos(-1.)*kstep/nstep
322328
wx = acos(-1.)*kstep/(nstep+1)
323329
if (kstep .ne. 0) then
@@ -326,7 +332,7 @@ subroutine getiauforcing(IPD_Control,IAU_Data)
326332
wt = 1.
327333
endif
328334
iau_state%wt = iau_state%wt_normfact*wt
329-
if (is_master()) print *,'filter wt',kstep,IPD_Control%fhour,iau_state%wt
335+
!if (is_master()) print *,'kstep,t1,t,t2,filter wt=',kstep,t1,IPD_Control%fhour,t2,iau_state%wt/iau_state%wt_normfact
330336
else
331337
iau_state%wt = 0.
332338
endif
@@ -340,31 +346,32 @@ subroutine getiauforcing(IPD_Control,IAU_Data)
340346
IAU_Data%in_interval=.false.
341347
else
342348
if (IPD_Control%iau_filter_increments) call setiauforcing(IPD_Control,IAU_Data,iau_state%wt)
343-
if (is_master()) print *,'apply iau forcing',t1,IPD_Control%fhour,t2
349+
if (is_master()) print *,'apply iau forcing t1,t,t2,filter wt=',t1,IPD_Control%fhour,t2,iau_state%wt/iau_state%wt_normfact
344350
IAU_Data%in_interval=.true.
345351
endif
346352
return
347353
endif
348354

349355
if (nfiles > 1) then
350-
t2=2
351-
if (IPD_Control%fhour < IPD_Control%iaufhrs(1) .or. IPD_Control%fhour >= IPD_Control%iaufhrs(nfiles)) then
356+
itnext=2
357+
if (IPD_Control%fhour < t1 .or. IPD_Control%fhour >= t2) then
352358
! if (is_master()) print *,'no iau forcing',IPD_Control%iaufhrs(1),IPD_Control%fhour,IPD_Control%iaufhrs(nfiles)
353359
IAU_Data%in_interval=.false.
354360
else
361+
if (is_master()) print *,'apply iau forcing t1,t,t2,filter wt=',t1,IPD_Control%fhour,t2,iau_state%wt/iau_state%wt_normfact
355362
IAU_Data%in_interval=.true.
356363
do k=nfiles,1,-1
357364
if (IPD_Control%iaufhrs(k) > IPD_Control%fhour) then
358-
t2=k
365+
itnext=k
359366
endif
360367
enddo
361-
! if (is_master()) print *,'t2=',t2
368+
! if (is_master()) print *,'itnext=',itnext
362369
if (IPD_Control%fhour >= iau_state%hr2) then ! need to read in next increment file
363370
iau_state%hr1=iau_state%hr2
364-
iau_state%hr2=IPD_Control%iaufhrs(int(t2))
371+
iau_state%hr2=IPD_Control%iaufhrs(itnext)
365372
iau_state%inc1=iau_state%inc2
366-
if (is_master()) print *,'reading next increment file',trim(IPD_Control%iau_inc_files(int(t2)))
367-
call read_iau_forcing(IPD_Control,iau_state%inc2,'INPUT/'//trim(IPD_Control%iau_inc_files(int(t2))))
373+
if (is_master()) print *,'reading next increment file',trim(IPD_Control%iau_inc_files(itnext))
374+
call read_iau_forcing(IPD_Control,iau_state%inc2,'INPUT/'//trim(IPD_Control%iau_inc_files(itnext)))
368375
endif
369376
call updateiauforcing(IPD_Control,IAU_Data,iau_state%wt)
370377
endif

0 commit comments

Comments
 (0)