MAPL_NetCDF.F90 Source File


This file depends on

sourcefile~~mapl_netcdf.f90~~EfferentGraph sourcefile~mapl_netcdf.f90 MAPL_NetCDF.F90 sourcefile~mapl_cf_time.f90 MAPL_CF_Time.F90 sourcefile~mapl_netcdf.f90->sourcefile~mapl_cf_time.f90 sourcefile~mapl_datetime_parsing_esmf.f90 MAPL_DateTime_Parsing_ESMF.F90 sourcefile~mapl_netcdf.f90->sourcefile~mapl_datetime_parsing_esmf.f90 sourcefile~mapl_exceptionhandling.f90 MAPL_ExceptionHandling.F90 sourcefile~mapl_netcdf.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_keywordenforcer.f90 MAPL_KeywordEnforcer.F90 sourcefile~mapl_netcdf.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~mapl_cf_time.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_cf_time.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~mapl_datetime_parsing_esmf.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_datetime_parsing_esmf.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~mapl_errorhandling.f90 MAPL_ErrorHandling.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_errorhandling.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_throw.f90 sourcefile~mapl_errorhandling.f90->sourcefile~mapl_throw.f90

Files dependent on this one

sourcefile~~mapl_netcdf.f90~~AfferentGraph sourcefile~mapl_netcdf.f90 MAPL_NetCDF.F90 sourcefile~mapl_geosatmaskmod.f90 MAPL_GeosatMaskMod.F90 sourcefile~mapl_geosatmaskmod.f90->sourcefile~mapl_netcdf.f90 sourcefile~mapl_obsutil.f90 MAPL_ObsUtil.F90 sourcefile~mapl_geosatmaskmod.f90->sourcefile~mapl_obsutil.f90 sourcefile~mapl_geosatmaskmod_smod.f90 MAPL_GeosatMaskMod_smod.F90 sourcefile~mapl_geosatmaskmod_smod.f90->sourcefile~mapl_netcdf.f90 sourcefile~mapl_geosatmaskmod_smod.f90->sourcefile~mapl_geosatmaskmod.f90 sourcefile~mapl_obsutil.f90->sourcefile~mapl_netcdf.f90 sourcefile~mapl_trajectorymod_smod.f90 MAPL_TrajectoryMod_smod.F90 sourcefile~mapl_trajectorymod_smod.f90->sourcefile~mapl_netcdf.f90 sourcefile~mapl_trajectorymod_smod.f90->sourcefile~mapl_obsutil.f90 sourcefile~mapl_trajectorymod.f90 MAPL_TrajectoryMod.F90 sourcefile~mapl_trajectorymod_smod.f90->sourcefile~mapl_trajectorymod.f90 sourcefile~test_mapl_netcdf.pf test_MAPL_NetCDF.pf sourcefile~test_mapl_netcdf.pf->sourcefile~mapl_netcdf.f90 sourcefile~mapl_historycollection.f90 MAPL_HistoryCollection.F90 sourcefile~mapl_historycollection.f90->sourcefile~mapl_geosatmaskmod.f90 sourcefile~mapl_historycollection.f90->sourcefile~mapl_trajectorymod.f90 sourcefile~mapl_historygridcomp.f90 MAPL_HistoryGridComp.F90 sourcefile~mapl_historygridcomp.f90->sourcefile~mapl_geosatmaskmod.f90 sourcefile~mapl_historygridcomp.f90->sourcefile~mapl_obsutil.f90 sourcefile~mapl_historygridcomp.f90->sourcefile~mapl_historycollection.f90 sourcefile~mapl_historygridcomp.f90->sourcefile~mapl_trajectorymod.f90 sourcefile~mapl_swathgridfactory.f90 MAPL_SwathGridFactory.F90 sourcefile~mapl_swathgridfactory.f90->sourcefile~mapl_obsutil.f90 sourcefile~mapl_trajectorymod.f90->sourcefile~mapl_obsutil.f90 sourcefile~mapl_xygridfactory.f90 MAPL_XYGridFactory.F90 sourcefile~mapl_xygridfactory.f90->sourcefile~mapl_obsutil.f90 sourcefile~extdatadrivergridcomp.f90 ExtDataDriverGridComp.F90 sourcefile~extdatadrivergridcomp.f90->sourcefile~mapl_historygridcomp.f90 sourcefile~mapl_capgridcomp.f90 MAPL_CapGridComp.F90 sourcefile~mapl_capgridcomp.f90->sourcefile~mapl_historygridcomp.f90 sourcefile~mapl_gridmanager.f90 MAPL_GridManager.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_swathgridfactory.f90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_xygridfactory.f90

Source Code

#include "MAPL_Exceptions.h"
#include "MAPL_ErrLog.h"
! Procedures to convert from NetCDF datetime to ESMF_Time and ESMF_TimeInterval
! NetCDF datetime is: {integer, character(len=*)}
! {1800, 'seconds since 2010-01-23 18:30:37'}
! {TIME_SPAN, 'TIME_UNIT since YYYY-MM-DD hh:mm:ss'}
module MAPL_NetCDF

   use MAPL_ExceptionHandling
   use MAPL_KeywordEnforcerMod
   use MAPL_DateTime_Parsing, only: datetime_duration
   use MAPL_DateTime_Parsing_ESMF
   use MAPL_CF_Time

   implicit none

   public :: convert_NetCDF_DateTime_to_ESMF
   public :: get_ESMF_Time_from_NetCDF_DateTime

   private

   interface convert_NetCDF_DateTime_to_ESMF
      module procedure :: get_ESMF_Time_from_NetCDF_DateTime_integer
      module procedure :: get_ESMF_Time_from_NetCDF_DateTime_real
   end interface convert_NetCDF_DateTime_to_ESMF

   interface get_ESMF_Time_from_NetCDF_DateTime
      module procedure :: get_ESMF_Time_from_NetCDF_DateTime_integer
      module procedure :: get_ESMF_Time_from_NetCDF_DateTime_real
   end interface get_ESMF_Time_from_NetCDF_DateTime

!   integer, parameter :: MAX_CHARACTER_LENGTH = 64

contains

!===============================================================================
!========================= HIGH-LEVEL PROCEDURES ===========================

   ! Convert NetCDF_DateTime {int_time, units_string} to
   ! ESMF time variables {interval, basetime, time} and time unit {time_unit}
   ! basetime is the start time, and time is basetime + interval
   subroutine get_ESMF_Time_from_NetCDF_DateTime_integer(duration, units_string, &
      interval, basetime, unusable, time, time_unit, rc)
      integer, intent(in) :: duration
      character(len=*), intent(in) :: units_string
      type(ESMF_TimeInterval), intent(inout) :: interval
      type(ESMF_Time), intent(inout) :: basetime
      class (KeywordEnforcer), optional, intent(in) :: unusable
      type(ESMF_Time), optional, intent(inout) :: time
      character(len=:), allocatable, optional, intent(out) :: time_unit
      integer, optional, intent(out) :: rc

      type(CF_Time_Integer) :: cft
      type(datetime_duration) :: dt_duration
      character(len=MAX_CHARACTER_LENGTH) :: isostring
      character(len=MAX_CHARACTER_LENGTH) :: tunit_
      integer :: status
      
      _UNUSED_DUMMY(unusable)

      _ASSERT((len_trim(adjustl(units_string)) > 0), 'units empty')

      cft = CF_Time_Integer(duration, units_string)
      call convert_CF_Time_to_datetime_duration(cft, dt_duration, _RC)
      call set_ESMF_TimeInterval(interval, dt_duration, _RC)

      call extract_ISO8601_from_CF_Time(cft, isostring, _RC)
      call set_ESMF_Time_from_ISO8601(basetime, isostring, _RC)

      if(present(time)) time = basetime + interval

      if(present(time_unit)) then
         call extract_CF_Time_unit(cft, tunit_, _RC)
         time_unit = trim(tunit_)
      end if

      _RETURN(_SUCCESS)

   end subroutine get_ESMF_Time_from_NetCDF_DateTime_integer

   ! Convert NetCDF_DateTime {real_time, units_string} to
   ! ESMF time variables {interval, basetime, time} and time unit {time_unit}
   ! basetime is the start time, and time is basetime + interval
   subroutine get_ESMF_Time_from_NetCDF_DateTime_real(duration, units_string, &
      interval, basetime, unusable, time, time_unit, rc)
      real(kind=ESMF_KIND_R8), intent(in) :: duration
      character(len=*), intent(in) :: units_string
      type(ESMF_TimeInterval), intent(inout) :: interval
      type(ESMF_Time), intent(inout) :: basetime
      class (KeywordEnforcer), optional, intent(in) :: unusable
      type(ESMF_Time), optional, intent(inout) :: time
      character(len=:), allocatable, optional, intent(out) :: time_unit
      integer, optional, intent(out) :: rc

      type(CF_Time_Real) :: cft
      type(datetime_duration) :: dt_duration
      character(len=MAX_CHARACTER_LENGTH) :: isostring
      character(len=MAX_CHARACTER_LENGTH) :: tunit_
      integer :: status
      
      _UNUSED_DUMMY(unusable)

      _ASSERT((len_trim(adjustl(units_string)) > 0), 'units empty')

      cft = CF_Time_Real(duration, units_string)
      call convert_CF_Time_to_datetime_duration(cft, dt_duration, _RC)
      call set_ESMF_TimeInterval(interval, dt_duration, _RC)

      call extract_ISO8601_from_CF_Time(cft, isostring, _RC)
      call set_ESMF_Time_from_ISO8601(basetime, isostring, _RC)

      if(present(time)) time = basetime + interval

      if(present(time_unit)) then
         call extract_CF_Time_unit(cft, tunit_, _RC)
         time_unit = trim(tunit_)
      end if

      _RETURN(_SUCCESS)

   end subroutine get_ESMF_Time_from_NetCDF_DateTime_real

!======================= END HIGH-LEVEL PROCEDURES =========================
!===============================================================================

end module MAPL_NetCDF