Newer
Older
!MNH_LIC Copyright 2020-2023 CNRS, Meteo-France and Universite Paul Sabatier

RODIER Quentin
committed
!MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
!MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt

RODIER Quentin
committed
!MNH_LIC for details. version 1.
!-----------------------------------------------------------------
! ############################
MODULE MODE_STATPROF_READER
! ############################

WAUTELET Philippe
committed
IMPLICIT NONE
PRIVATE

WAUTELET Philippe
committed
PUBLIC :: STATPROF_CSV_READ

WAUTELET Philippe
committed
INTEGER, PARAMETER :: NMAXLINELGT = 400
CONTAINS

RODIER Quentin
committed
!-------------------------------------------------------------------
!

WAUTELET Philippe
committed
!!**** *STATPROF_CSV_READ* -

RODIER Quentin
committed
!!
!! PURPOSE
!! -------
!! Prescribe probes through a CSV file
!!
!! AUTHOR
!! ------
!! E. Jezequel *CNRM & IFPEN*

RODIER Quentin
committed
!!
!! MODIFICATIONS
!! -------------
!! 03/2020 Original

WAUTELET Philippe
committed
! P. Wautelet 04/2022: restructure stations/profilers for better performance, reduce memory usage and correct some problems/bugs
!---------------------------------------------------------------

RODIER Quentin
committed
!
!###############################################################
SUBROUTINE STATPROF_CSV_READ( TPSTATPROF, HFILE, KNUMBSTATPROF )
!###############################################################

RODIER Quentin
committed

WAUTELET Philippe
committed
USE MODD_CONF, ONLY: LCARTESIAN

WAUTELET Philippe
committed
USE MODD_TYPE_STATPROF, ONLY: TPROFILERDATA, TSTATIONDATA, TSTATPROFDATA

WAUTELET Philippe
committed
USE MODE_MSG

WAUTELET Philippe
committed
USE MODE_STATPROF_TOOLS, ONLY: PROFILER_ADD, STATION_ADD, STATPROF_INI_INTERP, STATPROF_POSITION
CLASS(TSTATPROFDATA), INTENT(IN) :: TPSTATPROF ! Used only to identify datatype
CHARACTER(LEN=*), INTENT(IN) :: HFILE ! file to read
INTEGER, INTENT(OUT) :: KNUMBSTATPROF ! Total number of stations/profilers (inside physical domain of model)

RODIER Quentin
committed
!

WAUTELET Philippe
committed
CHARACTER(LEN=NMAXLINELGT) :: YSTRING

WAUTELET Philippe
committed
INTEGER :: ILU ! logical unit of the file
INTEGER :: INBLINE ! Nb of lines in csv file
LOGICAL :: GINSIDE ! True if station/profiler is inside physical domain of model
LOGICAL :: GPRESENT ! True if station/profiler is present on the current process
TYPE(TSTATIONDATA), TARGET :: TZSTATION
TYPE(TPROFILERDATA), TARGET :: TZPROFILER

WAUTELET Philippe
committed

WAUTELET Philippe
committed
CLASS(TSTATPROFDATA), POINTER :: TZSTATPROF
SELECT TYPE( TPSTATPROF )
TYPE IS( TPROFILERDATA )
TZSTATPROF => TZPROFILER
TYPE IS( TSTATIONDATA )
TZSTATPROF => TZSTATION
CLASS DEFAULT
CALL PRINT_MSG( NVERB_ERROR, 'GEN', 'STATPROF_CSV_READ', 'unknown type for TPSTATPROF' )
END SELECT
INBLINE = 0 !Number of stations/profilers found in the file
KNUMBSTATPROF = 0 !Number of stations/profilers found in the file AND inside the model domain

RODIER Quentin
committed
! Open file

WAUTELET Philippe
committed
OPEN( NEWUNIT = ILU, FILE = HFILE, FORM = 'formatted' )
READ( ILU, END = 101, FMT = '(A)' ) YSTRING ! Reading of header (skip it)

RODIER Quentin
committed
DO

WAUTELET Philippe
committed
! Read station/profiler coordinates

WAUTELET Philippe
committed
READ( ILU, END = 101, FMT = '(A)' ) YSTRING
! Skip empty lines
IF ( LEN_TRIM( YSTRING ) == 0 ) CYCLE

WAUTELET Philippe
committed
! Check if record is written in French convention
CALL FRENCH_TO_ENGLISH( YSTRING )
IF ( LCARTESIAN ) THEN

WAUTELET Philippe
committed
READ( YSTRING, * ) TZSTATPROF%CNAME, TZSTATPROF%XX, TZSTATPROF%XY, TZSTATPROF%XZ

WAUTELET Philippe
committed
ELSE

WAUTELET Philippe
committed
READ( YSTRING, * ) TZSTATPROF%CNAME, TZSTATPROF%XLAT, TZSTATPROF%XLON, TZSTATPROF%XZ

WAUTELET Philippe
committed
END IF

WAUTELET Philippe
committed
IF ( .NOT. LCARTESIAN ) CALL STATPROF_INI_INTERP( TZSTATPROF )
CALL STATPROF_POSITION( TZSTATPROF, GINSIDE, GPRESENT )

WAUTELET Philippe
committed
IF ( GINSIDE ) THEN

WAUTELET Philippe
committed
KNUMBSTATPROF = KNUMBSTATPROF + 1
TZSTATPROF%NID = KNUMBSTATPROF

WAUTELET Philippe
committed
END IF

WAUTELET Philippe
committed
IF ( GPRESENT ) THEN
SELECT TYPE( TZSTATPROF )
TYPE IS( TPROFILERDATA )
CALL PROFILER_ADD( TZSTATPROF )
TYPE IS( TSTATIONDATA )
CALL STATION_ADD( TZSTATPROF )
CLASS DEFAULT

WAUTELET Philippe
committed
CALL PRINT_MSG( NVERB_ERROR, 'GEN', 'STATPROF_CSV_READ', 'unknown type for TPSTATPROF', OLOCAL = .TRUE. )

WAUTELET Philippe
committed
END SELECT
END IF

WAUTELET Philippe
committed

RODIER Quentin
committed
INBLINE = INBLINE + 1
END DO

WAUTELET Philippe
committed

RODIER Quentin
committed
101 CONTINUE

WAUTELET Philippe
committed
CLOSE( ILU )

WAUTELET Philippe
committed
IF ( INBLINE == 0 ) CALL PRINT_MSG( NVERB_ERROR, 'GEN', 'STATPROF_CSV_READ', 'Data not found in file ' // TRIM( HFILE ) )

WAUTELET Philippe
committed

WAUTELET Philippe
committed
END SUBROUTINE STATPROF_CSV_READ

WAUTELET Philippe
committed

RODIER Quentin
committed
!#########################################################
SUBROUTINE FRENCH_TO_ENGLISH(HSTRING)

WAUTELET Philippe
committed
CHARACTER(LEN=NMAXLINELGT), INTENT(INOUT) :: HSTRING ! csv record

RODIER Quentin
committed
INTEGER :: JL
LOGICAL :: GFRENCH
!
GFRENCH = .FALSE.
!* analyses if the record has been written in French convention
! French convention (separator is ; decimal symbol is ,)
! or English convention (separator is , decimal symbol is .)

WAUTELET Philippe
committed
DO JL = 1, NMAXLINELGT

RODIER Quentin
committed
IF (HSTRING(JL:JL)==';') GFRENCH=.TRUE.
END DO
!
! If French convention is used in the file, transforms it in English convention
IF (GFRENCH) THEN

WAUTELET Philippe
committed
DO JL = 1, NMAXLINELGT

RODIER Quentin
committed
IF (HSTRING(JL:JL)==',') HSTRING(JL:JL)='.'
IF (HSTRING(JL:JL)==';') HSTRING(JL:JL)=','
END DO
END IF
!
END SUBROUTINE FRENCH_TO_ENGLISH
END MODULE MODE_STATPROF_READER