LCOV - code coverage report
Current view: | top level - hemco/HEMCO/src/Core - hcoio_diagn_mod.F90 (source / functions) |  |  | Hit | Total | Coverage
Test: | coverage.info |  | Lines: | 0 | 29 | 0.0 %
Date: | 2025-01-13 21:54:50 |  | Functions: | 0 | 2 | 0.0 %

              Line data    Source code
           1             : !EOC
           2             : !------------------------------------------------------------------------------
           3             : !                   Harmonized Emissions Component (HEMCO)                    !
           4             : !------------------------------------------------------------------------------
           5             : !BOP
           6             : !
           7             : ! !MODULE: hcoio_diagn_mod.F90
           8             : !
           9             : ! !DESCRIPTION: Module HCOIO\_Diagn\_Mod.F90 is the data interface module
          10             : ! for the HEMCO diagnostics. It contains routines to write out diagnostics
          11             : ! into a netCDF file.
          12             : !\\
          13             : !\\
          14             : ! In an ESMF/MAPL environment, the HEMCO diagnostics are not directly
          15             : ! written to disk but passed to the gridded component export state, where
          16             : ! they can be picked up by the MAPL HISTORY component.
          17             : !\\
          18             : !\\
          19             : ! !INTERFACE:
          20             : !
          21             : MODULE HCOIO_DIAGN_MOD
          22             : !
          23             : ! !USES:
          24             : !
          25             :   USE HCO_ERROR_MOD
          26             :
          27             :   IMPLICIT NONE
          28             :   PRIVATE
          29             : !
          30             : ! !PUBLIC MEMBER FUNCTIONS:
          31             : !
          32             :   PUBLIC :: HcoDiagn_Write
          33             :   PUBLIC :: HCOIO_Diagn_WriteOut
          34             : !
          35             : ! !REMARKS:
          36             : !  HEMCO diagnostics are still in testing mode. We will fully activate them
          37             : !  at a later time.  They will be turned on when debugging & unit testing.
          38             : !
          39             : ! !REVISION HISTORY:
          40             : !  04 May 2014 - C. Keller   - Initial version.
          41             : !  See https://github.com/geoschem/hemco for complete history
          42             : !EOP
          43             : !------------------------------------------------------------------------------
          44             : !BOC
          45             : !
          46             : ! !DEFINED PARAMETERS:
          47             : !
          48             :   ! Fill value used in HEMCO diagnostics netCDF files.
          49             : !  REAL(hp), PARAMETER :: FillValue = 1.e-31_hp
          50             :   REAL(sp), PARAMETER :: FillValue = HCO_MISSVAL
          51             :
          52             : CONTAINS
          53             : !EOC
          54             : !------------------------------------------------------------------------------
          55             : !                   Harmonized Emissions Component (HEMCO)                    !
          56             : !------------------------------------------------------------------------------
          57             : !BOP
          58             : !
          59             : ! !IROUTINE: HcoDiagn_Write
          60             : !
          61             : ! !DESCRIPTION: Subroutine HcoDiagn\_Write is the wrapper routine to write out
          62             : ! the content of the built-in HEMCO diagnostics. If input argument Restart is
          63             : ! set to TRUE, only the restart collection will be written out. Otherwise,
          64             : ! the default collection
          65             : !\\
          66             : !\\
          67             : ! !INTERFACE:
          68             : !
          69           0 :   SUBROUTINE HcoDiagn_Write( HcoState, Restart, RC )
          70             : !
          71             : ! !USES:
          72             : !
          73             :     USE HCO_State_Mod,        ONLY : HCO_State
          74             :     USE HCO_Clock_Mod,        ONLY : HcoClock_SetLast
          75             : !
          76             : ! !INPUT/OUTPUT PARAMETERS:
          77             : !
          78             :     TYPE(HCO_State), POINTER          :: HcoState     ! HEMCO state object
          79             :     LOGICAL,         INTENT(IN   )    :: Restart      ! write restart (enforced)?
          80             : !
          81             : ! !INPUT/OUTPUT PARAMETERS:
          82             : !
          83             :     INTEGER,         INTENT(INOUT)    :: RC           ! Return code
          84             : !
          85             : ! !REVISION HISTORY:
          86             : !  03 Apr 2015 - C. Keller   - Initial version
          87             : !  See https://github.com/geoschem/hemco for complete history
          88             : !EOP
          89             : !------------------------------------------------------------------------------
          90             : !BOC
          91             : !
          92             : ! !LOCAL VARIABLES:
          93             : !
          94             :     INTEGER            :: I, COL
          95             :     CHARACTER(LEN=255) :: MSG, LOC
          96             : #ifdef ADJOINT
          97             :     INTEGER            :: MaxIdx
          98             : #endif
          99             :
         100             :     !=================================================================
         101             :     ! HcoDiagn_Write begins here!
         102             :     !=================================================================
         103             :
         104             :     ! Init
         105           0 :     LOC = 'HcoDiagn_Write (hcoio_diagn_mod.F90)'
         106             :
         107             :     ! To write restart (enforced)
         108           0 :     IF ( RESTART ) THEN
         109             :        CALL HCOIO_DIAGN_WRITEOUT ( HcoState,                               &
         110             :                                    ForceWrite  = .TRUE.,                   &
         111             :                                    UsePrevTime = .FALSE.,                  &
         112             :                                    COL = HcoState%Diagn%HcoDiagnIDRestart, &
         113           0 :                                    RC          = RC                         )
         114           0 :        IF( RC /= HCO_SUCCESS) RETURN
         115             :
         116             :        ! Set last flag for use below
         117           0 :        CALL HcoClock_SetLast ( HcoState%Clock, .TRUE., RC )
         118           0 :        IF( RC /= HCO_SUCCESS) RETURN
         119             :
         120             :        CALL HCOIO_DIAGN_WRITEOUT ( HcoState,                               &
         121             :                                    ForceWrite  = .FALSE.,                  &
         122             :                                    UsePrevTime = .FALSE.,                  &
         123             :                                    COL = HcoState%Diagn%HcoDiagnIDDefault, &
         124           0 :                                    RC          = RC                         )
         125           0 :        IF( RC /= HCO_SUCCESS) RETURN
         126             :
         127             : #ifdef ADJOINT
         128             :        IF (HcoState%isAdjoint) THEN
         129             :        CALL HCOIO_DIAGN_WRITEOUT ( HcoState,                               &
         130             :                                    ForceWrite  = .FALSE.,                  &
         131             :                                    UsePrevTime = .FALSE.,                  &
         132             :                                    COL = HcoState%Diagn%HcoDiagnIDAdjoint, &
         133             :                                    RC          = RC                         )
         134             :        IF( RC /= HCO_SUCCESS) RETURN
         135             :        ENDIF
         136             : #endif
         137             :
         138             :        ! Reset IsLast flag. This is to ensure that the last flag is not
         139             :        ! carried over (ckeller, 11/1/16).
         140           0 :        CALL HcoClock_SetLast ( HcoState%Clock, .FALSE., RC )
         141           0 :        IF( RC /= HCO_SUCCESS) RETURN
         142             :
         143             :     ELSE
         144             :
         145             :        ! Loop over all collections that shall be written out.
         146             :        ! HCOIO_DIAGN_WRITEOUT will determine whether it is time to
         147             :        ! write a collection or not.
         148             : #ifndef ADJOINT
         149           0 :        DO I = 1, 3
         150             : #else
         151             :        MaxIdx = 3
         152             :        IF (HcoState%isAdjoint) MaxIdx = 4
         153             :        DO I = 1, MaxIdx
         154             : #endif
         155             :
         156             :           ! Define collection ID
         157           0 :           SELECT CASE ( I )
         158             :              CASE ( 1 )
         159           0 :                 COL = HcoState%Diagn%HcoDiagnIDDefault
         160             :              CASE ( 2 )
         161           0 :                 COL = HcoState%Diagn%HcoDiagnIDRestart
         162             :              CASE ( 3 )
         163           0 :                 COL = HcoState%Diagn%HcoDiagnIDManual
         164             : #ifdef ADJOINT
         165             :              CASE ( 4 )
         166             :                 COL = HcoState%Diagn%HcoDiagnIDAdjoint
         167             : #endif
         168             :           END SELECT
         169             :
         170             : #if       !defined ( ESMF_ )
         171             :           ! If not ESMF environment, never write the manual diagnostics
         172             :           ! to disk. Instead, the content of the manual diagnostics needs
         173             :           ! to be fetched explicitly.
         174           0 :           IF ( I == 3 ) CYCLE
         175             : #else
         176             :           ! Don't write restart variables to EXPORT in an ESMF environment.
         177             :           ! They are already passed to the INTERNAL state when calling
         178             :           ! HCO_RestartWrite. (ckeller, 10/9/17)
         179             :           IF ( I == 2 ) CYCLE
         180             : #endif
         181             :
         182             :           ! Restart file
         183             :           CALL HCOIO_DIAGN_WRITEOUT ( HcoState,                        &
         184             :                                       ForceWrite  = .FALSE.,           &
         185             :                                       UsePrevTime = .FALSE.,           &
         186             :                                       COL         = COL,               &
         187           0 :                                       RC          = RC                  )
         188           0 :           IF(RC /= HCO_SUCCESS) RETURN
         189             :        ENDDO
         190             :     ENDIF
         191             :
         192             :   END SUBROUTINE HcoDiagn_Write
         193             : !EOC
         194             : !------------------------------------------------------------------------------
         195             : !                   Harmonized Emissions Component (HEMCO)                    !
         196             : !------------------------------------------------------------------------------
         197             : !BOP
         198             : !
         199             : ! !IROUTINE: HCOIO_Diagn_WriteOut
         200             : !
         201             : ! !DESCRIPTION: Subroutine HCOIO\_Diagn\_WriteOut writes diagnostics to
         202             : ! output. Depending on the model environment, different subroutines will
         203             : ! be invoked.
         204             : !\\
         205             : !\\
         206             : ! !INTERFACE:
         207             : !
         208           0 :   SUBROUTINE HCOIO_Diagn_WriteOut( HcoState, ForceWrite,  &
         209             :                                    RC,          PREFIX,   UsePrevTime, &
         210             :                                    OnlyIfFirst, COL                     )
         211             : !
         212             : ! !USES:
         213             : !
         214             :     USE HCO_State_Mod,        ONLY : HCO_State
         215             :     USE HCOIO_Write_Mod,      ONLY : HCOIO_Write
         216             : !
         217             : ! !INPUT PARAMETERS:
         218             : !
         219             :     TYPE(HCO_State),  POINTER                 :: HcoState    ! HEMCO state object
         220             :     LOGICAL,                    INTENT(IN   ) :: ForceWrite  ! Write all diagnostics?
         221             :     CHARACTER(LEN=*), OPTIONAL, INTENT(IN   ) :: PREFIX      ! File prefix
         222             :     LOGICAL,          OPTIONAL, INTENT(IN   ) :: UsePrevTime ! Use previous time
         223             :     LOGICAL,          OPTIONAL, INTENT(IN   ) :: OnlyIfFirst ! Only write if nnDiagn is 1
         224             :     INTEGER,          OPTIONAL, INTENT(IN   ) :: COL         ! Collection Nr.
         225             : !
         226             : ! !INPUT/OUTPUT PARAMETERS:
         227             : !
         228             :     INTEGER,          INTENT(INOUT) :: RC          ! Failure or success
         229             : !
         230             : ! !REVISION HISTORY:
         231             : !  12 Sep 2013 - C. Keller   - Initial version
         232             : !  See https://github.com/geoschem/hemco for complete history
         233             : !EOP
         234             : !------------------------------------------------------------------------------
         235             : !BOC
         236             : !
         237             : ! !LOCAL VARIABLES:
         238             : !
         239             :     ! Strings
         240             :     CHARACTER(LEN=255) :: errMsg, thisLoc
         241             :
         242             :     !=================================================================
         243             :     ! HCOIO_DIAGN_WRITEOUT begins here!
         244             :     !=================================================================
         245             :
         246             :     ! Initialize
         247           0 :     RC      = HCO_SUCCESS
         248           0 :     errMsg  = ''
         249           0 :     thisLoc = 'HCOIO_DIAGN_WRITEOUT (src/Core/hcoio_diagn_mod.F90)'
         250             :
         251             :
         252             : #if defined(ESMF_)
         253             :     !------------------------------------------------------------------------
         254             :     ! ESMF environment: call ESMF output routines
         255             :     !------------------------------------------------------------------------
         256             :     CALL HCOIO_Write( HcoState,                                              &
         257             :                       RC,                                                    &
         258             :                       OnlyIfFirst = OnlyIfFirst,                             &
         259             :                       COL          = COL                                    )
         260             :
         261             :     ! Trap errors
         262             :     IF ( RC /= HCO_SUCCESS ) THEN
         263             :        errMsg = 'Error encountered in routine "HCOIO_Write"!'
         264             :        CALL HCO_ERROR( errMsg, RC, thisLoc )
         265             :        RETURN
         266             :     ENDIF
         267             :
         268             : #else
         269             :     !------------------------------------------------------------------------
         270             :     ! Standard environment: call default output routines
         271             :     !------------------------------------------------------------------------
         272             :     CALL HCOIO_Write( HcoState,                                              &
         273             :                       ForceWrite,                                            &
         274             :                       RC,                                                    &
         275             :                       PREFIX      = PREFIX,                                  &
         276             :                       UsePrevTime = UsePrevTime,                             &
         277             :                       OnlyIfFirst = OnlyIfFirst,                             &
         278           0 :                       COL         = COL                                     )
         279             :
         280             :     ! Trap errors
         281           0 :     IF ( RC /= HCO_SUCCESS ) THEN
         282           0 :        errMsg = 'Error encountered in routine "HCOIO_Write"!'
         283           0 :        CALL HCO_ERROR( errMsg, RC, thisLoc )
         284           0 :        RETURN
         285             :     ENDIF
         286             :
         287             : #endif
         288             :
         289             :     ! Return
         290           0 :     RC = HCO_SUCCESS
         291             :
         292             :   END SUBROUTINE HCOIO_DIAGN_WRITEOUT
         293             : !EOC
         294             : END MODULE HCOIO_Diagn_Mod
         295             :

Generated by: LCOV version 1.14