Skip to content

Commit

Permalink
Add new write routine that updates records from an
Browse files Browse the repository at this point in the history
existing file instead of writing an entire new file.

Modify driver script to make copy of the input restart
files for updating.

Fixes ufs-community#761.
  • Loading branch information
GeorgeGayno-NOAA committed Jan 25, 2023
1 parent 7b1f169 commit 468ecee
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
18 changes: 10 additions & 8 deletions sorc/global_cycle.fd/cycle.f90
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,16 @@ SUBROUTINE SFCDRV(LUGB, IDIM,JDIM,LSM,LENSFC,LSOIL,DELTSFC, &
! WRITE OUT UPDATED SURFACE DATA ON THE CUBED-SPHERE TILE.
!--------------------------------------------------------------------------------

CALL WRITE_DATA(SLIFCS,TSFFCS,SWEFCS,TG3FCS,ZORFCS, &
ALBFCS,ALFFCS,VEGFCS,CNPFCS,F10M, &
T2M,Q2M,VETFCS,SOTFCS,USTAR,FMM,FHH, &
SICFCS,SIHFCS,SITFCS, &
TPRCP,SRFLAG,SNDFCS, &
VMNFCS,VMXFCS,SLPFCS,ABSFCS, &
SLCFCS,SMCFCS,STCFCS, &
IDIM,JDIM,LENSFC,LSOIL,DO_NSST,NSST)
CALL WRITE_DATA_SELECTED_RECORDS(VEGFCS,LENSFC,IDIM,JDIM)

!CALL WRITE_DATA(SLIFCS,TSFFCS,SWEFCS,TG3FCS,ZORFCS, &
! ALBFCS,ALFFCS,VEGFCS,CNPFCS,F10M, &
! T2M,Q2M,VETFCS,SOTFCS,USTAR,FMM,FHH, &
! SICFCS,SIHFCS,SITFCS, &
! TPRCP,SRFLAG,SNDFCS, &
! VMNFCS,VMXFCS,SLPFCS,ABSFCS, &
! SLCFCS,SMCFCS,STCFCS, &
! IDIM,JDIM,LENSFC,LSOIL,DO_NSST,NSST)

IF (DO_NSST) THEN
DEALLOCATE(NSST%C_0)
Expand Down
45 changes: 45 additions & 0 deletions sorc/global_cycle.fd/read_write_data.f90
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ MODULE READ_WRITE_DATA
PUBLIC :: READ_GSI_DATA
PUBLIC :: READ_LAT_LON_OROG
PUBLIC :: WRITE_DATA
PUBLIC :: WRITE_DATA_SELECTED_RECORDS
public :: read_tf_clim_grb,get_tf_clm_dim
public :: read_salclm_gfs_nc,get_dim_nc

Expand Down Expand Up @@ -114,6 +115,50 @@ MODULE READ_WRITE_DATA
!! @param[in] nsst Data structure containing nsst fields.
!!
!! @author George Gayno NOAA/EMC

!> Write out selected surface records to a pre-existing
!! model restart file (in netcdf).
subroutine write_data_selected_records(vegfcs,lensfc,idim,jdim)

use mpi

implicit none

integer, intent(in) :: lensfc
integer, intent(in) :: idim, jdim

real, intent(in) :: vegfcs(lensfc)

real :: dum2d(idim,jdim)

character(len=50) :: fnbgso
character(len=3) :: rankch

integer :: myrank, error, ncid, id_var

call mpi_comm_rank(mpi_comm_world, myrank, error)

write(rankch, '(i3.3)') (myrank+1)

fnbgso = "./fnbgso." // rankch

print*
print*,"update OUTPUT SFC DATA TO: ",trim(fnbgso)

ERROR=NF90_OPEN(TRIM(fnbgso),NF90_WRITE,NCID)
CALL NETCDF_ERR(ERROR, 'OPENING FILE: '//TRIM(fnbgso) )

ERROR=NF90_INQ_VARID(NCID, "vfrac", ID_VAR)
CALL NETCDF_ERR(ERROR, 'READING vfrac ID' )

dum2d = reshape(vegfcs, (/idim,jdim/))
error = nf90_put_var( ncid, id_var, dum2d)
call netcdf_err(error, 'WRITING vegfcs RECORD' )

error = nf90_close(ncid)

end subroutine write_data_selected_records

subroutine write_data(slifcs,tsffcs,swefcs,tg3fcs,zorfcs, &
albfcs,alffcs,vegfcs,cnpfcs,f10m, &
t2m,q2m,vetfcs,sotfcs,ustar,fmm,fhh, &
Expand Down
5 changes: 5 additions & 0 deletions ush/global_cycle_driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ mkdir -p $DATA

for n in $(seq 1 $ntiles); do
ln -fs $COMIN/$PDY.${cyc}0000.sfc_data.tile${n}.nc $DATA/fnbgsi.00$n

# Make a copy of the input restart file in the working directory.
# global_cycle will update the required records for noah-mp.
cp $COMIN/$PDY.${cyc}0000.sfc_data.tile${n}.nc $COMOUT/$PDY.${cyc}0000.sfcanl_data.tile${n}.nc
ln -fs $COMOUT/$PDY.${cyc}0000.sfcanl_data.tile${n}.nc $DATA/fnbgso.00$n

ln -fs $FIXfv3/C${CRES}/C${CRES}_grid.tile${n}.nc $DATA/fngrid.00$n
ln -fs $FIXfv3/C${CRES}/C${CRES}_oro_data.tile${n}.nc $DATA/fnorog.00$n
if [[ "$DO_SNO_INC" == ".true." ]] ; then
Expand Down

0 comments on commit 468ecee

Please sign in to comment.