Skip to content

Commit

Permalink
GEOS-CHem netCDF utils now use netCDF-Fortran90 (aka NF90) interface
Browse files Browse the repository at this point in the history
NcdfUtil/m_netcdf_*.F90
NcdfUtil/ncdf_mod.F90
- Replaced "INCLUDE netcdf.inc" with "use netCDF"
- Now use the NF90_ function and variables
- Added equivalent netCDF f u
- Use F90 indentation style
- Trimmed trailing whitespace

CHANGELOG.md
- Updated accordingly

    Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
  • Loading branch information
yantosca committed Jul 18, 2023
1 parent f9d697f commit 7282c0e
Show file tree
Hide file tree
Showing 10 changed files with 1,861 additions and 2,058 deletions.
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

0 comments on commit 7282c0e

Please sign in to comment.