Newer
Older

WAUTELET Philippe
committed
!MNH_LIC Copyright 2002-2022 CNRS, Meteo-France and Universite Paul Sabatier
!MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence

WAUTELET Philippe
committed
!MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
!MNH_LIC for details. version 1.
!-----------------------------------------------------------------
! ###########################
MODULE MODI_WRITE_STATION_n
! ###########################
!
INTERFACE
!
SUBROUTINE WRITE_STATION_n(TPDIAFILE)

WAUTELET Philippe
committed
USE MODD_IO, ONLY: TFILEDATA
!
TYPE(TFILEDATA), INTENT(IN) :: TPDIAFILE ! diachronic file to write
!
END SUBROUTINE WRITE_STATION_n
!
END INTERFACE
!
END MODULE MODI_WRITE_STATION_n
!
! ##########################################
SUBROUTINE WRITE_STATION_n(TPDIAFILE)
! ##########################################
!
!
!!**** *WRITE_STATION* - write the balloon and aircraft trajectories and records
!! in the diachronic file
!!
!! PURPOSE
!! -------
!
!
!!** METHOD
!! ------
!!
!!
!!
!!
!!
!! EXTERNAL
!! --------
!!
!! IMPLICIT ARGUMENTS
!! ------------------
!!
!! REFERENCE
!! ---------
!!
!! AUTHOR
!! ------
!! Pierre TULET * Meteo-France *
!!
!! MODIFICATIONS
!! -------------
!! Original 15/02/2002
! P. Wautelet: 05/2016-04/2018: new data structures and calls for I/O

WAUTELET Philippe
committed
! P. Wautelet 13/09/2019: budget: simplify and modernize date/time management
! P. Wautelet 09/10/2020: Write_diachro: use new datatype tpfields

WAUTELET Philippe
committed
! P. Wautelet 03/03/2021: budgets: add tbudiachrometadata type (useful to pass more information to Write_diachro)

WAUTELET Philippe
committed
! P. Wautelet 04/02/2022: use TSVLIST to manage metadata of scalar variables
! P. Wautelet 07/04/2022: rewrite types for stations

WAUTELET Philippe
committed
! --------------------------------------------------------------------------
!
!* 0. DECLARATIONS
! ------------
!

WAUTELET Philippe
committed
USE MODD_ALLSTATION_n, ONLY: LDIAG_SURFRAD

RODIER Quentin
committed
use MODD_BUDGET, ONLY: tbudiachrometadata

WAUTELET Philippe
committed
USE MODD_CONF, ONLY: LCARTESIAN
USE MODD_CST, ONLY: XRV

WAUTELET Philippe
committed
USE MODD_IO, ONLY: TFILEDATA

WAUTELET Philippe
committed
USE MODD_NSV, ONLY: tsvlist, nsv, nsv_aer, nsv_aerbeg, nsv_aerend, &
nsv_dst, nsv_dstbeg, nsv_dstend, nsv_slt, nsv_sltbeg, nsv_sltend

WAUTELET Philippe
committed
USE MODD_PARAM_n, ONLY: CRAD, CSURF

WAUTELET Philippe
committed
USE MODD_PARAMETERS, ONLY: XUNDEF
USE MODD_STATION_n, only: NUMBSTAT, TSTATIONS
USE MODE_AERO_PSD

RODIER Quentin
committed
use MODE_WRITE_DIACHRO, ONLY: Write_diachro
!
IMPLICIT NONE
!
!
!* 0.1 declarations of arguments
!
TYPE(TFILEDATA), INTENT(IN) :: TPDIAFILE ! diachronic file to write
!
!-------------------------------------------------------------------------------
!
! 0.2 declaration of local variables
!
INTEGER :: II ! loop
!
!----------------------------------------------------------------------------
!
DO II = 1, NUMBSTAT
CALL STATION_DIACHRO_n( TSTATIONS(II) )
ENDDO
!
!----------------------------------------------------------------------------
!----------------------------------------------------------------------------
!
CONTAINS
!
!----------------------------------------------------------------------------
!----------------------------------------------------------------------------
!
!----------------------------------------------------------------------------
SUBROUTINE STATION_DIACHRO_n( TPSTATION )

WAUTELET Philippe
committed
use modd_budget, only: NLVL_CATEGORY, NLVL_SUBCATEGORY, NLVL_GROUP, NLVL_SHAPE, NLVL_TIMEAVG, NLVL_NORM, NLVL_MASK
use modd_field, only: NMNHDIM_STATION_TIME, NMNHDIM_STATION_PROC, NMNHDIM_UNUSED, &
tfieldmetadata_base, TYPEREAL
use modd_station_n, only: tstations_time
use modd_type_station, only: tstationdata
TYPE(TSTATIONDATA), INTENT(IN) :: TPSTATION
!
!* 0.2 declaration of local variables for diachro
!

WAUTELET Philippe
committed
REAL, DIMENSION(:,:,:,:,:,:), ALLOCATABLE :: ZWORK6 ! contains temporal series
REAL, DIMENSION(:,:,:,:,:,:), ALLOCATABLE :: ZW6 ! contains temporal series to write
REAL, DIMENSION(:,:,:,:), ALLOCATABLE :: ZSV, ZN0, ZSIG, ZRG
REAL, DIMENSION(:,:,:,:,:), ALLOCATABLE :: ZPTOTA
REAL, DIMENSION(:,:,:), ALLOCATABLE :: ZRHO
!
INTEGER, DIMENSION(:), ALLOCATABLE :: IGRID ! grid indicator
CHARACTER(LEN= 8) :: YGROUP ! group title
CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE :: YCOMMENT ! comment string
CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE :: YTITLE ! title
CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE :: YUNIT ! physical unit
!
!!! do not forget to increment the IPROC value if you add diagnostic !!!
INTEGER :: IPROC ! number of variables records
!!! do not forget to increment the JPROC value if you add diagnostic !!!
INTEGER :: JPROC ! loop counter
INTEGER :: JRR ! loop counter
INTEGER :: JSV ! loop counter
type(tbudiachrometadata) :: tzbudiachro
type(tfieldmetadata_base), dimension(:), allocatable :: tzfields
!
!----------------------------------------------------------------------------
IF (TPSTATION%XX==XUNDEF) RETURN
IF (TPSTATION%XY==XUNDEF) RETURN
IPROC = 8 + SIZE(TPSTATION%XR,2) + SIZE(TPSTATION%XSV,2)
IF (TPSTATION%XX==XUNDEF) IPROC = IPROC + 2
IF (SIZE(TPSTATION%XTKE )>0) IPROC = IPROC + 1

RODIER Quentin
committed
IF (LDIAG_SURFRAD) THEN

RODIER Quentin
committed
IF(CSURF=="EXTE") IPROC = IPROC + 10
IF(CRAD/="NONE") IPROC = IPROC + 7
END IF
IF (LORILAM) IPROC = IPROC + JPMODE*(3+NSOA+NCARB+NSP)
IF (LDUST) IPROC = IPROC + NMODE_DST*3
IF (ANY(TPSTATION%XTSRAD(:)/=XUNDEF)) IPROC = IPROC + 1
IF (ANY(TPSTATION%XSFCO2(:)/=XUNDEF)) IPROC = IPROC + 1
ALLOCATE (ZWORK6(1,1,1,SIZE(tstations_time%tpdates),1,IPROC))
ALLOCATE (YCOMMENT(IPROC))
ALLOCATE (YTITLE (IPROC))
ALLOCATE (YUNIT (IPROC))
ALLOCATE (IGRID (IPROC))
!
IGRID = 1
YGROUP = TPSTATION%CNAME
JPROC = 0
!
!----------------------------------------------------------------------------
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'ZS'
YUNIT (JPROC) = 'm'
YCOMMENT (JPROC) = 'Orography'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XZS
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'P'
YCOMMENT (JPROC) = 'Pressure'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XP(:)

RODIER Quentin
committed
!JPROC = JPROC + 1
!YTITLE (JPROC) = 'Z'
!YUNIT (JPROC) = 'm'
!YCOMMENT (JPROC) = 'Z Pos'
!ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XZ

RODIER Quentin
committed
IF (LCARTESIAN) THEN
JPROC = JPROC + 1
YTITLE (JPROC) = 'X'
YUNIT (JPROC) = 'm'
YCOMMENT (JPROC) = 'X Pos'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XX

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'Y'
YUNIT (JPROC) = 'm'
YCOMMENT (JPROC) = 'Y Pos'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XY

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'U'
YUNIT (JPROC) = 'm s-1'
YCOMMENT (JPROC) = 'Axial velocity'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XZON(:)

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'V'
YUNIT (JPROC) = 'm s-1'
YCOMMENT (JPROC) = 'Transversal velocity'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XMER(:)

RODIER Quentin
committed
ELSE
JPROC = JPROC + 1
YTITLE (JPROC) = 'LON'
YUNIT (JPROC) = 'degree'
YCOMMENT (JPROC) = 'Longitude'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XLON

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'LAT'
YUNIT (JPROC) = 'degree'
YCOMMENT (JPROC) = 'Latitude'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XLAT

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'ZON_WIND'
YUNIT (JPROC) = 'm s-1'
YCOMMENT (JPROC) = 'Zonal wind'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XZON(:)

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'MER_WIND'
YUNIT (JPROC) = 'm s-1'
YCOMMENT (JPROC) = 'Meridional wind'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XMER(:)

RODIER Quentin
committed
ENDIF
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'W'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'm s-1'
YCOMMENT (JPROC) = 'Air vertical speed'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XW(:)
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'Th'
YUNIT (JPROC) = 'K'
YCOMMENT (JPROC) = 'Potential temperature'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XTH(:)

RODIER Quentin
committed
IF (LDIAG_SURFRAD) THEN

RODIER Quentin
committed
IF (CSURF=="EXTE") THEN
JPROC = JPROC + 1
YTITLE (JPROC) = 'T2m'
YUNIT (JPROC) = 'K'
YCOMMENT (JPROC) = '2-m temperature'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XT2M(:)

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'Q2m'
YUNIT (JPROC) = 'kg kg-1'
YCOMMENT (JPROC) = '2-m humidity'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XQ2M(:)

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'HU2m'
YUNIT (JPROC) = 'percent'
YCOMMENT (JPROC) = '2-m relative humidity'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XHU2M(:)

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'zon10m'
YUNIT (JPROC) = 'm s-1'
YCOMMENT (JPROC) = '10-m zonal wind'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XZON10M(:)
!

RODIER Quentin
committed
JPROC = JPROC + 1
YTITLE (JPROC) = 'mer10m'
YUNIT (JPROC) = 'm s-1'
YCOMMENT (JPROC) = '10-m meridian wind'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XMER10M(:)

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'RN'

RODIER Quentin
committed
YUNIT (JPROC) = 'W m-2'
YCOMMENT (JPROC) = 'Net radiation'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XRN(:)

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'H'

RODIER Quentin
committed
YUNIT (JPROC) = 'W m-2'
YCOMMENT (JPROC) = 'Sensible heat flux'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XH(:)
!

RODIER Quentin
committed
JPROC = JPROC + 1
YTITLE (JPROC) = 'LE'

RODIER Quentin
committed
YUNIT (JPROC) = 'W m-2'
YCOMMENT (JPROC) = 'Total Latent heat flux'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XLE(:)

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'G'

RODIER Quentin
committed
YUNIT (JPROC) = 'W m-2'
YCOMMENT (JPROC) = 'Storage heat flux'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XGFLUX(:)

RODIER Quentin
committed
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'LEI'

RODIER Quentin
committed
YUNIT (JPROC) = 'W m-2'
YCOMMENT (JPROC) = 'Solid Latent heat flux'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XLEI(:)

RODIER Quentin
committed
END IF

RODIER Quentin
committed
IF (CRAD /= 'NONE') THEN
YTITLE (JPROC) = 'SWD'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'W m-2'
YCOMMENT (JPROC) = 'Downward short-wave radiation'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XSWD(:)
!

Gaelle DELAUTIER
committed
JPROC = JPROC + 1
YTITLE (JPROC) = 'SWU'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'W m-2'
YCOMMENT (JPROC) = 'Upward short-wave radiation'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XSWU(:)
!

Gaelle DELAUTIER
committed
JPROC = JPROC + 1
YTITLE (JPROC) = 'LWD'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'W m-2'

Gaelle DELAUTIER
committed
YCOMMENT (JPROC) = 'Downward long-wave radiation'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XLWD(:)
!

Gaelle DELAUTIER
committed
JPROC = JPROC + 1
YTITLE (JPROC) = 'LWU'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'W m-2'

Gaelle DELAUTIER
committed
YCOMMENT (JPROC) = 'Upward long-wave radiation'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XLWU(:)
JPROC = JPROC + 1

Gaelle DELAUTIER
committed
!
YTITLE (JPROC) = 'SWDIR'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'W m-2'
YCOMMENT (JPROC) = 'Downward direct short-wave radiation'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XSWDIR(:)
!
JPROC = JPROC + 1
YTITLE (JPROC) = 'SWDIFF'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'W m-2'
YCOMMENT (JPROC) = 'Downward diffuse short-wave radiation'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XSWDIFF(:)
!
YTITLE (JPROC) = 'DSTAOD'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'm'
YCOMMENT (JPROC) = 'Dust aerosol optical depth'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XDSTAOD(:)

RODIER Quentin
committed
END IF
DO JRR=1,SIZE(TPSTATION%XR,2)

WAUTELET Philippe
committed
YUNIT (JPROC) = 'kg kg-1'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XR(:,JRR)
IF (JRR==1) THEN
YTITLE (JPROC) = 'Rv'
YCOMMENT (JPROC) = 'Water vapor mixing ratio'
ELSE IF (JRR==2) THEN
YTITLE (JPROC) = 'Rc'
YCOMMENT (JPROC) = 'Liquid cloud water mixing ratio'
ELSE IF (JRR==3) THEN
YTITLE (JPROC) = 'Rr'
YCOMMENT (JPROC) = 'Rain water mixing ratio'
ELSE IF (JRR==4) THEN
YTITLE (JPROC) = 'Ri'
YCOMMENT (JPROC) = 'Ice cloud water mixing ratio'
ELSE IF (JRR==5) THEN
YTITLE (JPROC) = 'Rs'
YCOMMENT (JPROC) = 'Snow mixing ratio'
ELSE IF (JRR==6) THEN
YTITLE (JPROC) = 'Rg'
YCOMMENT (JPROC) = 'Graupel mixing ratio'
ELSE IF (JRR==7) THEN
YTITLE (JPROC) = 'Rh'
YCOMMENT (JPROC) = 'Hail mixing ratio'
IF (SIZE(TPSTATION%XTKE,1)>0) THEN
JPROC = JPROC+1
YTITLE (JPROC) = 'Tke'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'm2 s-2'
YCOMMENT (JPROC) = 'Turbulent kinetic energy'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XTKE(:)
IF (SIZE(TPSTATION%XSV,2)>=1) THEN

WAUTELET Philippe
committed
! Scalar variables
DO JSV = 1, NSV
JPROC = JPROC + 1
YTITLE(JPROC) = TRIM( TSVLIST(JSV)%CMNHNAME )
YCOMMENT(JPROC) = ''
IF ( TRIM( TSVLIST(JSV)%CUNITS ) == 'ppv' ) THEN
YUNIT(JPROC) = 'ppb'
ZWORK6(1,1,1,:,1,JPROC) = TPSTATION%XSV(:,JSV) * 1.e9 !*1e9 for conversion ppv->ppb

WAUTELET Philippe
committed
ELSE
YUNIT(JPROC) = TRIM( TSVLIST(JSV)%CUNITS )
ZWORK6(1,1,1,:,1,JPROC) = TPSTATION%XSV(:,JSV)

WAUTELET Philippe
committed
END IF
IF ((LORILAM).AND. .NOT.(ANY(TPSTATION%XP(:) == 0.))) THEN
ALLOCATE (ZSV(1,1,SIZE(tstations_time%tpdates),NSV_AER))
ALLOCATE (ZRHO(1,1,SIZE(tstations_time%tpdates)))
ALLOCATE (ZN0(1,1,SIZE(tstations_time%tpdates),JPMODE))
ALLOCATE (ZRG(1,1,SIZE(tstations_time%tpdates),JPMODE))
ALLOCATE (ZSIG(1,1,SIZE(tstations_time%tpdates),JPMODE))
ALLOCATE (ZPTOTA(1,1,SIZE(tstations_time%tpdates),NSP+NCARB+NSOA,JPMODE))
ZSV(1,1,:,1:NSV_AER) = TPSTATION%XSV(:,NSV_AERBEG:NSV_AEREND)
IF (SIZE(TPSTATION%XR,2) >0) THEN
DO JRR=1,SIZE(TPSTATION%XR,2)
ZRHO(1,1,:) = ZRHO(1,1,:) + TPSTATION%XR(:,JRR)
ZRHO(1,1,:) = TPSTATION%XTH(:) * ( 1. + XRV/XRD*TPSTATION%XR(:,1) ) &

WAUTELET Philippe
committed
/ ( 1. + ZRHO(1,1,:) )
ZRHO(1,1,:) = TPSTATION%XTH(:)
ZRHO(1,1,:) = TPSTATION%XP(:) / &
(XRD *ZRHO(1,1,:) *((TPSTATION%XP(:)/XP00)**(XRD/XCPD)) )

WAUTELET Philippe
committed
CALL PPP2AERO(ZSV,ZRHO, PSIG3D=ZSIG, PRG3D=ZRG, PN3D=ZN0,PCTOTA=ZPTOTA)
DO JSV=1,JPMODE
! mean radius
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A6,I1)')'AERRGA',JSV
YUNIT (JPROC) = 'um'

WAUTELET Philippe
committed
WRITE(YCOMMENT(JPROC),'(A18,I1)')'RG (nb) AERO MODE ',JSV
ZWORK6 (1,1,1,:,1,JPROC) = ZRG(1,1,:,JSV)
! standard deviation
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A7,I1)')'AERSIGA',JSV
YUNIT (JPROC) = ' '
WRITE(YCOMMENT(JPROC),'(A16,I1)')'SIGMA AERO MODE ',JSV
ZWORK6 (1,1,1,:,1,JPROC) = ZSIG(1,1,:,JSV)
! particles number
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A6,I1)')'AERN0A',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'm-3'
WRITE(YCOMMENT(JPROC),'(A13,I1)')'N0 AERO MODE ',JSV
ZWORK6 (1,1,1,:,1,JPROC) = ZN0(1,1,:,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MOC ',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS OC AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_OC,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MBC ',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS BC AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_BC,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MDST ',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS DST AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_DST,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSO4 ',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SO4 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SO4,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MNO3 ',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS NO3 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_NO3,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MH2O ',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS H2O AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_H2O,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MNH3 ',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS NH3 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_NH3,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSOA1',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SOA1 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA1,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSOA2',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SOA2 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA2,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSOA3',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SOA3 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA3,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSOA4',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SOA4 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA4,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSOA5',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SOA5 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA5,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSOA6',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SOA6 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA6,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSOA7',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SOA7 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA7,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSOA8',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SOA8 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA8,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A5,I1)')'MSOA9',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A23,I1)')'MASS SOA9 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA9,JSV)
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A6,I1)')'MSOA10',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'ug m-3'
WRITE(YCOMMENT,'(A24,I1)')'MASS SOA10 AEROSOL MODE ',JSV
ZWORK6(1,1,1,:,1,JPROC)=ZPTOTA(1,1,:,JP_AER_SOA10,JSV)

WAUTELET Philippe
committed
ENDDO

WAUTELET Philippe
committed
DEALLOCATE (ZSV,ZRHO)
DEALLOCATE (ZN0,ZRG,ZSIG)

WAUTELET Philippe
committed
IF ((LDUST).AND. .NOT.(ANY(TPSTATION%XP(:) == 0.))) THEN
ALLOCATE (ZSV(1,1,SIZE(tstations_time%tpdates),NSV_DST))
ALLOCATE (ZRHO(1,1,SIZE(tstations_time%tpdates)))
ALLOCATE (ZN0(1,1,SIZE(tstations_time%tpdates),NMODE_DST))
ALLOCATE (ZRG(1,1,SIZE(tstations_time%tpdates),NMODE_DST))
ALLOCATE (ZSIG(1,1,SIZE(tstations_time%tpdates),NMODE_DST))
ZSV(1,1,:,1:NSV_DST) = TPSTATION%XSV(:,NSV_DSTBEG:NSV_DSTEND)
IF (SIZE(TPSTATION%XR,2) >0) THEN
DO JRR=1,SIZE(TPSTATION%XR,2)
ZRHO(1,1,:) = ZRHO(1,1,:) + TPSTATION%XR(:,JRR)
ZRHO(1,1,:) = TPSTATION%XTH(:) * ( 1. + XRV/XRD*TPSTATION%XR(:,1) ) &

WAUTELET Philippe
committed
/ ( 1. + ZRHO(1,1,:) )
ZRHO(1,1,:) = TPSTATION%XTH(:)
ZRHO(1,1,:) = TPSTATION%XP(:) / &
(XRD *ZRHO(1,1,:) *((TPSTATION%XP(:)/XP00)**(XRD/XCPD)) )
CALL PPP2DUST(ZSV,ZRHO, PSIG3D=ZSIG, PRG3D=ZRG, PN3D=ZN0)
DO JSV=1,NMODE_DST
! mean radius
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A6,I1)')'DSTRGA',JSV
YUNIT (JPROC) = 'um'

WAUTELET Philippe
committed
WRITE(YCOMMENT(JPROC),'(A18,I1)')'RG (nb) DUST MODE ',JSV
ZWORK6 (1,1,1,:,1,JPROC) = ZRG(1,1,:,JSV)
! standard deviation
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A7,I1)')'DSTSIGA',JSV
YUNIT (JPROC) = ' '
WRITE(YCOMMENT(JPROC),'(A16,I1)')'SIGMA DUST MODE ',JSV
ZWORK6 (1,1,1,:,1,JPROC) = ZSIG(1,1,:,JSV)
! particles number
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A6,I1)')'DSTN0A',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'm-3'
WRITE(YCOMMENT(JPROC),'(A13,I1)')'N0 DUST MODE ',JSV
ZWORK6 (1,1,1,:,1,JPROC) = ZN0(1,1,:,JSV)
ENDDO

WAUTELET Philippe
committed
DEALLOCATE (ZSV,ZRHO)
DEALLOCATE (ZN0,ZRG,ZSIG)

WAUTELET Philippe
committed
IF ((LSALT).AND. .NOT.(ANY(TPSTATION%XP(:) == 0.))) THEN
ALLOCATE (ZSV(1,1,SIZE(tstations_time%tpdates),NSV_SLT))
ALLOCATE (ZRHO(1,1,SIZE(tstations_time%tpdates)))
ALLOCATE (ZN0(1,1,SIZE(tstations_time%tpdates),NMODE_SLT))
ALLOCATE (ZRG(1,1,SIZE(tstations_time%tpdates),NMODE_SLT))
ALLOCATE (ZSIG(1,1,SIZE(tstations_time%tpdates),NMODE_SLT))
ZSV(1,1,:,1:NSV_SLT) = TPSTATION%XSV(:,NSV_SLTBEG:NSV_SLTEND)
IF (SIZE(TPSTATION%XR,2) >0) THEN
DO JRR=1,SIZE(TPSTATION%XR,2)
ZRHO(1,1,:) = ZRHO(1,1,:) + TPSTATION%XR(:,JRR)
ZRHO(1,1,:) = TPSTATION%XTH(:) * ( 1. + XRV/XRD*TPSTATION%XR(:,1) ) &
/ ( 1. + ZRHO(1,1,:) )
ZRHO(1,1,:) = TPSTATION%XTH(:)
ZRHO(1,1,:) = TPSTATION%XP(:) / &
(XRD *ZRHO(1,1,:) *((TPSTATION%XP(:)/XP00)**(XRD/XCPD)) )
CALL PPP2SALT(ZSV,ZRHO, PSIG3D=ZSIG, PRG3D=ZRG, PN3D=ZN0)
DO JSV=1,NMODE_SLT
! mean radius
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A6,I1)')'SLTRGA',JSV
YUNIT (JPROC) = 'um'

WAUTELET Philippe
committed
WRITE(YCOMMENT(JPROC),'(A18,I1)')'RG (nb) SALT MODE ',JSV
ZWORK6 (1,1,1,:,1,JPROC) = ZRG(1,1,:,JSV)
! standard deviation
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A7,I1)')'SLTSIGA',JSV
YUNIT (JPROC) = ' '
WRITE(YCOMMENT(JPROC),'(A16,I1)')'SIGMA DUST MODE ',JSV
ZWORK6 (1,1,1,:,1,JPROC) = ZSIG(1,1,:,JSV)
! particles number
JPROC = JPROC+1
WRITE(YTITLE(JPROC),'(A6,I1)')'SLTN0A',JSV

WAUTELET Philippe
committed
YUNIT (JPROC) = 'm-3'
WRITE(YCOMMENT(JPROC),'(A13,I1)')'N0 DUST MODE ',JSV
ZWORK6 (1,1,1,:,1,JPROC) = ZN0(1,1,:,JSV)
ENDDO
DEALLOCATE (ZSV,ZRHO)
DEALLOCATE (ZN0,ZRG,ZSIG)

WAUTELET Philippe
committed
END IF
IF (ANY(TPSTATION%XTSRAD(:)/=XUNDEF)) THEN
JPROC = JPROC+1
YTITLE (JPROC) = 'Tsrad'
YUNIT (JPROC) = 'K'
YCOMMENT (JPROC) = 'Radiative Surface Temperature'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XTSRAD(:)
IF (ANY(TPSTATION%XSFCO2(:)/=XUNDEF)) THEN
JPROC = JPROC+1
YTITLE (JPROC) = 'SFCO2'

WAUTELET Philippe
committed
YUNIT (JPROC) = 'mg m-2 s-1'
YCOMMENT (JPROC) = 'CO2 Surface Flux'
ZWORK6 (1,1,1,:,1,JPROC) = TPSTATION%XSFCO2(:)
!----------------------------------------------------------------------------
!
!
ALLOCATE (ZW6(1,1,1,SIZE(tstations_time%tpdates),1,JPROC))
ZW6 = ZWORK6(:,:,:,:,:,:JPROC)
DEALLOCATE(ZWORK6)
!
allocate( tzfields( jproc ) )
tzfields(:)%cmnhname = ytitle(1 : jproc)
tzfields(:)%cstdname = ''
tzfields(:)%clongname = ytitle(1 : jproc)
tzfields(:)%cunits = yunit(1 : jproc)
tzfields(:)%ccomment = ycomment(1 : jproc)
tzfields(:)%ngrid = 0
tzfields(:)%ntype = TYPEREAL
tzfields(:)%ndims = 2
tzfields(:)%ndimlist(1) = NMNHDIM_UNUSED
tzfields(:)%ndimlist(2) = NMNHDIM_UNUSED
tzfields(:)%ndimlist(3) = NMNHDIM_UNUSED
tzfields(:)%ndimlist(4) = NMNHDIM_STATION_TIME
tzfields(:)%ndimlist(5) = NMNHDIM_UNUSED
tzfields(:)%ndimlist(6) = NMNHDIM_STATION_PROC

WAUTELET Philippe
committed
tzbudiachro%lleveluse(NLVL_CATEGORY) = .true.
tzbudiachro%clevels (NLVL_CATEGORY) = 'Stations'
tzbudiachro%ccomments(NLVL_CATEGORY) = 'Level for the different stations'
tzbudiachro%lleveluse(NLVL_SUBCATEGORY) = .false.
tzbudiachro%clevels (NLVL_SUBCATEGORY) = ''
tzbudiachro%ccomments(NLVL_SUBCATEGORY) = ''
tzbudiachro%lleveluse(NLVL_GROUP) = .true.
tzbudiachro%clevels (NLVL_GROUP) = ygroup
tzbudiachro%ccomments(NLVL_GROUP) = 'Values at position of station ' // Trim( ygroup )
tzbudiachro%lleveluse(NLVL_SHAPE) = .false.
tzbudiachro%clevels (NLVL_SHAPE) = 'Point'
tzbudiachro%ccomments(NLVL_SHAPE) = 'Values at position of station ' // Trim( ygroup )
tzbudiachro%lleveluse(NLVL_TIMEAVG) = .false.

WAUTELET Philippe
committed
tzbudiachro%clevels (NLVL_TIMEAVG) = 'Not_time_averaged'

WAUTELET Philippe
committed
tzbudiachro%ccomments(NLVL_TIMEAVG) = 'Values are not time averaged'
tzbudiachro%lleveluse(NLVL_NORM) = .false.

WAUTELET Philippe
committed
tzbudiachro%clevels (NLVL_NORM) = 'Not_normalized'

WAUTELET Philippe
committed
tzbudiachro%ccomments(NLVL_NORM) = 'Values are not normalized'
tzbudiachro%lleveluse(NLVL_MASK) = .false.
tzbudiachro%clevels (NLVL_MASK) = ''
tzbudiachro%ccomments(NLVL_MASK) = ''

WAUTELET Philippe
committed
tzbudiachro%lmobile = .false.

WAUTELET Philippe
committed
!Compression does not make sense here
!Keep these values for backward compatibility of LFI files

WAUTELET Philippe
committed
tzbudiachro%licompress = .true.
tzbudiachro%ljcompress = .true.
tzbudiachro%lkcompress = .false.
tzbudiachro%ltcompress = .false.
tzbudiachro%lnorm = .false.

WAUTELET Philippe
committed
!Boundaries in physical domain does not make sense here
!These values are not written in the netCDF files
!These values are written in the LFI files. Kept for backward compatibility of LFI files

WAUTELET Philippe
committed
tzbudiachro%nil = 1
tzbudiachro%nih = 1
tzbudiachro%njl = 1
tzbudiachro%njh = 1
tzbudiachro%nkl = 1
tzbudiachro%nkh = 1
call Write_diachro( tpdiafile, tzbudiachro, tzfields, tstations_time%tpdates, zw6 )
deallocate( tzfields )
DEALLOCATE (ZW6)
DEALLOCATE (YCOMMENT)
DEALLOCATE (YTITLE )
DEALLOCATE (YUNIT )
DEALLOCATE (IGRID )
!----------------------------------------------------------------------------
END SUBROUTINE STATION_DIACHRO_n
!----------------------------------------------------------------------------
!----------------------------------------------------------------------------
!
END SUBROUTINE WRITE_STATION_n