!--------------------------------------------------------------------------------------------------
!  DOXYGEN
!> @brief OUTPUT OF FIELDS
!> @details PRINT IN A SEPARATE FILE FOR EACH PE AND EACH OUTPUT PERIOD.
!> @author ORIGINATOR - ?????
!> @date ??-??-?? \n
!> @author LUCCI 
!> @date 18-03-20 \n
!> @version V1.1.0
!> @details MODERNIZATION OF THE CODE, INCLUDING:
!!                      * F77 TO F90/F95
!!                      * INDENTATION & UNIFORMIZATION CODE
!!                      * REPLACEMENT OF COMMONS BLOCK FOR MODULES
!!                      * DOCUMENTATION WITH DOXYGEN
!!                      * OPENMP FUNCTIONALITY 
!<
!> @details <b>Use Module:</b>
!! @arg @c ACMCLD
!! @arg @c ACMCLH
!! @arg @c ACMPRE
!! @arg @c ACMRDL
!! @arg @c ACMRDS
!! @arg @c ACMSFC
!! @arg @c CLDWTR
!! @arg @c CNVCLD
!! @arg @c CONTIN
!! @arg @c CTLBLK
!! @arg @c DGNSOUT
!! @arg @c LOOPS
!! @arg @c MASKS
!! @arg @c MPPSTAFF
!! @arg @c NHYDRO
!! @arg @c PARMETA
!! @arg @c PHYS
!! @arg @c PPTASM
!! @arg @c PVRBLS
!! @arg @c SOIL
!! @arg @c VRBLS
!> @details <b>Driver:</b> 
!! @arg @c GEF
!> @details <b>Calls:</b>
!--------------------------------------------------------------------------------------------------     
    SUBROUTINE OUT2
!-------------------------------------------------------------------------------------------------- 
! SUBROUTINE OUT2
!
! SUBROUTINE: OUT2 - OUTPUT OF FIELDS
! PROGRAMMER: ?????  
! ORG: ?????
! DATE: ??-??-??
!
! ABSTRACT: 
! PRINT IN A SEPARATE FILE FOR EACH PE AND EACH OUTPUT PERIOD 
!
! PROGRAM HISTORY LOG:
! ??-??-??  ?????      - ORIGINATOR
! 18-01-15  LUCCI      - MODERNIZATION OF THE CODE, INCLUDING:
!                        * F77 TO F90/F95
!                        * INDENTATION & UNIFORMIZATION CODE
!                        * REPLACEMENT OF COMMONS BLOCK FOR MODULES
!                        * DOCUMENTATION WITH DOXYGEN
!                        * OPENMP FUNCTIONALITY
!
! INPUT ARGUMENT LIST:
! NONE
!
! OUTPUT ARGUMENT LIST:
! NONE
!
! INPUT/OUTPUT ARGUMENT LIST:
! NONE
!
! OUTPUT FILES:
! OUTPUT - PRINT FILE.
!
! USE MODULES: ACMCLD
!              ACMCLH
!              ACMPRE
!              ACMRDL
!              ACMRDS
!              ACMSFC
!              CLDWTR
!              CNVCLD
!              CONTIN
!              CTLBLK
!              DGNSOUT
!              LOOPS
!              MASKS
!              MPPSTAFF
!              NHYDRO
!              PARMETA
!              PHYS
!              PPTASM
!              PVRBLS
!              SOIL
!              VRBLS
!
! DRIVER     : GEF
!
! CALLS      : ----- 
!--------------------------------------------------------------------------------------------------
    USE ACMCLD
    USE ACMCLH
    USE ACMPRE
    USE ACMRDL
    USE ACMRDS
    USE ACMSFC
    USE CLDWTR
    USE CNVCLD
    USE CONTIN
    USE CTLBLK
    USE DGNSOUT
    USE LOOPS
    USE MASKS
    USE MPPSTAFF
    USE NHYDRO
    USE PARMETA
    USE PHYS
    USE PPTASM
    USE PVRBLS
    USE SOIL
    USE VRBLS
!
    IMPLICIT NONE
!
    CHARACTER(LEN=4)                                                                            ::&
    & C_NHRS
!   
    CHARACTER(LEN=150)                                                                          ::&
    & OUTFILE , OUTFILE2, OUTFILE3, OUTFILE4, OUTFILE5, OUTFILE6
!
    NHRS = NHRS + 1
!
    WRITE(C_NHRS,'(I4.4)') NHRS 
!            
    OUTFILE = "GEFfcst_"//C_MYPE//"."//C_NHRS
!
    OPEN (UNIT=LISTOUT, FILE= TRIM(OUTFILE), FORM = 'UNFORMATTED')
!
    WRITE(LISTOUT) PD
    WRITE(LISTOUT) T
    WRITE(LISTOUT) U
    WRITE(LISTOUT) V
    WRITE(LISTOUT) Q
    WRITE(LISTOUT) CWM
    WRITE(LISTOUT) THS
    WRITE(LISTOUT) U00
    WRITE(LISTOUT) UL
!    WRITE(LISTOUT) W      
!    WRITE(LISTOUT) DWDT    !NON-HYDROSTATIC
!    WRITE(LISTOUT) Z
!
    CLOSE (LISTOUT)
!
    OUTFILE2 = "GEFfcstVEG_"//C_MYPE//"."//C_NHRS
!
    OPEN (UNIT=LISTOUT, FILE= TRIM(OUTFILE2), FORM = 'UNFORMATTED')
!       
    WRITE(LISTOUT) TSHLTR
    WRITE(LISTOUT) QSHLTR
    WRITE(LISTOUT) PLM
    WRITE(LISTOUT) SFCLHX
    WRITE(LISTOUT) SFCSHX
!    WRITE(LISTOUT) QWBS
!    WRITE(LISTOUT) TWBS 
!    WRITE(LISTOUT) GRNFLX
    WRITE(LISTOUT) VEGFRC
!    WRITE(LISTOUT) IVGTYP
!    WRITE(LISTOUT) ISLTYP
!    WRITE(LISTOUT) GLAT
!    WRITE(LISTOUT) GLON
    WRITE(LISTOUT) SM   
    WRITE(LISTOUT) SICE
    WRITE(LISTOUT) Z0
    WRITE(LISTOUT) OMGALF
    WRITE(LISTOUT) ALBEDO
    WRITE(LISTOUT) ALBASE
!    WRITE(LISTOUT) MXSNAL
!    WRITE(LISTOUT) CZEN
!    WRITE(LISTOUT) CZMEAN
!    WRITE(LISTOUT) FIS
!    WRITE(LISTOUT) Q10    
!    WRITE(LISTOUT) TH10    
!    WRITE(LISTOUT) QZ0    
!    WRITE(LISTOUT) THZ0   
    WRITE(LISTOUT) U10
    WRITE(LISTOUT) V10
!    WRITE(LISTOUT) UZ0
!    WRITE(LISTOUT) VZ0
!    WRITE(LISTOUT) USTAR
!    WRITE(LISTOUT) THS
!    WRITE(LISTOUT) Q2    
!    WRITE(LISTOUT) TCUCN    
!    WRITE(LISTOUT) TRAIN    
!    WRITE(LISTOUT) DIV  
!    WRITE(LISTOUT) RTOP
! 
    CLOSE (LISTOUT)
!
    OUTFILE3 = "GEF_sw_rdtn"//C_MYPE//"."//C_NHRS
!
    OPEN (UNIT=LISTOUT, FILE= TRIM(OUTFILE3), FORM = 'UNFORMATTED')
!
!    WRITE(LISTOUT) RSWIN
!    WRITE(LISTOUT) RSWOUT
!    WRITE(LISTOUT) RSWTOA
    WRITE(LISTOUT) ASWIN
    WRITE(LISTOUT) ASWOUT
!    WRITE(LISTOUT) ASWTOA
!    WRITE(LISTOUT) RSWNET
!    WRITE(LISTOUT) RSWTT
!
    CLOSE (LISTOUT)
!
    OUTFILE4 = "GEF_lw_rdtn"//C_MYPE//"."//C_NHRS
!
    OPEN (UNIT=LISTOUT, FILE= TRIM(OUTFILE4), FORM = 'UNFORMATTED')
!
!    WRITE(LISTOUT) RLWIN
!    WRITE(LISTOUT) RLWOUT
!    WRITE(LISTOUT) RLWTOA
    WRITE(LISTOUT) ALWIN
    WRITE(LISTOUT) ALWOUT
    WRITE(LISTOUT) ALWTOA 
!    WRITE(LISTOUT) RLWNET
!    WRITE(LISTOUT) RLWTT
!    WRITE(LISTOUT) EPSR
!    WRITE(LISTOUT) RADOT   
!    WRITE(LISTOUT) SIGT4 
!    
    CLOSE (LISTOUT)
!
    OUTFILE5 = "GEF_clouds"//C_MYPE//"."//C_NHRS
!
    OPEN (UNIT=LISTOUT, FILE= TRIM(OUTFILE5), FORM = 'UNFORMATTED')
!
!    WRITE(LISTOUT) CUPPT
!    WRITE(LISTOUT) CFRACL
!    WRITE(LISTOUT) CFRACM
!    WRITE(LISTOUT) CFRACH
!    WRITE(LISTOUT) ACFRCV
!    WRITE(LISTOUT) ACFRST
!    WRITE(LISTOUT) CNVTOP
!    WRITE(LISTOUT) CNVBOT
    WRITE(LISTOUT) HTOP
    WRITE(LISTOUT) HBOT
!
    CLOSE (LISTOUT)	 
!
    OUTFILE6 = "GEF_precandsoil"//C_MYPE//"."//C_NHRS
!
    OPEN (UNIT=LISTOUT, FILE= TRIM(OUTFILE6), FORM = 'UNFORMATTED')
!
    WRITE(LISTOUT) ACPREC
    WRITE(LISTOUT) CUPREC
    WRITE(LISTOUT) APREC
    WRITE(LISTOUT) ACSNOW
!    WRITE(LISTOUT) ACSNOM
    WRITE(LISTOUT) PREC
    WRITE(LISTOUT) STC
    WRITE(LISTOUT) SMC
    WRITE(LISTOUT) SMSTAV
    WRITE(LISTOUT) BGROFF
    WRITE(LISTOUT) SSROFF
!    WRITE(LISTOUT) CMC
    WRITE(LISTOUT) POTEVP
    WRITE(LISTOUT) POTFLX
    WRITE(LISTOUT) SFCEVP
    WRITE(LISTOUT) SUBSHX
    WRITE(LISTOUT) SNOPCX
    WRITE(LISTOUT) SI
!    WRITE(LISTOUT) SNO
!    WRITE(LISTOUT) SMSTOT
!    WRITE(LISTOUT) SOILTB  
!    WRITE(LISTOUT) SR 
!    WRITE(LISTOUT) AKHS
!    WRITE(LISTOUT) AKMS
!    
    CLOSE (LISTOUT)	 
!
    ACPREC = 0.
    CUPREC = 0.
    APREC  = 0.
    ACSNOW = 0.
    ACSNOM = 0.
    PREC   = 0.
    BGROFF = 0.
    SSROFF = 0.
    POTEVP = 0.
    POTFLX = 0.
    SFCEVP = 0.
    SUBSHX = 0.
    SNOPCX = 0.
    Q2     = 0.
!
    SFCLHX = 0.
    SFCSHX = 0.
!
   
    END SUBROUTINE OUT2
