Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into feature/noahmp
Browse files Browse the repository at this point in the history
  • Loading branch information
uturuncoglu committed Jan 26, 2024
2 parents 970bcab + a2c9176 commit 40ecc30
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 55 deletions.
104 changes: 57 additions & 47 deletions io/module_write_internal_state.F90
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
!-----------------------------------------------------------------------
module write_internal_state
!
!-----------------------------------------------------------------------
!*** the internal state of the write component.
!-----------------------------------------------------------------------
!***
!*** revision history
!***
! Feb 2017: J. Wang - Initial code
!
!-----------------------------------------------------------------------
!
!> @file
!> @brief The internal state of the write component.
!> @author Jun Wang @date Feb, 2017

!> @brief The internal state of the write component.
!> @author Jun Wang @date Feb, 2017
module write_internal_state
use esmf
!
!-----------------------------------------------------------------------
Expand All @@ -20,12 +14,27 @@ module write_internal_state
!-----------------------------------------------------------------------
!
type output_grid_info
integer :: im, jm, lm
integer :: i_start,i_end, j_start,j_end
real,dimension(:,:),allocatable :: lonPtr, latPtr
integer,dimension(:),allocatable :: i_start_wrtgrp, i_end_wrtgrp, j_start_wrtgrp, j_end_wrtgrp
real :: latse, latnw, lonse, lonnw
real :: latstart, latlast, lonstart, lonlast
integer :: im !< Output grid global I dimension size.
integer :: jm !< Output grid global J dimension size.
integer :: lm !< Output grid global L dimension size.
integer :: i_start !< Output grid lower bound of I dimension on current PE.
integer :: i_end !< Output grid upper bound of I dimension on current PE.
integer :: j_start !< Output grid lower bound of J dimension on current PE.
integer :: j_end !< Output grid upper bound of J dimension on current PE.
real,dimension(:,:),allocatable :: lonPtr !< Output grid longitudes.
real,dimension(:,:),allocatable :: latPtr !< Output grid latitudes.
integer,dimension(:),allocatable :: i_start_wrtgrp !< I dimension lower bound of all wrire groups.
integer,dimension(:),allocatable :: i_end_wrtgrp !< I dimension upper bound of all wrire groups.
integer,dimension(:),allocatable :: j_start_wrtgrp !< J dimension lower bound of all wrire groups.
integer,dimension(:),allocatable :: j_end_wrtgrp !< J dimension upper bound of all wrire groups.
real :: latse !< Output grid South East corner latitude.
real :: latnw !< Output grid North West corner latitude.
real :: lonse !< Output grid South East corner longitude.
real :: lonnw !< Output grid North West corner longitude.
real :: latstart !< Output grid start latitude.
real :: latlast !< Output grid last latitude.
real :: lonstart !< Output grid start logitude.
real :: lonlast !< Output grid last longitude.
end type output_grid_info

type wrt_internal_state
Expand All @@ -34,72 +43,73 @@ module write_internal_state
! pe information and task layout
!--------------------------------
!
integer :: mype
integer :: petcount
integer :: mype !< MPI rank.
integer :: petcount !< Number of PEs.
!
!--------------------
!*** grid information
!--------------------
type(esmf_grid) :: wrtgrid
type(esmf_grid) :: wrtgrid !< ESMF output grid.

type(output_grid_info) ,dimension(:), allocatable :: out_grid_info
!> Array of output_grid_info for all domains.
type(output_grid_info) ,dimension(:), allocatable :: out_grid_info
!
!--------------------------
!*** file bundle for output
!--------------------------
integer :: FBCount
integer :: FBCount !< Numebr of output ESMF field bundles.
!
!-----------------------------------------------------------------------
!*** THE OUTPUT FILE
!-----------------------------------------------------------------------
!
integer :: num_files
integer :: num_files !< Number of output files.
!
!-----------------------------------------------------------------------
!*** THE OUTPUT FILE
!-----------------------------------------------------------------------
!
type(ESMF_FieldBundle),dimension(:),allocatable :: wrtFB
!> ESMF write field bundles.
type(ESMF_FieldBundle),dimension(:),allocatable :: wrtFB
!
!-------------------------------------
!*** Times used in history filenames
!-------------------------------------
!
type(ESMF_Time) :: io_basetime
integer :: idate(7)
integer :: fdate(7)
type(ESMF_Time) :: io_basetime !< ESMF clock's starting time.
integer :: idate(7) !< Forecast initial time.
integer :: fdate(7) !< Forecast current time.
!
!-----------------------------------------
!*** I/O direction flags (Read or Write)
!-----------------------------------------
!
logical :: output_history
logical :: output_history !< True if history output is requested.
!
!-----------------------------------------
!*** POST flags and required variables
!-----------------------------------------
!
logical :: write_dopost
character(80) :: post_namelist
!
integer :: fhzero
integer :: ntrac
integer :: ncld
integer :: nsoil
integer :: imp_physics
integer :: dtp
real,dimension(:),allocatable :: ak,bk
logical :: write_dopost !< True if inline post is requested.
character(80) :: post_namelist !< File name of the inline post namelist.
!
integer :: fhzero !< Hours between clearing of diagnostic buckets.
integer :: ntrac !< Number of tracers.
integer :: ncld !< Number of hydrometeors.
integer :: nsoil !< Number of soil layers.
integer :: imp_physics !< Choice of microphysics scheme.
integer :: dtp !< Physics timestep.
real,dimension(:),allocatable :: ak !< a parameter for sigma pressure level calculations.
real,dimension(:),allocatable :: bk !< b parameter for sigma pressure level calculations.
!-----------------------------------------------------------------------
!
end type wrt_internal_state
!
!-----------------------------------------------------------------------
!*** THIS STATE IS SUPPORTED BY C POINTERS BUT NOT F90 POINTERS
!*** THEREFORE WE NEED THIS WRAP.
!-----------------------------------------------------------
!

!> This state is supported by c pointers but not f90 pointers
!> therefore we need this wrap.
type write_wrap
type(wrt_internal_state),pointer :: write_int_state
!> Write grid component internal state.
type(wrt_internal_state),pointer :: write_int_state
end type write_wrap

!-----------------------------------------------------------
Expand Down
60 changes: 52 additions & 8 deletions io/module_write_netcdf.F90
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
!> @file
!> @brief Module containing history files output routines.
!> @author Dusan Jovic @date Nov 1, 2017

!> Return error to ESMF and finalize it.
#define ESMF_ERR_RETURN(rc) \
if (ESMF_LogFoundError(rc, msg="Breaking out of subroutine", line=__LINE__, file=__FILE__)) call ESMF_Finalize(endflag=ESMF_END_ABORT)

!> Return error to ESMF and finalize it.
#define NC_ERR_STOP(status) \
if (status /= nf90_noerr) write(0,*) "file: ", __FILE__, " line: ", __LINE__, trim(nf90_strerror(status)); \
if (status /= nf90_noerr) call ESMF_Finalize(endflag=ESMF_END_ABORT)

!> @brief Output routines for writing history files.
!>
!> @author Dusan Jovic @date Nov 1, 2017
module module_write_netcdf

use mpi
Expand All @@ -19,11 +28,21 @@ module module_write_netcdf
private
public write_netcdf

logical :: par

contains

!----------------------------------------------------------------------------------------
logical :: par !< True if parallel I/O should be used.

contains

!> Write netCDF file.
!>
!> @param[in] wrtfb ESMF write field bundle.
!> @param[in] filename NetCDF filename.
!> @param[in] use_parallel_netcdf True if parallel I/O should be used.
!> @param[in] mpi_comm MPI communicator for parallel I/O.
!> @param[in] mype MPI rank.
!> @param[in] grid_id Output grid identifier.
!> @param[out] rc Return code - 0 for success, ESMF error code otherwise.
!>
!> @author Dusan Jovic @date Nov 1, 2017
subroutine write_netcdf(wrtfb, filename, &
use_parallel_netcdf, mpi_comm, mype, &
grid_id, rc)
Expand Down Expand Up @@ -716,7 +735,14 @@ subroutine write_netcdf(wrtfb, filename, &

end subroutine write_netcdf

!----------------------------------------------------------------------------------------
!> Get global attribute.
!>
!> @param[in] fldbundle ESMF field bundle.
!> @param[in] ncid NetCDF file ID.
!> @param[in] mype MPI rank.
!> @param[out] rc Return code - 0 for success, ESMF error code otherwise.
!>
!> @author Dusan Jovic @date Nov 1, 2017
subroutine get_global_attr(fldbundle, ncid, mype, rc)
type(ESMF_FieldBundle), intent(in) :: fldbundle
integer, intent(in) :: ncid
Expand Down Expand Up @@ -785,7 +811,15 @@ subroutine get_global_attr(fldbundle, ncid, mype, rc)

end subroutine get_global_attr

!----------------------------------------------------------------------------------------
!> Get grid attribute.
!>
!> @param[in] grid ESMF output grid.
!> @param[in] prefix grid attribute prefix.
!> @param[in] ncid NetCDF file ID.
!> @param[in] varid NetCDF variable ID.
!> @param[out] rc Return code - 0 for success, ESMF error code otherwise.
!>
!> @author Dusan Jovic @date Nov 1, 2017
subroutine get_grid_attr(grid, prefix, ncid, varid, rc)
type(ESMF_Grid), intent(in) :: grid
character(len=*), intent(in) :: prefix
Expand Down Expand Up @@ -849,7 +883,17 @@ subroutine get_grid_attr(grid, prefix, ncid, varid, rc)

end subroutine get_grid_attr

!----------------------------------------------------------------------------------------
!> Add a dimension.
!>
!> @param[in] ncid NetCDF file ID.
!> @param[in] dim_name Dimension name.
!> @param[in] dimid Dimension ID.
!> @param[in] grpid Group ID.
!> @param[in] grid ESMF output grid.
!> @param[in] mype MPI rank.
!> @param[out] rc Return code - 0 for success, ESMF error code otherwise.
!>
!> @author Dusan Jovic @date Nov 1, 2017
subroutine add_dim(ncid, dim_name, dimid, grid, mype, rc)
integer, intent(in) :: ncid
character(len=*), intent(in) :: dim_name
Expand Down

0 comments on commit 40ecc30

Please sign in to comment.