SUBROUTINE WRTCFOU

!**** *WRTCFOU*   - WRITES FOURIER COEFFICIENTS OF TRANSMISSION COEFFICIENTS
!                   ON A LFI FILE. DISTRIBUTED MEMORY CODE.

!     Purpose.
!     --------

!**   Interface.
!     ----------
!        *CALL* *WRTCFOU(.....)*

!        Explicit arguments :
!        --------------------
!        none

!        Implicit arguments :
!        --------------------

!     Externals.
!     ----------
!       Calls some LFI routines.
!       Calls DIWRFOU.
!       Calls FOUTCNORM.

!     Reference.
!     ----------

!     Author.
!     -------
!        K. YESSAD (CNRM/GMAP). 

!     Modifications.
!     --------------
!        Original : FEB 1999
!        Modified by G> Radnoti 99/11/07  ALADIN geometry
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMCT0   , ONLY : LRFOUTCNORM, LRPLANE 
USE YOMDIM   , ONLY : NTCMAX   ,NDGLG    ,NFLEVG   ,NDGUNG   ,&
 & NDGUXG  
USE YOMFOUTC , ONLY : RFORAB3C ,RFORAB4C ,RFORAB6C ,RFORAB3N ,&
 & RFORAB4N ,RFORAB6N ,RFORAT1C ,RFORAT2C ,RFORAT3C ,&
 & RFORAT4C ,RFORAT5C ,RFORAT1N ,RFORAT2N ,RFORAT3N ,&
 & RFORAT4N ,RFORAT5N ,RFOCOR   ,RFOAC  
USE YOMLUN   , ONLY : NTCSR    ,NULOUT
USE YOMMP    , ONLY : MYSETA   ,MYPROC   ,NFRSTLAT ,NLSTLAT ,NGPSET2PE
USE YOMTAG   , ONLY : MTAGDISTFO

IMPLICIT NONE

INTEGER(KIND=JPIM) :: IDGLG
INTEGER(KIND=JPIM) :: IDIMG
INTEGER(KIND=JPIM) :: IDIML
INTEGER(KIND=JPIM) :: IFACTFOUTC
INTEGER(KIND=JPIM) :: IFLEVG
INTEGER(KIND=JPIM) :: IFRSTLAT
INTEGER(KIND=JPIM) :: IGLN
INTEGER(KIND=JPIM) :: IGLX
INTEGER(KIND=JPIM) :: IIOPROC
INTEGER(KIND=JPIM) :: ILEN
INTEGER(KIND=JPIM) :: ILENAC
INTEGER(KIND=JPIM) :: ILSTLAT
INTEGER(KIND=JPIM) :: INAR
INTEGER(KIND=JPIM) :: INARFIELDS
INTEGER(KIND=JPIM) :: INARFRAME
INTEGER(KIND=JPIM) :: INARI
INTEGER(KIND=JPIM) :: INDGLL
INTEGER(KIND=JPIM) :: INIMES
INTEGER(KIND=JPIM) :: INUMF
INTEGER(KIND=JPIM) :: IREP
INTEGER(KIND=JPIM) :: IRP

LOGICAL :: LLFOUTCNORM
LOGICAL :: LLIMST
LOGICAL :: LLIOPROC

REAL(KIND=JPRB) :: ZFORAB3CG(NFLEVG,0:2*NTCMAX,NDGLG) 
REAL(KIND=JPRB) :: ZFORAB4CG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAB6CG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAB3NG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAB4NG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAB6NG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT1CG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT2CG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT3CG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT4CG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT5CG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT1NG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT2NG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT3NG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT4NG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFORAT5NG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFOCORG(NFLEVG,0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFOACG((NFLEVG+1)*(NFLEVG+1),0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZFOTC(17*NFLEVG+(NFLEVG+1)*(NFLEVG+1),0:2*NTCMAX,NDGLG)
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "diwrfou.intfb.h"
#include "foutcnorm.intfb.h"

! ------------------------------------------------------------------

! 1/ Preliminary initialisations:

IF (LHOOK) CALL DR_HOOK('WRTCFOU',0,ZHOOK_HANDLE)
IRP=0
INARI=0
IF (LRPLANE) THEN
  INARFRAME=5
ELSE
  INARFRAME=3
ENDIF
INARFIELDS=18
INAR=INARFRAME+INARFIELDS
IFACTFOUTC=1
LLIMST=.FALSE.
INIMES=1
IIOPROC=NGPSET2PE(1,1)
LLIOPROC=(IIOPROC == MYPROC)
ILSTLAT=MIN(NLSTLAT(MYSETA),NDGUXG)
IFRSTLAT=MAX(NFRSTLAT(MYSETA),NDGUNG)
INDGLL=ILSTLAT+1-IFRSTLAT   
IDIML=(17*NFLEVG+(NFLEVG+1)*(NFLEVG+1))*(2*NTCMAX+1)*INDGLL
IDIMG=(17*NFLEVG+(NFLEVG+1)*(NFLEVG+1))*(2*NTCMAX+1)*NDGLG

! ------------------------------------------------------------------

! 2/ Opens file:

IF (LLIOPROC) THEN
  CALL LFIAFM(IRP,NTCSR,IFACTFOUTC)
  CALL LFIOUV(IRP,NTCSR,.TRUE.,'FOUTC','NEW',.TRUE.,LLIMST,INIMES,INAR,INARI)
ENDIF

! ------------------------------------------------------------------

! 3/ Writes frame:

IF (LLIOPROC) THEN
  CALL LFIINTECR(IRP,NTCSR,'NTCMAX',NTCMAX,1)
  CALL LFIINTECR(IRP,NTCSR,'NDGLG',NDGLG,1)
  CALL LFIINTECR(IRP,NTCSR,'NFLEVG',NFLEVG,1)
  IF (LRPLANE) THEN
    CALL LFIINTECR(IRP,NTCSR,'NDGUNG',NDGUNG,1)
    CALL LFIINTECR(IRP,NTCSR,'NDGUXG',NDGUXG,1)
  ENDIF
ENDIF

! ------------------------------------------------------------------

! 4/ Memory transfer before processor communications:

INUMF=0
ZFOTC=0.0_JPRB

! * clear-sky parallel/diffuse reflectivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAB3C(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * clear-sky diffuse transmissivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAB4C(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * clear-sky diffuse reflectivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAB6C(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * cloudy parallel/diffuse reflectivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAB3N(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * cloudy diffuse transmissivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAB4N(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * cloudy diffuse reflectivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAB6N(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * clear-sky parallel transmissivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT1C(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * clear-sky parallel/diffuse transmissivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT2C(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * clear-sky parallel/diffuse reflectivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT3C(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * clear-sky diffuse transmissivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT4C(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * clear-sky diffuse reflectivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT5C(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * cloudy parallel transmissivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT1N(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * cloudy parallel/diffuse transmissivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT2N(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * cloudy parallel/diffuse reflectivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT3N(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * cloudy diffuse transmissivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT4N(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * cloudy diffuse reflectivity.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFORAT5N(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * correction for cloudiness for thermal radiation.
ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFOCOR(1:NFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+NFLEVG

! * Curtis matrix for thermal radiation for clear sky.
IFLEVG=(NFLEVG+1)*(NFLEVG+1)
ZFOTC(INUMF+1:INUMF+IFLEVG,0:2*NTCMAX,1:INDGLL)= &
 & RFOAC(1:IFLEVG,0:2*NTCMAX,1:INDGLL)  
INUMF=INUMF+(NFLEVG+1)*(NFLEVG+1)

! ------------------------------------------------------------------

! 5/ Processor communications:

! * All procs other than IIOPROC send data towards IIOPROC.
CALL DIWRFOU(NTCMAX,INDGLL,NDGLG,NDGLG,INUMF,0,MTAGDISTFO,0,IIOPROC,IDIML,ZFOTC)

! * Proc IIOPROC receives data from the other procs.
IF (LLIOPROC) THEN
  IF (LRPLANE) THEN
    IDGLG=(NDGUXG-NDGUNG+1) 
  ELSE
    IDGLG=NDGLG
  ENDIF
  CALL DIWRFOU(NTCMAX,INDGLL,IDGLG,NDGLG,INUMF,1,&
   & MTAGDISTFO,0,IIOPROC,IDIMG,ZFOTC)  
ENDIF

! ------------------------------------------------------------------

! 6/ Memory transfer after processor communications:

IF (LLIOPROC) THEN

  INUMF=0

! * clear-sky parallel/diffuse reflectivity.
  ZFORAB3CG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * clear-sky diffuse transmissivity.
  ZFORAB4CG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * clear-sky diffuse reflectivity.
  ZFORAB6CG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * cloudy parallel/diffuse reflectivity.
  ZFORAB3NG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * cloudy diffuse transmissivity.
  ZFORAB4NG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * cloudy diffuse reflectivity.
  ZFORAB6NG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * clear-sky parallel transmissivity.
  ZFORAT1CG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * clear-sky parallel/diffuse transmissivity.
  ZFORAT2CG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * clear-sky parallel/diffuse reflectivity.
  ZFORAT3CG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * clear-sky diffuse transmissivity.
  ZFORAT4CG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * clear-sky diffuse reflectivity.
  ZFORAT5CG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * cloudy parallel transmissivity.
  ZFORAT1NG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * cloudy parallel/diffuse transmissivity.
  ZFORAT2NG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * cloudy parallel/diffuse reflectivity.
  ZFORAT3NG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * cloudy diffuse transmissivity.
  ZFORAT4NG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * cloudy diffuse reflectivity.
  ZFORAT5NG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * correction for cloudiness for thermal radiation.
  ZFOCORG(1:NFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+NFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+NFLEVG

! * Curtis matrix for thermal radiation for clear sky.
  IFLEVG=(NFLEVG+1)*(NFLEVG+1)
  ZFOACG(1:IFLEVG,0:2*NTCMAX,1:NDGLG)= &
   & ZFOTC(INUMF+1:INUMF+IFLEVG,0:2*NTCMAX,1:NDGLG)  
  INUMF=INUMF+(NFLEVG+1)*(NFLEVG+1)

ENDIF

! ------------------------------------------------------------------

! 7/ Writes fields:

IF (LLIOPROC) THEN

  IGLN=MAX(1,NDGUNG)
  IGLX=MIN(NDGLG,NDGUXG)
  ILEN=(IGLX-IGLN+1)*(1+2*NTCMAX)*NFLEVG
  ILENAC=(IGLX-IGLN+1)*(1+2*NTCMAX)*(NFLEVG+1)*(NFLEVG+1)
  IREP=0

! * clear-sky parallel/diffuse reflectivity.
  CALL LFIECR(IREP,NTCSR,'RAB3C',ZFORAB3CG(1,0,IGLN),ILEN)

! * clear-sky diffuse transmissivity.
  CALL LFIECR(IREP,NTCSR,'RAB4C',ZFORAB4CG(1,0,IGLN),ILEN)

! * clear-sky diffuse reflectivity.
  CALL LFIECR(IREP,NTCSR,'RAB6C',ZFORAB6CG(1,0,IGLN),ILEN)

! * cloudy parallel/diffuse reflectivity.
  CALL LFIECR(IREP,NTCSR,'RAB3N',ZFORAB3NG(1,0,IGLN),ILEN)

! * cloudy diffuse transmissivity.
  CALL LFIECR(IREP,NTCSR,'RAB4N',ZFORAB4NG(1,0,IGLN),ILEN)

! * cloudy diffuse reflectivity.
  CALL LFIECR(IREP,NTCSR,'RAB6N',ZFORAB6NG(1,0,IGLN),ILEN)

! * clear-sky parallel transmissivity.
  CALL LFIECR(IREP,NTCSR,'RAT1C',ZFORAT1CG(1,0,IGLN),ILEN)

! * clear-sky parallel/diffuse transmissivity.
  CALL LFIECR(IREP,NTCSR,'RAT2C',ZFORAT2CG(1,0,IGLN),ILEN)

! * clear-sky parallel/diffuse reflectivity.
  CALL LFIECR(IREP,NTCSR,'RAT3C',ZFORAT3CG(1,0,IGLN),ILEN)

! * clear-sky diffuse transmissivity.
  CALL LFIECR(IREP,NTCSR,'RAT4C',ZFORAT4CG(1,0,IGLN),ILEN)

! * clear-sky diffuse reflectivity.
  CALL LFIECR(IREP,NTCSR,'RAT5C',ZFORAT5CG(1,0,IGLN),ILEN)

! * cloudy parallel transmissivity.
  CALL LFIECR(IREP,NTCSR,'RAT1N',ZFORAT1NG(1,0,IGLN),ILEN)

! * cloudy parallel/diffuse transmissivity.
  CALL LFIECR(IREP,NTCSR,'RAT2N',ZFORAT2NG(1,0,IGLN),ILEN)

! * cloudy parallel/diffuse reflectivity.
  CALL LFIECR(IREP,NTCSR,'RAT3N',ZFORAT3NG(1,0,IGLN),ILEN)

! * cloudy diffuse transmissivity.
  CALL LFIECR(IREP,NTCSR,'RAT4N',ZFORAT4NG(1,0,IGLN),ILEN)

! * cloudy diffuse reflectivity.
  CALL LFIECR(IREP,NTCSR,'RAT5N',ZFORAT5NG(1,0,IGLN),ILEN)

! * correction for cloudiness for thermal radiation.
  CALL LFIECR(IREP,NTCSR,'COR',ZFOCORG(1,0,IGLN),ILEN)

! * Curtis matrix for thermal radiation for clear sky.
  CALL LFIECR(IREP,NTCSR,'AC',ZFOACG(1,0,IGLN),ILENAC)

ENDIF

! ------------------------------------------------------------------

! 8/ Closes file:

IF (LLIOPROC) CALL LFIFER(IRP,NTCSR,'KEEP')

! ------------------------------------------------------------------

! 9/ Statistics:

LLFOUTCNORM=LRFOUTCNORM(1).OR.LRFOUTCNORM(2).OR. &
 & LRFOUTCNORM(3).OR.LRFOUTCNORM(4)  

IF (LLIOPROC.AND.LLFOUTCNORM) THEN

  IGLN=MAX(1,NDGUNG)
  IGLX=MIN(NDGLG,NDGUXG)

! * clear-sky parallel/diffuse reflectivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAB3C',ZFORAB3CG(1,0,IGLN))

! * clear-sky diffuse transmissivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAB4C',ZFORAB4CG(1,0,IGLN))

! * clear-sky diffuse reflectivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAB6C',ZFORAB6CG(1,0,IGLN))

! * cloudy parallel/diffuse reflectivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAB3N',ZFORAB3NG(1,0,IGLN))

! * cloudy diffuse transmissivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAB4N',ZFORAB4NG(1,0,IGLN))

! * cloudy diffuse reflectivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAB6N',ZFORAB6NG(1,0,IGLN))

! * clear-sky parallel transmissivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT1C',ZFORAT1CG(1,0,IGLN))

! * clear-sky parallel/diffuse transmissivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT2C',ZFORAT2CG(1,0,IGLN))

! * clear-sky parallel/diffuse reflectivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT3C',ZFORAT3CG(1,0,IGLN))

! * clear-sky diffuse transmissivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT4C',ZFORAT4CG(1,0,IGLN))

! * clear-sky diffuse reflectivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT5C',ZFORAT5CG(1,0,IGLN))

! * cloudy parallel transmissivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT1N',ZFORAT1NG(1,0,IGLN))

! * cloudy parallel/diffuse transmissivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT2N',ZFORAT2NG(1,0,IGLN))

! * cloudy parallel/diffuse reflectivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT3N',ZFORAT3NG(1,0,IGLN))

! * cloudy diffuse transmissivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT4N',ZFORAT4NG(1,0,IGLN))

! * cloudy diffuse reflectivity.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'RAT5N',ZFORAT5NG(1,0,IGLN))

! * correction for cloudiness for thermal radiation.
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,NFLEVG,IGLX-IGLN+1,NTCMAX,'COR  ',ZFOCORG(1,0,IGLN))

! * Curtis matrix for thermal radiation for clear sky.
  IFLEVG=(NFLEVG+1)*(NFLEVG+1)
  CALL FOUTCNORM(LRFOUTCNORM,NULOUT,IFLEVG,IGLX-IGLN+1,NTCMAX,'AC   ',ZFOACG(1,0,IGLN))

ENDIF

! ------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('WRTCFOU',1,ZHOOK_HANDLE)
END SUBROUTINE WRTCFOU
