Skip to content

Commit

Permalink
Switch between JEDI and GSI-formatted increments in namelist (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidNew-NOAA authored Apr 12, 2024
1 parent b600182 commit 68bc14d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
34 changes: 25 additions & 9 deletions src/netcdf_io/calc_analysis.fd/inc2anl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ subroutine add_increment(fcstvar, incvar)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
use vars_calc_analysis, only: fcstncfile, anlncfile, incr_file,&
nlat, nlon, nlev, anlfile, use_nemsio_anl, &
levpe, mype
levpe, mype, jedi
use module_ncio, only: Dataset, read_vardata, write_vardata, &
open_dataset, close_dataset, has_var
use nemsio_module
Expand All @@ -184,7 +184,8 @@ subroutine add_increment(fcstvar, incvar)
character(7), intent(in) :: fcstvar, incvar
! local variables
real, allocatable, dimension(:,:,:) :: work3d_bg
real, allocatable, dimension(:,:) :: work3d_inc
real, allocatable, dimension(:,:) :: work3d_inc_gsi
real, allocatable, dimension(:,:,:) :: work3d_inc_jedi
real, allocatable, dimension(:) :: work1d
integer :: j,jj,k,krev,iret
type(Dataset) :: incncfile
Expand All @@ -196,12 +197,22 @@ subroutine add_increment(fcstvar, incvar)
call read_vardata(fcstncfile, fcstvar, work3d_bg, nslice=k, slicedim=3)
! get increment
incncfile = open_dataset(incr_file, paropen=.true.)
call read_vardata(incncfile, trim(incvar)//"_inc", work3d_inc, nslice=k, slicedim=3)
! add increment to background
do j=1,nlat
jj=nlat+1-j ! increment is S->N, history files are N->S
work3d_bg(:,j,1) = work3d_bg(:,j,1) + work3d_inc(:,jj)
end do
! JEDI-derived increments have a time dimension, so read to appropriate array
if ( jedi ) then
call read_vardata(incncfile, trim(incvar)//"_inc", work3d_inc_jedi, nslice=k, slicedim=3)
! add increment to background
do j=1,nlat
jj=nlat+1-j ! increment is S->N, history files are N->S
work3d_bg(:,j,1) = work3d_bg(:,j,1) + work3d_inc_jedi(:,jj,1)
end do
else
call read_vardata(incncfile, trim(incvar)//"_inc", work3d_inc_gsi, nslice=k, slicedim=3)
! add increment to background
do j=1,nlat
jj=nlat+1-j ! increment is S->N, history files are N->S
work3d_bg(:,j,1) = work3d_bg(:,j,1) + work3d_inc_gsi(:,jj)
end do
end if
! write out analysis to file
if (use_nemsio_anl) then
allocate(work1d(nlat*nlon))
Expand All @@ -216,7 +227,12 @@ subroutine add_increment(fcstvar, incvar)
end if
end do
! clean up and close
deallocate(work3d_bg, work3d_inc)
if ( jedi ) then
deallocate(work3d_inc_jedi)
else
deallocate(work3d_inc_gsi)
end if
deallocate(work3d_bg)
call close_dataset(incncfile)
else
write(6,*) fcstvar, ' not in background file, skipping...'
Expand Down
6 changes: 4 additions & 2 deletions src/netcdf_io/calc_analysis.fd/init_calc_analysis.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ subroutine read_nml
!! read in namelist parameters from
!! calc_analysis.nml file in same directory
!! as executable
use vars_calc_analysis, only: anal_file, fcst_file, incr_file, use_nemsio_anl, fhr, mype, npes
use vars_calc_analysis, only: anal_file, fcst_file, incr_file, use_nemsio_anl, fhr, mype, npes, jedi
implicit none
! local variables to this subroutine
character(len=500) :: datapath = './'
Expand All @@ -24,10 +24,11 @@ subroutine read_nml
character(len=2) :: hrstr
integer, parameter :: lunit = 10
logical :: lexist = .false.
namelist /setup/ datapath, analysis_filename, firstguess_filename, increment_filename, fhr, use_nemsio_anl
namelist /setup/ datapath, analysis_filename, firstguess_filename, increment_filename, fhr, use_nemsio_anl, jedi

fhr = 6 ! default to 6 hour cycle only
use_nemsio_anl = .false. ! default to using netCDF for background and analysis
jedi = .false. ! default to GSI (not JEDI)

! read in the namelist
inquire(file='calc_analysis.nml', exist=lexist)
Expand Down Expand Up @@ -64,6 +65,7 @@ subroutine read_nml
else
write(6,*) 'writing analysis in netCDF format'
end if
write(6,*) 'Use JEDI format = ', jedi
end if

end subroutine read_nml
Expand Down
2 changes: 2 additions & 0 deletions src/netcdf_io/calc_analysis.fd/vars_calc_analysis.f90
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module vars_calc_analysis
public :: fhr
public :: mype, npes
public :: levpe
public :: jedi

character(len=500) :: anal_file, fcst_file, incr_file
integer, dimension(7) :: idate, jdate
Expand All @@ -44,5 +45,6 @@ module vars_calc_analysis
integer, dimension(7) :: fhrs_pe
integer :: mype, npes
integer, allocatable, dimension(:) :: levpe
logical :: jedi

end module vars_calc_analysis

0 comments on commit 68bc14d

Please sign in to comment.