Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert GEOS-Chem netCDF utility routines to use the netCDF-F90 interface #1882

Merged
merged 4 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Explicitly define tagCH4 simulations in `Input_Opt` rather than basing off of number of advected species
- The `fullchem` mechanism must now be built with KPP 3.0.0 or later
- Changed the AEIC 2019 monthly climatology specification format in ExtData.rc to match standard convention for climatology
- NetCDF utilities in `NcdfUtil` folder now use the netCDF-F90 API

### Fixed
- Add missing mol wt for HgBrO in `run/shared/species_database_hg.yml`
Expand Down
67 changes: 21 additions & 46 deletions NcdfUtil/m_netcdf_io_checks.F90
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ module m_netcdf_io_checks
!
function Ncdoes_Udim_Exist (ncid)
!
implicit none
!
include "netcdf.inc"
use netCDF
!
! !INPUT PARAMETERS:
!! ncid : netCDF file id to check
Expand All @@ -70,18 +68,11 @@ function Ncdoes_Udim_Exist (ncid)
!BOC
!
! !LOCAL VARIABLES:
integer :: ierr
integer :: udimid
!
ierr = Nf_Inq_Unlimdim (ncid, udimid)
integer :: ierr, udim_id

if (ierr == NF_NOERR) then
Ncdoes_Udim_Exist = .true.
else
Ncdoes_Udim_Exist = .false.
end if

return
Ncdoes_Udim_Exist = .false.
ierr = NF90_Inquire(ncid, unlimitedDimId=udim_id)
IF ( ierr /= NF90_NOERR ) Ncdoes_Udim_Exist = .true.

end function Ncdoes_Udim_Exist
!EOC
Expand All @@ -96,9 +87,7 @@ end function Ncdoes_Udim_Exist
!
function Ncdoes_Var_Exist (ncid, varname)
!
implicit none
!
include "netcdf.inc"
use netCDF
!
! !INPUT PARAMETERS:
!! ncid : netCDF file id to check
Expand Down Expand Up @@ -126,15 +115,9 @@ function Ncdoes_Var_Exist (ncid, varname)
integer :: ierr
integer :: varid
!
ierr = Nf_Inq_Varid (ncid, varname, varid)

if (ierr == NF_NOERR) then
Ncdoes_Var_Exist = .true.
else
Ncdoes_Var_Exist = .false.
end if

return
ierr = NF90_Inq_Varid(ncid, varname, varid)
Ncdoes_Var_Exist = .false.
if (ierr == NF90_NOERR) Ncdoes_Var_Exist = .true.

end function Ncdoes_Var_Exist
!EOC
Expand All @@ -147,11 +130,9 @@ end function Ncdoes_Var_Exist
!
! !INTERFACE:
!
function Ncdoes_Attr_Exist (ncid, varname, attname, attType)
!
implicit none
function Ncdoes_Attr_Exist(ncid, varname, attname, attType)
!
include "netcdf.inc"
use netCDF
!
! !INPUT PARAMETERS:
!! ncid : netCDF file id to check
Expand Down Expand Up @@ -184,21 +165,20 @@ function Ncdoes_Attr_Exist (ncid, varname, attname, attType)
!BOC
!
! !LOCAL VARIABLES:
integer :: ierr
integer :: varid
INTEGER :: attLen
INTEGER :: ierr, varId, attLen, attNum

! Init
Ncdoes_Attr_Exist = .false.
attType = -1

! First check the variable
ierr = Nf_Inq_Varid (ncid, varname, varid)
ierr = NF90_Inq_Varid (ncid, varname, varid)

! Check the attribute if variable was found
IF ( ierr == NF_NOERR ) THEN
ierr = Nf_Inq_Att( ncId, varId, attName, attType, attLen )
IF ( ierr == NF_NOERR ) THEN
IF ( ierr == NF90_NOERR ) THEN
ierr = NF90_Inquire_Attribute( ncId, varId, attName, &
attType, attLen, attNum )
IF ( ierr == NF90_NOERR ) THEN
NcDoes_Attr_Exist = .TRUE.
ENDIF
ENDIF
Expand All @@ -218,9 +198,7 @@ end function Ncdoes_Attr_Exist
!
function Ncdoes_Dim_Exist (ncid, dimname )
!
implicit none
!
include "netcdf.inc"
use netCDF
!
! !INPUT PARAMETERS:
!! ncid : netCDF file id to check
Expand Down Expand Up @@ -249,14 +227,11 @@ function Ncdoes_Dim_Exist (ncid, dimname )
integer :: dimid

! First check the variable
ierr = Nf_Inq_Dimid (ncid, dimname, dimid)
ierr = NF90_Inq_Dimid(ncid, dimname, dimid)

! Check the attribute if variable was found
if (ierr == NF_NOERR) then
Ncdoes_Dim_Exist = .true.
else
Ncdoes_Dim_Exist = .false.
end if
Ncdoes_Dim_Exist = .false.
if (ierr == NF90_NOERR) Ncdoes_Dim_Exist = .true.

return

Expand Down
44 changes: 18 additions & 26 deletions NcdfUtil/m_netcdf_io_create.F90
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,15 @@ subroutine Nccr_Wr (ncid, filname, WRITE_NC4)
!
! !USES:
!
use netCDF
use m_do_err_out
!
implicit none
!
include "netcdf.inc"
!
! !INPUT PARAMETERS:
! ncid : opened netCDF file id
! filname : name of netCDF file to open for writing
integer , intent(in) :: ncid
character (len=*), intent(in) :: filname
LOGICAL, OPTIONAL, INTENT(IN) :: WRITE_NC4
integer , intent(INOUT) :: ncid
character (len=*), intent(IN) :: filname
LOGICAL, OPTIONAL, INTENT(IN) :: WRITE_NC4
!
! !DESCRIPTION: Creates a netCDF file for writing and does some error checking.
!\\
Expand All @@ -65,10 +62,10 @@ subroutine Nccr_Wr (ncid, filname, WRITE_NC4)
! John Tannahill (LLNL) and Jules Kouatchou
!
! !REMARKS:
! If the netCDF4 library is used, then the NF_CLOBBER flag will write
! If the netCDF4 library is used, then the NF90_CLOBBER flag will write
! a classic (i.e. netCDF3) file. Use OR(NF_NETCDF4,NF_CLASSIC_MODEL) to
! create netCDF-4 file that supports compression and uses "classic" netcdf data model
! (no groups, no user-defined types)
! create netCDF-4 file that supports compression and uses "classic"
! netcdf data model (no groups, no user-defined types)
!
! !REVISION HISTORY:
! See https://github.com/geoschem/ncdfutil for complete history
Expand All @@ -91,18 +88,18 @@ subroutine Nccr_Wr (ncid, filname, WRITE_NC4)
ENDIF

IF ( TMP_NC4 ) THEN
#if defined( NC_HAS_COMPRESSION )
mode = IOR( NF_NETCDF4, NF_CLASSIC_MODEL ) ! netCDF4 file
ierr = Nf_Create (filname, mode, ncid) ! w/ compression
#ifdef NC_HAS_COMPRESSION )
mode = IOR( NF90_NETCDF4, NF90_CLASSIC_MODEL ) ! netCDF4 file
ierr = NF90_Create(filname, mode, ncid) ! w/ compression
#else
ierr = Nf_Create (filname, NF_64BIT_OFFSET, ncid) ! netCDF4 file
! w/o compression
ierr = NF90_Create(filname, NF90_64BIT_OFFSET, ncid) ! netCDF4 file
! w/o compression
#endif
ELSE
ierr = Nf_Create (filname, NF_CLOBBER, ncid) ! netCDF3 file
ierr = NF90_Create(filname, NF90_CLOBBER, ncid) ! netCDF3 file
ENDIF

if (ierr /= NF_NOERR) then
if (ierr /= NF90_NOERR) then
err_msg = 'In Nccr_Wr, cannot create: ' // Trim (filname)
call Do_Err_Out (err_msg, .true., 0, 0, 0, 0 , 0.0d0, 0.0d0)
end if
Expand All @@ -124,11 +121,8 @@ subroutine Ncdo_Sync (ncid)
!
! !USES:
!
use netCDF
use m_do_err_out
!
implicit none
!
include "netcdf.inc"
!
! !INPUT PARAMETERS:
!! ncid : netCDF file id
Expand All @@ -150,15 +144,13 @@ subroutine Ncdo_Sync (ncid)
character (len=128) :: err_msg
integer :: ierr
!
ierr = Nf_Sync (ncid)
ierr = NF90_Sync (ncid)

if (ierr /= NF_NOERR) then
err_msg = 'In Ncdo_Sync: ' // Nf_Strerror (ierr)
if (ierr /= NF90_NOERR) then
err_msg = 'In Ncdo_Sync: ' // NF90_Strerror (ierr)
call Do_Err_Out (err_msg, .true., 1, ncid, 0, 0, 0.0d0, 0.0d0)
end if

return

end subroutine Ncdo_Sync
!EOC
end module m_netcdf_io_create
Loading