Skip to content

Commit

Permalink
feature/coldstart Keep a personal copy of chgres_cube
Browse files Browse the repository at this point in the history
with the new name of coldstart.  This copy does not include
the nam, rap or hrrr grib2 options.

#9
  • Loading branch information
GeorgeGayno-NOAA committed Oct 15, 2020
1 parent 4571564 commit 5ecb21a
Show file tree
Hide file tree
Showing 14 changed files with 18,131 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sorc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ add_subdirectory(nemsio_chgdate.fd)
add_subdirectory(mkgfsnemsioctl.fd)
add_subdirectory(fre-nctools.fd)
add_subdirectory(grid_tools.fd)
add_subdirectory(chgres_cube.fd)
#add_subdirectory(chgres_cube.fd)
add_subdirectory(coldstart.fd)
add_subdirectory(orog_mask_tools.fd)
add_subdirectory(sfc_climo_gen.fd)
add_subdirectory(vcoord_gen.fd)
Expand Down
40 changes: 40 additions & 0 deletions sorc/coldstart.fd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set(fortran_src
atmosphere.F90
chgres.F90
grib2_util.F90
input_data.F90
model_grid.F90
program_setup.f90
search_util.f90
static_data.F90
surface.F90
thompson_mp_climo_data.F90
utils.f90
write_data.F90)

if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -r8 -convert big_endian -assume byterecl")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-0 -fdefault-real-8 -fconvert=big-endian")
endif()

set(exe_name coldstart)
add_executable(${exe_name} ${fortran_src})
target_link_libraries(
${exe_name}
nemsio::nemsio
sfcio::sfcio
sigio::sigio
bacio::bacio_4
sp::sp_d
w3nco::w3nco_d
esmf
wgrib2::wgrib2_lib
wgrib2::wgrib2_api
MPI::MPI_Fortran
NetCDF::NetCDF_Fortran)
if(OpenMP_Fortran_FOUND)
target_link_libraries(${exe_name} OpenMP::OpenMP_Fortran)
endif()

install(TARGETS ${exe_name} RUNTIME DESTINATION ${exec_dir})
2,060 changes: 2,060 additions & 0 deletions sorc/coldstart.fd/atmosphere.F90

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions sorc/coldstart.fd/chgres.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
program chgres

!-------------------------------------------------------------------------
! Program CHGRES
!
! Abstract: Initialize an FV3 run using history or restart data from
! another FV3 run, or the NEMS version of the spectral GFS.
! Converts atmospheric, surface and nst data.
!
!-------------------------------------------------------------------------

use mpi
use esmf

use atmosphere, only : atmosphere_driver

use program_setup, only : read_setup_namelist, &
read_varmap, &
convert_atm, &
convert_sfc

use model_grid, only : define_target_grid, &
define_input_grid, &
cleanup_input_target_grid_data

use surface, only : surface_driver

implicit none

integer :: ierr, localpet, npets

type(esmf_vm) :: vm

!-------------------------------------------------------------------------
! Initialize mpi and esmf environment.
!-------------------------------------------------------------------------

call mpi_init(ierr)

print*,"- INITIALIZE ESMF"
call ESMF_Initialize(rc=ierr)
if(ESMF_logFoundError(rcToCheck=ierr,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("INITIALIZING ESMF", ierr)

print*,"- CALL VMGetGlobal"
call ESMF_VMGetGlobal(vm, rc=ierr)
if(ESMF_logFoundError(rcToCheck=ierr,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN VMGetGlobal", ierr)

print*,"- CALL VMGet"
call ESMF_VMGet(vm, localPet=localpet, petCount=npets, rc=ierr)
if(ESMF_logFoundError(rcToCheck=ierr,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN VMGet", ierr)

print*,'- NPETS IS ',npets
print*,'- LOCAL PET ',localpet

!-------------------------------------------------------------------------
! Read program configuration namelist.
!-------------------------------------------------------------------------

call read_setup_namelist

!-------------------------------------------------------------------------
! Read variable mapping file (used for grib2 input data only).
!-------------------------------------------------------------------------

call read_varmap

!-------------------------------------------------------------------------
! Create esmf grid objects for input and target grids.
!-------------------------------------------------------------------------

call define_target_grid(localpet, npets)

call define_input_grid(localpet, npets)

!-------------------------------------------------------------------------
! Convert atmospheric fields
!-------------------------------------------------------------------------

if (convert_atm) then

call atmosphere_driver(localpet)

end if

!-------------------------------------------------------------------------
! Convert surface/nsst fields
!-------------------------------------------------------------------------

if (convert_sfc) then

call surface_driver(localpet)

end if

call cleanup_input_target_grid_data

print*,"- CALL ESMF_finalize"
call ESMF_finalize(endflag=ESMF_END_KEEPMPI, rc=ierr)

call mpi_finalize(ierr)

print*,"- DONE."

end program chgres
77 changes: 77 additions & 0 deletions sorc/coldstart.fd/grib2_util.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module grib2_util

!--------------------------------------------------------------------------
! Module: grib2_util
!
! Abstract: Utilities for use when reading grib2 data.
!
!--------------------------------------------------------------------------

use esmf

use model_grid, only : i_input, j_input

implicit none

contains

subroutine rh2spfh(rh_sphum,p,t)

implicit none
real,parameter :: alpha=-9.477E-4 , & !K^-1,
Tnot=273.15, & !K
Lnot=2.5008E6, & !JKg^-1
Rv=461.51, & !JKg^-1K^-1
esnot=611.21 !Pa

real(esmf_kind_r4), intent(inout), dimension(i_input,j_input) ::rh_sphum
real(esmf_kind_r8), intent(in) :: p, t(i_input,j_input)

real, dimension(i_input,j_input) :: es, e, rh

print*,"- CONVERT RH TO SPFH AT LEVEL ", p

rh = rh_sphum
!print *, 'T = ', T, ' RH = ', RH, ' P = ', P
es = esnot * exp( Lnot/Rv * ((t-Tnot)/(t*tnot) + alpha * LOG(t/Tnot) - alpha * (t-Tnot)/ t))
!print *, 'es = ', es
e = rh * es / 100.0
!print *, 'e = ', e
rh_sphum = 0.622 * e / p
!print *, 'q = ', sphum

!if (P .eq. 100000.0) THEN
! print *, 'T = ', T, ' RH = ', RH, ' P = ', P, ' es = ', es, ' e = ', e, ' q = ', sphum
!end if

end subroutine RH2SPFH

subroutine convert_omega(omega,p,t,q,clb,cub)

implicit none
real(esmf_kind_r8), pointer :: omega(:,:,:), p(:,:,:), t(:,:,:), q(:,:,:),omtmp,ptmp

integer :: clb(3), cub(3), i ,j, k

real, parameter :: Rd = 287.15_esmf_kind_r8, & !JKg^-1K^-1
Rv=461.51_esmf_kind_r8, & !JKg^-1K^-1
g = 9.81_esmf_kind_r8 ! ms^-2

real(esmf_kind_r8) :: tv, w

do k = clb(3),cub(3)
do j = clb(2),cub(2)
do i = clb(1),cub(1)
tv = t(i,j,k)*(1+Rd/Rv*q(i,j,k))
omtmp=>omega(i,j,k)
ptmp=>p(i,j,k)

w = -1 * omtmp * Rd * tv / (ptmp * g)
omega(i,j,k)=w
enddo
enddo
enddo

end subroutine convert_omega

end module grib2_util
Loading

0 comments on commit 5ecb21a

Please sign in to comment.