From 8572be42ee5e198b0dd7ad9ac8dd46bbfb9a0b24 Mon Sep 17 00:00:00 2001
From: Juan Escobar <escj@aero.obs-mip.fr>
Date: Fri, 18 Jun 2021 16:57:22 +0200
Subject: [PATCH] Juan 18/06/2021: ECRAD-1.4.0 , add new MNH source
 read_albedo_data.f90,read_emiss_data.f90

---
 .../004_Reunion/003_mesonh/run_mesonh_xyz     |  4 +-
 .../KTEST/004_Reunion/004_diag/run_diag_xyz   |  5 ++
 .../007_16janvier/008_run2/run_mesonh_xyz     |  4 +-
 .../KTEST/007_16janvier/009_diag/run_diag_xyz |  4 +-
 src/MNH/read_albedo_data.f90                  | 64 +++++++++++++++++++
 src/MNH/read_emiss_data.f90                   | 63 ++++++++++++++++++
 6 files changed, 138 insertions(+), 6 deletions(-)
 create mode 100644 src/MNH/read_albedo_data.f90
 create mode 100644 src/MNH/read_emiss_data.f90

diff --git a/MY_RUN/KTEST/004_Reunion/003_mesonh/run_mesonh_xyz b/MY_RUN/KTEST/004_Reunion/003_mesonh/run_mesonh_xyz
index ce9bd3dc3..a7a52d531 100755
--- a/MY_RUN/KTEST/004_Reunion/003_mesonh/run_mesonh_xyz
+++ b/MY_RUN/KTEST/004_Reunion/003_mesonh/run_mesonh_xyz
@@ -10,8 +10,8 @@ ln -fs ../002_prep_ideal_case/REUNION_IDEA*.{des,lfi,nc} .
 ln -sf ../001_prep_pgd/REUNION_PGD_1km5.{des,lfi,nc} .
 
 if [ "x${MNH_ECRAD}" != "x" ]  ; then
-ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-1.0.1/data/RAD* .
-ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-1.0.1/data/*.nc .
+ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-${VERSION_ECRAD}/data/RAD* .
+ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-${VERSION_ECRAD}/data/*.nc .
 sed -e's/ECMW/ECRA/g' EXSEG1.nam.src > EXSEG1.nam
 else
 cp EXSEG1.nam.src EXSEG1.nam
diff --git a/MY_RUN/KTEST/004_Reunion/004_diag/run_diag_xyz b/MY_RUN/KTEST/004_Reunion/004_diag/run_diag_xyz
index 4f3502cb1..a14520746 100755
--- a/MY_RUN/KTEST/004_Reunion/004_diag/run_diag_xyz
+++ b/MY_RUN/KTEST/004_Reunion/004_diag/run_diag_xyz
@@ -11,5 +11,10 @@ rm -f KWRAI* OUT*
 ln -sf ../003_mesonh/REUNI.1.00A20.004.* .
 ln -sf ../001_prep_pgd/REUNION_PGD_1km5.* .
 
+if [ "x${MNH_ECRAD}" != "x" ]  ; then
+ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-${VERSION_ECRAD}/data/RAD* .
+ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-${VERSION_ECRAD}/data/*.nc .
+fi
+
 time ${MPIRUN} DIAG${XYZ}
 
diff --git a/MY_RUN/KTEST/007_16janvier/008_run2/run_mesonh_xyz b/MY_RUN/KTEST/007_16janvier/008_run2/run_mesonh_xyz
index 77692f0f6..e82b13a48 100755
--- a/MY_RUN/KTEST/007_16janvier/008_run2/run_mesonh_xyz
+++ b/MY_RUN/KTEST/007_16janvier/008_run2/run_mesonh_xyz
@@ -14,8 +14,8 @@ ln -sf  ../003_nest/16JAN98_36km.neste1.{des,lfi,nc} .
 ln -sf  ../003_nest/16JAN98_9km.neste1.{des,lfi,nc} .
 
 if [ "x${MNH_ECRAD}" != "x" ]  ; then
-ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-1.0.1/data/RAD* .
-ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-1.0.1/data/*.nc .
+ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-${VERSION_ECRAD}/data/RAD* .
+ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-${VERSION_ECRAD}/data/*.nc .
 sed -e's/ECMW/ECRA/g' EXSEG1.nam.src > EXSEG1.nam
 sed -e's/ECMW/ECRA/g' EXSEG2.nam.src > EXSEG2.nam
 else
diff --git a/MY_RUN/KTEST/007_16janvier/009_diag/run_diag_xyz b/MY_RUN/KTEST/007_16janvier/009_diag/run_diag_xyz
index 27ffa99ea..ef961876a 100755
--- a/MY_RUN/KTEST/007_16janvier/009_diag/run_diag_xyz
+++ b/MY_RUN/KTEST/007_16janvier/009_diag/run_diag_xyz
@@ -14,8 +14,8 @@ ln -sf ../003_nest/16JAN98_9km.neste1.* .
 ln -sf ../003_nest/16JAN98_36km.neste1.* .
 
 if [ "x${MNH_ECRAD}" != "x" ]  ; then
-ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-1.0.1/data/RAD* .
-ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-1.0.1/data/*.nc .
+ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-${VERSION_ECRAD}/data/RAD* .
+ln -sf ${SRC_MESONH}/src/LIB/RAD/ecrad-${VERSION_ECRAD}/data/*.nc .
 fi
 
 cp  DIAG1.nam1 DIAG1.nam
diff --git a/src/MNH/read_albedo_data.f90 b/src/MNH/read_albedo_data.f90
new file mode 100644
index 000000000..0409608c8
--- /dev/null
+++ b/src/MNH/read_albedo_data.f90
@@ -0,0 +1,64 @@
+!MNH_LIC Copyright 1994-2019 CNRS, Meteo-France and Universite Paul Sabatier
+!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
+!MNH_LIC for details. version 1.
+!-----------------------------------------------------------------
+!     ###################### 
+      MODULE MODI_READ_ALBEDO_DATA
+!     ######################
+!
+
+
+USE MODD_PARAM_ECRAD_n, ONLY : USER_ALB_DIFF, USER_ALB_DIR
+
+implicit none
+
+CONTAINS
+
+      SUBROUTINE READ_ALBEDO_DATA(SURF_TYPE)
+
+use easy_netcdf, only : netcdf_file
+use radiation_config, only: get_enum_code
+
+character(len=*), intent(in) :: SURF_TYPE
+
+!enum, bind(c) 
+ !    enumerator IAlbedoSnow, &
+  !        &     IAlbedoGrass
+  !end enum
+character(len=*), parameter :: AlbedoModelName(0:5) =  (/ 'OCEA', &
+                                               &        'VEGE',&
+                                               &        'DESE',&
+                                               &        'SNOW',&
+                                               &        'ZERO',&
+                                               &        'UNIT'    /)
+                                               
+type(netcdf_file)  :: file
+character(len=255) :: albedo_data_name 
+integer :: NALB
+real, allocatable :: ALL_ALB_DIFF(:,:)
+real, allocatable :: ALL_ALB_DIR(:,:)
+
+albedo_data_name = '/home/liboisq/MesoNH/MNH-V5-4-4/src/QUENTIN/ecrad-1.4.0/data/spectral_albedo.nc'
+
+! Determine albedo model
+call get_enum_code(SURF_TYPE, AlbedoModelName, &
+        &            ' ', NALB) 
+        
+! Open the file and configure the way it is read
+call file%open(trim(albedo_data_name), iverbose=1)
+call file%transpose_matrices()
+
+! Read the albedos
+call file%get_real_matrix('albedo_diff', ALL_ALB_DIFF)
+call file%get_real_matrix('albedo_dir', ALL_ALB_DIR)
+USER_ALB_DIFF(:) = ALL_ALB_DIFF(NALB+1,:)  ! because index starts at 0
+USER_ALB_DIR(:) = ALL_ALB_DIR(NALB+1,:)
+
+call file%close()
+
+
+END SUBROUTINE READ_ALBEDO_DATA
+
+END MODULE MODI_READ_ALBEDO_DATA
+
diff --git a/src/MNH/read_emiss_data.f90 b/src/MNH/read_emiss_data.f90
new file mode 100644
index 000000000..ba95430aa
--- /dev/null
+++ b/src/MNH/read_emiss_data.f90
@@ -0,0 +1,63 @@
+!MNH_LIC Copyright 1994-2019 CNRS, Meteo-France and Universite Paul Sabatier
+!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
+!MNH_LIC for details. version 1.
+!-----------------------------------------------------------------
+!     ###################### 
+      MODULE MODI_READ_EMISS_DATA
+!     ######################
+!
+
+
+USE MODD_PARAM_ECRAD_n, ONLY : USER_EMISS
+
+implicit none
+
+CONTAINS
+
+
+!
+      SUBROUTINE READ_EMISS_DATA(SURF_TYPE)
+!
+use easy_netcdf, only : netcdf_file
+use radiation_config, only: get_enum_code
+
+
+character(len=*), intent(in) :: SURF_TYPE
+
+
+character(len=*), parameter :: EmissModelName(0:5) = (/ 'OCEA', &
+                                               &        'VEGE',&
+                                               &        'DESE',&
+                                               &        'SNOW',&
+                                               &        'ZERO',&
+                                               &        'UNIT'    /)
+                                               
+type(netcdf_file)  :: file
+character(len=255)    :: emiss_data_name 
+integer :: NEMISS
+real, allocatable :: ALL_EMISS(:,:)
+
+emiss_data_name = '/home/liboisq/MesoNH/MNH-V5-4-4/src/QUENTIN/ecrad-1.4.0/data/spectral_emissivity.nc'
+
+! Determine emissivity model
+call get_enum_code(SURF_TYPE, EmissModelName, &
+        &            ' ', NEMISS) 
+        
+
+! Open the file and configure the way it is read
+call file%open(trim(emiss_data_name), iverbose=1)
+call file%transpose_matrices()
+
+! Read the emissivities
+call file%get_real_matrix('emissivity', ALL_EMISS)
+
+USER_EMISS(:) = ALL_EMISS(NEMISS+1,:)
+
+call file%close()
+
+
+END SUBROUTINE READ_EMISS_DATA
+
+END MODULE MODI_READ_EMISS_DATA
+
-- 
GitLab