Skip to content

Commit

Permalink
Adding read-in of netCDF "_FillValue" when SUBMODELNAME=MPAS. For eac…
Browse files Browse the repository at this point in the history
…h netCDF variable, grid locations are assigned SPVAL wherever "_FillValue" is found.
  • Loading branch information
jaymes-kenyon committed Aug 6, 2024
1 parent c292731 commit a4b7fe7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 17 deletions.
38 changes: 30 additions & 8 deletions sorc/ncep_post.fd/getIVariableN.f
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ subroutine getIVariableN(fileName,DateStr,dh,VarName,VarBuff,IM,JSTA_2L,JEND_2U,
! the portion of VarBuff that is needed for this task.

use wrf_io_flags_mod
use ctlblk_mod, only: spval, submodelname
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
implicit none
!
Expand All @@ -71,6 +72,8 @@ subroutine getIVariableN(fileName,DateStr,dh,VarName,VarBuff,IM,JSTA_2L,JEND_2U,
! real, allocatable, dimension(:,:,:,:) :: data
integer :: ierr
character(len=132) :: Stagger
real :: FillValue
integer :: OutCount

! call set_wrf_debug_level ( 1 )

Expand Down Expand Up @@ -118,15 +121,34 @@ subroutine getIVariableN(fileName,DateStr,dh,VarName,VarBuff,IM,JSTA_2L,JEND_2U,
if (ndim>3) then
write(*,*) 'Error: ndim = ',ndim
endif
do l=1,lm1
ll=lm1-l+1 ! flip the z axis not sure about soil
do i=1,im1
do j=js,je
VarBuff(i,j,l)=data(i,j,ll,1)
enddo

if (SUBMODELNAME=='MPAS') then
! For MPAS: determine the fill value associated with the variable
call ext_ncd_get_var_ti_real(dh,"_FillValue",TRIM(VarName),FillValue,1,OutCount,ierr)
do l=1,lm1
ll=lm1-l+1 ! flip the z axis not sure about soil
do i=1,im1
do j=js,je
if (data(i,j,ll,1) /= FillValue) then
VarBuff(i,j,l)=data(i,j,ll,1)
else ! For MPAS: assign SPVAL where FillValue is present
VarBuff(i,j,l)=spval
endif
enddo
enddo
enddo
else
do l=1,lm1
ll=lm1-l+1 ! flip the z axis not sure about soil
do i=1,im1
do j=js,je
VarBuff(i,j,l)=data(i,j,ll,1)
enddo
enddo
! write(*,*) Varname,' L ',l,': = ',data(1,1,ll,1)
enddo
! write(*,*) Varname,' L ',l,': = ',data(1,1,ll,1)
enddo
endif

deallocate(data)
return

Expand Down
41 changes: 32 additions & 9 deletions sorc/ncep_post.fd/getVariable.f
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ subroutine getVariable(fileName,DateStr,dh,VarName,VarBuff,IM,JSTA_2L,JEND_2U,LM
! the portion of VarBuff that is needed for this task.
! use mpi
use wrf_io_flags_mod, only: wrf_real, wrf_real8
use ctlblk_mod, only: spval, submodelname
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
implicit none

Expand All @@ -73,7 +74,8 @@ subroutine getVariable(fileName,DateStr,dh,VarName,VarBuff,IM,JSTA_2L,JEND_2U,LM
real, allocatable, dimension(:,:,:,:) :: data
integer :: ierr,size,mype,idsize,ier
character(len=132) :: Stagger
real SPVAL
real :: FillValue
integer :: OutCount

! call set_wrf_debug_level ( 1 )
call mpi_comm_rank(MPI_COMM_WORLD,mype,ier)
Expand Down Expand Up @@ -126,15 +128,36 @@ subroutine getVariable(fileName,DateStr,dh,VarName,VarBuff,IM,JSTA_2L,JEND_2U,LM
if (ndim>3) then
write(*,*) 'Error: ndim = ',ndim
endif
do l=1,lm1
ll=lm1-l+1 ! flip the z axis not sure about soil
do i=1,im1
do j=js,je
VarBuff(i,j,l)=data(i,j,ll,1)
enddo

if (SUBMODELNAME=='MPAS') then
! For MPAS: determine the fill value associated with the variable
call ext_ncd_get_var_ti_real(dh,"_FillValue",TRIM(VarName),FillValue,1,OutCount,ierr)
!if (VarName=='T') print*, 'JSK: T fill is ',Fillvalue
!if (VarName=='P_HYD') print*, 'JSK: P_HYD fill is ',Fillvalue
do l=1,lm1
ll=lm1-l+1 ! flip the z axis not sure about soil
do i=1,im1
do j=js,je
if (data(i,j,ll,1) /= FillValue) then
VarBuff(i,j,l)=data(i,j,ll,1)
else ! For MPAS: assign SPVAL where FillValue is present
VarBuff(i,j,l)=spval
endif
enddo
enddo
enddo
else
do l=1,lm1
ll=lm1-l+1 ! flip the z axis not sure about soil
do i=1,im1
do j=js,je
VarBuff(i,j,l)=data(i,j,ll,1)
enddo
enddo
! write(*,*) Varname,' L ',l,': = ',data(1,1,ll,1)
enddo
! write(*,*) Varname,' L ',l,': = ',data(1,1,ll,1)
enddo
endif

deallocate(data)
return

Expand Down

0 comments on commit a4b7fe7

Please sign in to comment.