Juan 14/02/2014: add management of ForeFire with key MNH_FOREFIRE PACK-MNH-V5-1--0-02-FF
authorJuan Escobar <juan.escobar@aero.obs-mip.fr>
Fri, 14 Feb 2014 09:15:53 +0000 (09:15 +0000)
committerPhilippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Thu, 19 May 2016 14:44:49 +0000 (16:44 +0200)
38 files changed:
conf/profile_mesonh.ihm
src/LIB/FOREFIRE/C_ForeFire_Interface.c [new file with mode: 0644]
src/LIB/FOREFIRE/F_ForeFire_Interface.f90 [new file with mode: 0644]
src/LIB/FOREFIRE/coupling_forefiren.f90 [new file with mode: 0644]
src/LIB/FOREFIRE/init_forefiren.f90 [new file with mode: 0644]
src/LIB/FOREFIRE/modd_forefire.f90 [new file with mode: 0644]
src/LIB/FOREFIRE/modd_forefiren.f90 [new file with mode: 0644]
src/LIB/FOREFIRE/modn_forefire.f90 [new file with mode: 0644]
src/MNH/boundaries.f90
src/MNH/default_desfmn.f90
src/MNH/goto_model_wrapper.f90
src/MNH/ground_paramn.f90
src/MNH/ini_cpl.f90
src/MNH/ini_dynamics.f90
src/MNH/ini_lb.f90
src/MNH/ini_modeln.f90
src/MNH/ini_nsv.f90
src/MNH/ini_one_wayn.f90
src/MNH/ini_segn.f90
src/MNH/ls_coupling.f90
src/MNH/modd_dynn.f90
src/MNH/modd_nsv.f90
src/MNH/modeln.f90
src/MNH/modn_dynn.f90
src/MNH/one_wayn.f90
src/MNH/prep_real_case.f90
src/MNH/read_desfmn.f90
src/MNH/read_exsegn.f90
src/MNH/read_field.f90
src/MNH/relaxation.f90
src/MNH/spawn_field2.f90
src/MNH/spawn_model2.f90
src/MNH/two_wayn.f90
src/MNH/update_nsv.f90
src/MNH/write_desfmn.f90
src/MNH/write_lbn.f90
src/MNH/write_lfin.f90
src/Makefile.MESONH.mk

index a629a97..70074e3 100755 (executable)
@@ -85,6 +85,10 @@ export MNH_INT=${MNH_INT}
 #
 export MNH_REAL=${MNH_REAL}
 #
+#  FOREFIRE
+#
+export MNH_FOREFIRE=${MNH_FOREFIRE}
+#
 ##########################################################
 ##########################################################
 ##########################################################
diff --git a/src/LIB/FOREFIRE/C_ForeFire_Interface.c b/src/LIB/FOREFIRE/C_ForeFire_Interface.c
new file mode 100644 (file)
index 0000000..97ca72b
--- /dev/null
@@ -0,0 +1,429 @@
+/*\r
+*MNH_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier\r
+*MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence\r
+*MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt  \r
+*MNH_LIC for details. version 1.\r
+*/\r
+/*\r
+!     ######################################################################\r
+!\r
+!!****  *C_ForeFire_Interface* - C bindings for LibForeFire\r
+!!****                        \r
+!!\r
+!!    PURPOSE\r
+!!    -------\r
+!!     Purpose is to provide entry points to the ForeFire library in order\r
+!!    to perform wildfire simulations\r
+!\r
+!\r
+!!**  METHOD\r
+!!    ------\r
+!!     All function calls are made from dynamic library, the shared lib is loaded at init\r
+!!     It matches F_ForeFire_Interface.f90 \r
+!!\r
+!!    EXTERNAL\r
+!!    --------\r
+!!      NA\r
+!!    IMPLICIT ARGUMENTS\r
+!!    ------------------\r
+!!      NA\r
+!!\r
+!!    REFERENCE\r
+!!    ---------\r
+!!    \r
+!!\r
+!!    AUTHOR\r
+!!    ------\r
+!!    J. P. Lafore  *Meteo-France*\r
+!!\r
+!!    MODIFICATIONS\r
+!!    -------------\r
+!!      Original    (SPE- Corte, Filippi) 04/2010 \r
+!! \r
+!------------------------------------------------------------------------------\r
+!\r
+*/\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <dlfcn.h>\r
+#include <assert.h>\r
+\r
+#define MAXCHARFORFUNC 200\r
+\r
+void *my_lib_handle = NULL;\r
+char passingchar[MAXCHARFORFUNC];\r
+\r
+const char* castchar(const char* cname){\r
+       int len = strlen(cname);\r
+       unsigned i = 0;\r
+       assert(len<MAXCHARFORFUNC);\r
+       for (i=0;i < len;i++){\r
+               passingchar[i]=cname[i];\r
+       }\r
+       passingchar[len]='\0';\r
+       return passingchar;\r
+}\r
+\r
+void loadLib(){\r
+       char libff[100];\r
+       sprintf(libff,"%s/exe/libForeFire.so",getenv("SRC_MESONH"));\r
+       my_lib_handle = dlopen(libff, RTLD_LAZY);\r
+}\r
+\r
+void MNHInit(double* t) {\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(double);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"MNHInit");\r
+               if (void_func!=NULL) {\r
+                       void_func(*t);\r
+               } else {\r
+                       printf("function 'MNHInit' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+\r
+}\r
+\r
+void MNHCreateDomain(int* id\r
+               , int* year, int* month, int* day, double* t\r
+               , double* lat, double* lon\r
+               , int* mdimx, double* meshx\r
+               , int* mdimy, double* meshy\r
+               , int* mdimz, int* sizein, double* zgrid\r
+               , double* dt) {\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(int, int, int, int, double, double, double\r
+                       , int, double*, int, double*, int, double*, double);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"MNHCreateDomain");\r
+               if (void_func!=NULL) {\r
+                       void_func(*id, *year, *month, *day, *t, *lat, *lon\r
+                                       , *mdimx, meshx, *mdimy, meshy, *mdimz, zgrid, *dt);\r
+               } else {\r
+                       printf("function 'MNHInit' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+\r
+}\r
+\r
+void CheckLayer(const char* layerName) {\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"CheckLayer");\r
+               if (void_func!=NULL) {\r
+                       void_func(layerName);\r
+               } else {\r
+                       printf("function 'checkLayer' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+\r
+}\r
+\r
+void MNHStep(double* dt) {\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(double);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"MNHStep");\r
+               if (void_func!=NULL) {\r
+                       void_func(*dt);\r
+               } else {\r
+                       printf("function 'MNHStep' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+\r
+}\r
+\r
+void MNHGoTo(double* time) {\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(double);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"MNHGoTo");\r
+               if (void_func!=NULL) {\r
+                       void_func(*time);\r
+               } else {\r
+                       printf("function 'MNHGoTo' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+\r
+}\r
+\r
+void Execute(const char* command) {\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"executeMNHCommand");\r
+               if (void_func!=NULL) {\r
+                       void_func(command);\r
+               } else {\r
+                       printf("function 'executeMNHCommand' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+\r
+}\r
+\r
+void FFPutString(const char* name, char* n){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, char*);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFPutString");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, n);\r
+               } else {\r
+                       printf("function 'FFPutString' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+\r
+void FFGetString(const char* name, const char* n){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, const char*);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFGetString");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, n);\r
+               } else {\r
+                       printf("function 'FFGetString' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+\r
+void FFPutInt(const char* name, int* n){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, int*);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFPutInt");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, n);\r
+               } else {\r
+                       printf("function 'FFPutInt' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+\r
+void FFGetInt(const char* name, int* n){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, int*);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFGetInt");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, n);\r
+               } else {\r
+                       printf("function 'FFGetInt' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+\r
+void FFGetIntArray(const char* name, int* x,\r
+               int *sizein, int *sizeout){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, int*, int, int);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFGetIntArray");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, x, *sizein, *sizeout);\r
+               } else {\r
+                       printf("function 'FFGetIntArray' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+\r
+void FFPutIntArray(const char* name, double *curtime\r
+               , int* x, int *sizein, int *sizeout){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, double, int*, int, int);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFPutIntArray");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, *curtime, x, *sizein, *sizeout);\r
+               } else {\r
+                       printf("function 'FFPutIntArray' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+\r
+void FFPutDouble(const char* name, double* x){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, double*);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFPutDouble");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, x);\r
+               } else {\r
+                       printf("function 'FFPutDouble' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+\r
+void FFGetDouble(const char* name, double* x){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, double*);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFGetDouble");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, x);\r
+               } else {\r
+                       printf("function 'FFGetDouble' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+\r
+void FFGetDoubleArray(const char* name, double *curtime\r
+               , double* x, int *sizein, int *sizeout){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, double, double*, int, int);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFGetDoubleArray");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, *curtime, x, *sizein, *sizeout);\r
+               } else {\r
+                       printf("function 'FFGetDoubleArray' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+void FFDumpDoubleArray(int *nmodel, int *nip, const char* name, double *curtime\r
+               , double* x, int *sizein, int *ni, int *nj, int *nk, int *sizeout){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(int, int, const char*, double, double*, int, int, int, int, int);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFDumpDoubleArray");\r
+               if (void_func!=NULL) {\r
+                       void_func(*nmodel, *nip, name, *curtime, x, *sizein, *ni, *nj, *nk, *sizeout);\r
+               } else {\r
+                       printf("function 'FFDumpDoubleArray' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
+void FFPutDoubleArray(const char* name, double* x,\r
+               int *sizein, int *sizeout){\r
+\r
+       if ( my_lib_handle == NULL ) loadLib();\r
+\r
+       void (*void_func)(const char*, double*, int, int);\r
+\r
+       if (my_lib_handle!=NULL) {\r
+               *(void **) (&void_func) = dlsym(my_lib_handle,"FFPutDoubleArray");\r
+               if (void_func!=NULL) {\r
+                       void_func(name, x, *sizein, *sizeout);\r
+               } else {\r
+                       printf("function 'FFPutDoubleArray' not found !!\n");\r
+                       printf(dlerror());\r
+               }\r
+       } else {\r
+               printf("libForeFire not found !!\n");\r
+               printf(dlerror());\r
+       }\r
+}\r
diff --git a/src/LIB/FOREFIRE/F_ForeFire_Interface.f90 b/src/LIB/FOREFIRE/F_ForeFire_Interface.f90
new file mode 100644 (file)
index 0000000..b9457e7
--- /dev/null
@@ -0,0 +1,180 @@
+!MNH_LIC Copyright 1994-2014 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 MODD_FOREFIRE_FORTRAN_API
+
+       USE&
+        ISO_C_BINDING, ONLY: C_INT, C_DOUBLE, C_CHAR, C_NULL_CHAR
+       USE MODD_NSV, ONLY: NSV_FF
+       IMPLICIT NONE
+       
+       CHARACTER(LEN=19, KIND=C_CHAR)  :: sCoupling = C_CHAR_'couplingResolution'//C_NULL_CHAR
+       CHARACTER(LEN=9, KIND=C_CHAR)   :: sParallel = C_CHAR_'parallel'//C_NULL_CHAR
+       CHARACTER(LEN=18, KIND=C_CHAR)  :: sNumIte = C_CHAR_'numAtmoIterations'//C_NULL_CHAR
+       CHARACTER(LEN=14, KIND=C_CHAR)  :: sOutUpdate = C_CHAR_'outputsUpdate'//C_NULL_CHAR
+       CHARACTER(LEN=15, KIND=C_CHAR)  :: s3DFlow = C_CHAR_'3DOutputs.Flow'//C_NULL_CHAR
+       CHARACTER(LEN=15, KIND=C_CHAR)  :: s3DPhys = C_CHAR_'3DOutputs.Phys'//C_NULL_CHAR
+       CHARACTER(LEN=15, KIND=C_CHAR)  :: s3DChem = C_CHAR_'3DOutputs.Chem'//C_NULL_CHAR
+       CHARACTER(LEN=9, KIND=C_CHAR)   :: sAltitude = C_CHAR_'altitude'//C_NULL_CHAR
+       CHARACTER(LEN=6, KIND=C_CHAR)   :: sZgrid = C_CHAR_'ZGRID'//C_NULL_CHAR
+       CHARACTER(LEN=9, KIND=C_CHAR)   :: sNumFNMax = C_CHAR_'numFNMax'//C_NULL_CHAR
+       CHARACTER(LEN=14, KIND=C_CHAR)  :: sMNHmult = C_CHAR_'mnhMultiplier'//C_NULL_CHAR
+       CHARACTER(LEN=14, KIND=C_CHAR)  :: sPosX = C_CHAR_'FireNodesPosX'//C_NULL_CHAR
+       CHARACTER(LEN=14, KIND=C_CHAR)  :: sPosY = C_CHAR_'FireNodesPosY'//C_NULL_CHAR
+       CHARACTER(LEN=14, KIND=C_CHAR)  :: sVelX = C_CHAR_'FireNodesVelX'//C_NULL_CHAR
+       CHARACTER(LEN=14, KIND=C_CHAR)  :: sVelY = C_CHAR_'FireNodesVelY'//C_NULL_CHAR
+       CHARACTER(LEN=14, KIND=C_CHAR)  :: sTime = C_CHAR_'FireNodesTime'//C_NULL_CHAR
+       CHARACTER(LEN=14, KIND=C_CHAR)  :: sId = C_CHAR_'FireNodesId'//C_NULL_CHAR
+       CHARACTER(LEN=6, KIND=C_CHAR)   :: sWindU = C_CHAR_'windU'//C_NULL_CHAR
+       CHARACTER(LEN=6, KIND=C_CHAR)   :: sWindV = C_CHAR_'windV'//C_NULL_CHAR
+       CHARACTER(LEN=11, KIND=C_CHAR)  :: sOutWindU = C_CHAR_'outerWindU'//C_NULL_CHAR
+       CHARACTER(LEN=11, KIND=C_CHAR)  :: sOutWindV = C_CHAR_'outerWindV'//C_NULL_CHAR
+       CHARACTER(LEN=2, KIND=C_CHAR)   :: sU = C_CHAR_'U'//C_NULL_CHAR
+       CHARACTER(LEN=2, KIND=C_CHAR)   :: sV = C_CHAR_'V'//C_NULL_CHAR
+       CHARACTER(LEN=2, KIND=C_CHAR)   :: sW = C_CHAR_'W'//C_NULL_CHAR
+       CHARACTER(LEN=2, KIND=C_CHAR)   :: sT = C_CHAR_'T'//C_NULL_CHAR
+       CHARACTER(LEN=2, KIND=C_CHAR)   :: sP = C_CHAR_'P'//C_NULL_CHAR
+       CHARACTER(LEN=4, KIND=C_CHAR)   :: sTKE = C_CHAR_'TKE'//C_NULL_CHAR
+       CHARACTER(LEN=6, KIND=C_CHAR)   :: sMoist = C_CHAR_'moist'//C_NULL_CHAR
+       CHARACTER(LEN=9, KIND=C_CHAR)   :: sHeatFlux = C_CHAR_'heatFlux'//C_NULL_CHAR
+       CHARACTER(LEN=10, KIND=C_CHAR)  :: sVaporFlux = C_CHAR_'vaporFlux'//C_NULL_CHAR
+       CHARACTER(LEN=7, KIND=C_CHAR), DIMENSION(:), ALLOCATABLE        :: sScalarVariables
+       CHARACTER(LEN=7, KIND=C_CHAR), DIMENSION(:), ALLOCATABLE        :: sChemicalVariables
+       ! INTERFACES FOR THE FUNCTIONS TO BE CALLED IN C !
+       !------------------------------------------------!
+       
+   INTERFACE
+
+       SUBROUTINE MNH_TO_FF_INIT(T) BIND(C, NAME='MNHInit')
+                       IMPORT C_DOUBLE
+               REAL(C_DOUBLE), INTENT(IN) :: T
+       END SUBROUTINE MNH_TO_FF_INIT
+
+       SUBROUTINE MNH_TO_FF_CREATEDOMAIN(ID, YEAR, MONTH, DAY, TIME &
+                       , LAT, LON, MDIMX, MESHX, MDIMY, MESHY, MDIMZ, SIZEIN, ZGRID, DT) BIND(C, NAME='MNHCreateDomain')
+                       IMPORT C_INT, C_DOUBLE
+               INTEGER(C_INT), INTENT(IN) :: ID
+               INTEGER(C_INT), INTENT(IN) :: YEAR, MONTH, DAY
+               REAL(C_DOUBLE), INTENT(IN) :: TIME
+               REAL(C_DOUBLE), INTENT(IN) :: LAT, LON
+               INTEGER(C_INT), INTENT(IN) :: MDIMX, MDIMY, MDIMZ
+               REAL(C_DOUBLE), DIMENSION(MDIMX), INTENT(IN) :: MESHX
+               REAL(C_DOUBLE), DIMENSION(MDIMY), INTENT(IN) :: MESHY
+               INTEGER(C_INT), INTENT(IN) :: SIZEIN
+               REAL(C_DOUBLE), DIMENSION(SIZEIN), INTENT(IN) :: ZGRID
+               REAL(C_DOUBLE), INTENT(IN) :: DT
+       END SUBROUTINE MNH_TO_FF_CREATEDOMAIN
+
+       SUBROUTINE MNH_TO_FF_CHECKLAYER(LAYERNAME) BIND(C, NAME='CheckLayer')
+                       IMPORT C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*)    :: LAYERNAME
+       END SUBROUTINE MNH_TO_FF_CHECKLAYER
+
+       SUBROUTINE MNH_TO_FF_STEP(DT) BIND(C, NAME='MNHStep')
+                       IMPORT C_DOUBLE
+               REAL(C_DOUBLE), INTENT(IN) :: DT
+       END SUBROUTINE MNH_TO_FF_STEP
+
+       SUBROUTINE MNH_TO_FF_GOTO(T) BIND(C, NAME='MNHGoTo')
+                       IMPORT C_DOUBLE
+               REAL(C_DOUBLE), INTENT(IN) :: T
+       END SUBROUTINE MNH_TO_FF_GOTO
+
+       SUBROUTINE MNH_TO_FF_EXECUTECOMMAND(COMMAND) BIND(C, NAME='Execute')
+                       IMPORT C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: COMMAND
+       END SUBROUTINE MNH_TO_FF_EXECUTECOMMAND
+
+       SUBROUTINE MNH_PUT_STRING(WORD) BIND(C, NAME='FFGetString')
+               IMPORT C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: WORD
+       END SUBROUTINE MNH_PUT_STRING
+
+       SUBROUTINE MNH_GET_STRING(WORD) BIND(C, NAME='FFPutString')
+               IMPORT C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: WORD
+       END SUBROUTINE MNH_GET_STRING
+
+       SUBROUTINE MNH_PUT_INT(MNAME, M) BIND(C, NAME='FFGetInt')
+               IMPORT C_INT, C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: MNAME
+               INTEGER(C_INT), INTENT(IN) :: M
+       END SUBROUTINE MNH_PUT_INT
+
+       SUBROUTINE MNH_GET_INT(MNAME, M) BIND(C, NAME='FFPutInt')
+               IMPORT C_INT, C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: MNAME
+               INTEGER(C_INT), INTENT(OUT) :: M
+       END SUBROUTINE MNH_GET_INT
+
+       SUBROUTINE MNH_PUT_INTARRAY(MNAME, M, CURTIME, SIZEIN, SIZEOUT) BIND(C, NAME='FFGetIntArray')
+               IMPORT C_INT, C_DOUBLE, C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: MNAME
+               REAL(C_DOUBLE), INTENT(IN) :: CURTIME
+               INTEGER(C_INT), INTENT(IN) :: SIZEIN, SIZEOUT
+               INTEGER(C_INT), DIMENSION(SIZEIN), INTENT(IN) :: M
+       END SUBROUTINE MNH_PUT_INTARRAY
+
+       SUBROUTINE MNH_GET_INTARRAY(MNAME, M, SIZEIN, SIZEOUT) BIND(C, NAME='FFPutIntArray')
+               IMPORT C_INT, C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: MNAME
+               INTEGER(C_INT), INTENT(IN) :: SIZEIN, SIZEOUT
+               INTEGER(C_INT), DIMENSION(SIZEIN), INTENT(OUT) :: M
+       END SUBROUTINE MNH_GET_INTARRAY
+
+       SUBROUTINE MNH_PUT_DOUBLE(MNAME, M) BIND(C, NAME='FFGetDouble')
+               IMPORT C_DOUBLE, C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: MNAME
+               REAL(C_DOUBLE), INTENT(IN) :: M
+       END SUBROUTINE MNH_PUT_DOUBLE
+
+       SUBROUTINE MNH_GET_DOUBLE(MNAME, M) BIND(C, NAME='FFPutDouble')
+               IMPORT C_DOUBLE, C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: MNAME
+               REAL(C_DOUBLE), INTENT(OUT) :: M
+       END SUBROUTINE MNH_GET_DOUBLE
+
+       SUBROUTINE MNH_PUT_DOUBLEARRAY(MNAME, CURTIME, M, SIZEIN, SIZEOUT) BIND(C, NAME='FFGetDoubleArray')
+               IMPORT C_INT, C_DOUBLE, C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: MNAME
+               REAL(C_DOUBLE), INTENT(IN) :: CURTIME
+               INTEGER(C_INT), INTENT(IN) :: SIZEIN, SIZEOUT
+               REAL(C_DOUBLE), DIMENSION(SIZEIN), INTENT(IN) :: M
+       END SUBROUTINE MNH_PUT_DOUBLEARRAY
+
+       SUBROUTINE MNH_DUMP_DOUBLEARRAY(NMODEL, IP, MNAME, CURTIME, M, SIZEIN, NI, NJ, NK, SIZEOUT) BIND(C, NAME='FFDumpDoubleArray')
+               IMPORT C_INT, C_DOUBLE, C_CHAR
+               INTEGER(C_INT), INTENT(IN) :: NMODEL, IP
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: MNAME
+               REAL(C_DOUBLE), INTENT(IN) :: CURTIME
+               INTEGER(C_INT), INTENT(IN) :: SIZEIN, NI, NJ, NK, SIZEOUT
+               REAL(C_DOUBLE), DIMENSION(SIZEIN), INTENT(IN) :: M
+       END SUBROUTINE MNH_DUMP_DOUBLEARRAY
+
+       SUBROUTINE MNH_GET_DOUBLEARRAY(MNAME, M, SIZEIN, SIZEOUT) BIND(C, NAME='FFPutDoubleArray')
+               IMPORT C_INT, C_DOUBLE, C_CHAR
+               CHARACTER(KIND=C_CHAR), DIMENSION(*) :: MNAME
+               INTEGER(C_INT), INTENT(IN) :: SIZEIN, SIZEOUT
+               REAL(C_DOUBLE), DIMENSION(SIZEIN), INTENT(OUT) :: M
+       END SUBROUTINE MNH_GET_DOUBLEARRAY
+       
+       FUNCTION cast_char_to_c(NAME)
+               IMPORT C_CHAR, C_NULL_CHAR
+                       CHARACTER (LEN=6) :: NAME
+                       CHARACTER(KIND=C_CHAR, LEN=7)   :: cast_char_to_c  
+       END FUNCTION cast_char_to_c
+
+   END INTERFACE
+
+END MODULE MODD_FOREFIRE_FORTRAN_API
+       
+FUNCTION cast_char_to_c(NAME)
+   USE&
+        ISO_C_BINDING, ONLY: C_CHAR, C_NULL_CHAR
+       CHARACTER (LEN=6) :: NAME
+       CHARACTER(KIND=C_CHAR, LEN=7)   :: cast_char_to_c  
+       cast_char_to_c = TRIM(NAME)//C_NULL_CHAR
+END FUNCTION cast_char_to_c
+
diff --git a/src/LIB/FOREFIRE/coupling_forefiren.f90 b/src/LIB/FOREFIRE/coupling_forefiren.f90
new file mode 100644 (file)
index 0000000..8d5dde8
--- /dev/null
@@ -0,0 +1,314 @@
+!MNH_LIC Copyright 1994-2014 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_COUPLING_FOREFIRE_n
+!############################## 
+
+    INTERFACE
+
+        SUBROUTINE COUPLING_FOREFIRE_n (DT, PSFTH, PSFTQ, PSFSV)
+            IMPLICIT NONE
+            REAL, INTENT(IN)  :: DT    ! time step of mesonh (s)
+            REAL, DIMENSION(:,:),   INTENT(INOUT)  :: PSFTH, PSFTQ ! heat surface flux
+            REAL, DIMENSION(:,:,:), INTENT(INOUT)  :: PSFSV ! surface flux of scalars
+        END SUBROUTINE COUPLING_FOREFIRE_n
+
+        SUBROUTINE SEND_GROUND_WIND_n (U, V, KG, IINFO)
+            IMPLICIT NONE
+            REAL, DIMENSION(:,:,:), INTENT(IN)  :: U, V ! wind components
+            INTEGER, INTENT(IN) :: KG ! vertical indice of the ground
+            INTEGER, INTENT(IN) :: IINFO ! integer for parallel communications
+        END SUBROUTINE SEND_GROUND_WIND_n
+      
+        SUBROUTINE FOREFIRE_SEND_PARAL_n (IINFO)
+            IMPLICIT NONE
+            INTEGER, INTENT(IN) :: IINFO ! integer for parallel communications
+        END SUBROUTINE FOREFIRE_SEND_PARAL_n
+      
+        SUBROUTINE FOREFIRE_RECEIVE_PARAL_n ()
+            IMPLICIT NONE
+        END SUBROUTINE FOREFIRE_RECEIVE_PARAL_n
+
+        SUBROUTINE FOREFIRE_DUMP_FIELDS_n(U, V, W, MNHSV, TH &
+                                         , R, PABS, TKE, NX, NY, NZ)
+            IMPLICIT NONE
+            REAL, DIMENSION(:,:,:), INTENT(IN)  :: U, V, W ! wind components (m/s)
+            REAL, DIMENSION(:,:,:), INTENT(IN)  :: TH, R, PABS, TKE ! physical fields
+            REAL, DIMENSION(:,:,:,:), INTENT(IN)  :: MNHSV ! other MNH variables (/m3)
+            INTEGER, INTENT(IN) :: NX, NY, NZ ! size of the matrices
+        END SUBROUTINE FOREFIRE_DUMP_FIELDS_n
+      
+    END INTERFACE
+
+      
+END MODULE MODI_COUPLING_FOREFIRE_n
+
+
+!#######################################################
+SUBROUTINE COUPLING_FOREFIRE_n (DT, PSFTH, PSFTQ, PSFSV)
+!#######################################################
+
+!!****  *COUPLING_FOREFIRE_n* -
+!!      P. Tulet CNRM
+!!      X. Pialat SPE
+
+USE MODD_FOREFIRE_n
+USE MODD_FOREFIRE
+USE MODD_FOREFIRE_FORTRAN_API
+USE MODD_NSV
+
+IMPLICIT NONE
+
+REAL, INTENT(IN)                                                       :: DT                           ! time step
+REAL, DIMENSION(:,:), INTENT(INOUT)    :: PSFTH, PSFTQ         ! heat surface flux
+REAL, DIMENSION(:,:,:), INTENT(INOUT)  :: PSFSV                        ! surface flux of scalars
+
+! bound indices for the scalar variables
+
+INTEGER                                                                                        :: JSV
+
+!* Advancing the fire simulation for a MNH step
+!
+   CALL MNH_TO_FF_STEP(DT)
+!
+!* Injecting fluxes from the fire simulation into MNH
+!
+       CALL MNH_GET_DOUBLEARRAY(sHeatFlux, FF_HEATFLUX, FF_MATRIXSIZE, 1)
+       PSFTH(:, :) = PSFTH(:, :) + FF_HEATFLUX(:, :)
+
+       CALL MNH_GET_DOUBLEARRAY(sVaporFlux, FF_VAPORFLUX, FF_MATRIXSIZE, 1)
+       PSFTQ(:, :) = PSFTQ(:, :) + FF_VAPORFLUX(:, :)
+
+       DO JSV = 1, NSV_FF
+               CALL MNH_GET_DOUBLEARRAY(sScalarVariables(JSV), FF_SVFLUXES(:, :, JSV), FF_MATRIXSIZE, 1) 
+               PSFSV(:, :, NSV_FFBEG-1+JSV) = PSFSV(:, :, NSV_FFBEG-1+JSV) + FF_SVFLUXES(:, :, JSV)
+       END DO
+       
+       IF ( LFFCHEM ) THEN
+               DO JSV = 1, NFFCHEMVAR
+                       CALL MNH_GET_DOUBLEARRAY(sChemicalVariables(JSV), FF_CVFLUXES(:, :, JSV), FF_MATRIXSIZE, 1) 
+                       PSFSV(:, :, FF_CHEMINDICES(JSV)) = PSFSV(:, :, FF_CHEMINDICES(JSV)) + FF_CVFLUXES(:, :, JSV)
+               END DO
+       ENDIF
+
+END SUBROUTINE COUPLING_FOREFIRE_n
+
+       
+!##############################################
+SUBROUTINE SEND_GROUND_WIND_n (U, V, KG, IINFO)
+!##############################################
+
+!!****  *SEND_GROUND_WIND_n* -
+!!      X. Pialat SPE
+
+USE MODD_FOREFIRE_n
+USE MODD_FOREFIRE
+USE MODD_FOREFIRE_FORTRAN_API
+
+USE MODE_ll
+USE MODD_ARGSLIST_ll, ONLY : LIST_ll
+
+IMPLICIT NONE
+
+REAL, DIMENSION(:,:,:), INTENT(IN)  :: U, V            ! wind components
+INTEGER, INTENT(IN)                                            :: KG                   ! vertical indice of the ground
+INTEGER, INTENT(IN)                                            :: IINFO                ! integer for parallel communications
+
+INTEGER                                                                                :: IFF, JFF, VAL1, VAL2, VAL3
+TYPE(LIST_ll), POINTER                 :: FOREFIREFIELD_ll    ! list of fields to exchange for ForeFire
+
+!
+!* Communicating the surface wind to the forefire simulation
+!
+       CALL MNH_PUT_DOUBLEARRAY(sWindU, FF_TIME, U(:,:,KG:KG), FF_MATRIXSIZE, 1)
+       CALL MNH_PUT_DOUBLEARRAY(swindV, FF_TIME, V(:,:,KG:KG), FF_MATRIXSIZE, 1)
+
+!* Then some non-conventional manipulations to communicate the outer velocities
+       DO IFF = 2, FF_NX-1
+               FFOUTERWINDU(IFF,2) = U(IFF,3,KG)
+               FFOUTERWINDU(IFF,FF_NY-1) = U(IFF,FF_NY-2,KG)
+               FFOUTERWINDV(IFF,2) = V(IFF,3,KG)
+               FFOUTERWINDV(IFF,FF_NY-1) = V(IFF,FF_NY-2,KG)
+       END DO
+       DO JFF = 2, FF_NY-1
+               FFOUTERWINDU(2,JFF) = U(3,JFF,KG)
+               FFOUTERWINDU(FF_NX-1,JFF) = U(FF_NX-2,JFF,KG)
+               FFOUTERWINDV(2,JFF) = V(3,JFF,KG)
+               FFOUTERWINDV(FF_NX-1,JFF) = V(FF_NX-2,JFF,KG)
+       END DO
+         
+       VAL1 = INT(U(2,3,KG)*FFMULT+0.5)
+       VAL2 = INT(U(3,3,KG)*FFMULT+0.5)
+       VAL3 = INT(U(3,2,KG)*FFMULT+0.5)
+       FFOUTERWINDU(2,2) = VAL1*FFMULT*FFMULT*100 + VAL2*FFMULT*10 + VAL3
+       VAL1 = INT(V(2,3,KG)*FFMULT+0.5)
+       VAL2 = INT(V(3,3,KG)*FFMULT+0.5)
+       VAL3 = INT(V(3,2,KG)*FFMULT+0.5)
+       FFOUTERWINDV(2,2) = VAL1*FFMULT*FFMULT*100 + VAL2*FFMULT*10 + VAL3
+
+       VAL1 = INT(U(FF_NX-2,2,KG)*FFMULT+0.5)
+       VAL2 = INT(U(FF_NX-2,3,KG)*FFMULT+0.5)
+       VAL3 = INT(U(FF_NX-1,3,KG)*FFMULT+0.5)
+       FFOUTERWINDU(FF_NX-1,2) = VAL1*FFMULT*FFMULT*100 + VAL2*FFMULT*10 + VAL3
+       VAL1 = INT(V(FF_NX-2,2,KG)*FFMULT+0.5)
+       VAL2 = INT(V(FF_NX-2,3,KG)*FFMULT+0.5)
+       VAL3 = INT(V(FF_NX-1,3,KG)*FFMULT+0.5)
+       FFOUTERWINDV(FF_NX-1,2) = VAL1*FFMULT*FFMULT*100 + VAL2*FFMULT*10 + VAL3
+
+       VAL1 = INT(U(3,FF_NY-1,KG)*FFMULT+0.5)
+       VAL2 = INT(U(3,FF_NY-2,KG)*FFMULT+0.5)
+       VAL3 = INT(U(2,FF_NY-2,KG)*FFMULT+0.5)
+       FFOUTERWINDU(2,FF_NY-1) = VAL1*FFMULT*FFMULT*100 + VAL2*FFMULT*10 + VAL3
+       VAL1 = INT(V(3,FF_NY-1,KG)*FFMULT+0.5)
+       VAL2 = INT(V(3,FF_NY-2,KG)*FFMULT+0.5)
+       VAL3 = INT(V(2,FF_NY-2,KG)*FFMULT+0.5)
+       FFOUTERWINDV(2,FF_NY-1) = VAL1*FFMULT*FFMULT*100 + VAL2*FFMULT*10 + VAL3
+
+       VAL1 = INT(U(FF_NX-1,FF_NY-2,KG)*FFMULT+0.5)
+       VAL2 = INT(U(FF_NX-2,FF_NY-2,KG)*FFMULT+0.5)
+       VAL3 = INT(U(FF_NX-2,FF_NY-1,KG)*FFMULT+0.5)
+       FFOUTERWINDU(FF_NX-1,FF_NY-1) = VAL1*FFMULT*FFMULT*100 + VAL2*FFMULT*10 + VAL3
+       VAL1 = INT(V(FF_NX-1,FF_NY-2,KG)*FFMULT+0.5)
+       VAL2 = INT(V(FF_NX-2,FF_NY-2,KG)*FFMULT+0.5)
+       VAL3 = INT(V(FF_NX-2,FF_NY-1,KG)*FFMULT+0.5)
+       FFOUTERWINDV(FF_NX-1,FF_NY-1) = VAL1*FFMULT*FFMULT*100 + VAL2*FFMULT*10 + VAL3
+
+       NULLIFY(FOREFIREFIELD_ll)
+       CALL ADD2DFIELD_ll(FOREFIREFIELD_ll,FFOUTERWINDU)
+       CALL ADD2DFIELD_ll(FOREFIREFIELD_ll,FFOUTERWINDV)
+       CALL UPDATE_HALO_ll(FOREFIREFIELD_ll,IINFO)
+       CALL CLEANLIST_ll(FOREFIREFIELD_ll)
+       CALL MNH_PUT_DOUBLEARRAY(sOutWindU, FF_TIME, FFOUTERWINDU, FF_MATRIXSIZE, 1)
+       CALL MNH_PUT_DOUBLEARRAY(sOutWindV, FF_TIME, FFOUTERWINDV, FF_MATRIXSIZE, 1)
+   
+END SUBROUTINE SEND_GROUND_WIND_n
+
+       
+!#####################################
+SUBROUTINE FOREFIRE_RECEIVE_PARAL_n ()
+!#####################################
+
+!!****  *FOREFIRE_RECEIVE_PARAL_n* -
+!!      X. Pialat SPE
+
+USE MODD_FOREFIRE_n
+USE MODD_FOREFIRE
+USE MODD_FOREFIRE_FORTRAN_API
+
+IMPLICIT NONE
+
+       CALL MNH_PUT_DOUBLEARRAY(sPosX, FF_TIME, FFNODES_POSX, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_PUT_DOUBLEARRAY(sPosY, FF_TIME, FFNODES_POSY, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_PUT_DOUBLEARRAY(sVelX, FF_TIME, FFNODES_VELX, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_PUT_DOUBLEARRAY(sVelY, FF_TIME, FFNODES_VELY, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_PUT_DOUBLEARRAY(sTime, FF_TIME, FFNODES_TIME, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_PUT_DOUBLEARRAY(sId, FF_TIME, FFNODES_ID, FF_PARALMATRIXSIZE, 1)
+   
+END SUBROUTINE FOREFIRE_RECEIVE_PARAL_n
+
+       
+!#######################################
+SUBROUTINE FOREFIRE_SEND_PARAL_n (IINFO)
+!#######################################
+
+!!****  *FOREFIRE_SEND_PARAL_n* -
+!!      X. Pialat (SPE)
+
+USE MODD_FOREFIRE_n
+USE MODD_FOREFIRE
+USE MODD_FOREFIRE_FORTRAN_API
+
+USE MODE_ll
+USE MODD_ARGSLIST_ll, ONLY : LIST_ll
+
+IMPLICIT NONE
+
+INTEGER, INTENT(IN)                                    :: IINFO
+TYPE(LIST_ll), POINTER           :: FOREFIREFIELD_ll    ! list of fields to exchange for ForeFire
+
+       CALL MNH_GET_DOUBLEARRAY(sPosX, FFNODES_POSX, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_GET_DOUBLEARRAY(sPosY, FFNODES_POSY, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_GET_DOUBLEARRAY(sVelX, FFNODES_VELX, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_GET_DOUBLEARRAY(sVelY, FFNODES_VELY, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_GET_DOUBLEARRAY(sTime, FFNODES_TIME, FF_PARALMATRIXSIZE, 1)
+       CALL MNH_GET_DOUBLEARRAY(sId, FFNODES_ID, FF_PARALMATRIXSIZE, 1)
+!
+!* Calling the MNH parallel routines for the forefire-related variables
+!
+       NULLIFY(FOREFIREFIELD_ll)
+       CALL ADD3DFIELD_ll(FOREFIREFIELD_ll, FFNODES_POSX)
+       CALL ADD3DFIELD_ll(FOREFIREFIELD_ll, FFNODES_POSY)
+       CALL ADD3DFIELD_ll(FOREFIREFIELD_ll, FFNODES_VELX)
+       CALL ADD3DFIELD_ll(FOREFIREFIELD_ll, FFNODES_VELY)
+       CALL ADD3DFIELD_ll(FOREFIREFIELD_ll, FFNODES_TIME)
+       CALL ADD3DFIELD_ll(FOREFIREFIELD_ll, FFNODES_ID)
+       CALL UPDATE_HALO_ll(FOREFIREFIELD_ll, IINFO)
+       CALL CLEANLIST_ll(FOREFIREFIELD_ll)
+   
+END SUBROUTINE FOREFIRE_SEND_PARAL_n
+       
+       
+!#####################################################
+SUBROUTINE FOREFIRE_DUMP_FIELDS_n(U, V, W, MNHSV, TH &
+                                                                       , R, PABS, TKE, NX, NY, NZ)
+!#####################################################
+
+!!****  *FOREFIRE_DUMP_FIELDS_n* -
+!!      X. Pialat (SPE)
+
+USE MODD_NSV
+USE MODD_FOREFIRE_n
+USE MODD_FOREFIRE
+USE MODD_FOREFIRE_FORTRAN_API
+USE MODD_CH_M9_n,      ONLY: CNAMES
+
+IMPLICIT NONE
+
+REAL, DIMENSION(:,:,:), INTENT(IN)     :: U, V, W                                      ! wind components (m/s)
+REAL, DIMENSION(:,:,:), INTENT(IN)     :: TH, R, PABS, TKE             ! physical fields
+REAL, DIMENSION(:,:,:,:), INTENT(IN)   :: MNHSV                                        ! other MNH variables (/m3)
+INTEGER, INTENT(IN)                                                    :: NX, NY, NZ                           ! size of the matrices
+
+INTEGER :: JSV
+
+!
+!* sending the arrays to binary unformatted fortran files for visualization
+!
+       IF ( ((FF_TIME/FFOUTPUTSUPDATE).GE.FFNUMOUT) ) THEN
+               FF3DOUT = 1
+               FFNUMOUT = FFNUMOUT + 1
+       END IF
+       
+       IF ( FF3DOUTPUTSFLOW .AND. FF3DOUT.EQ.1 ) THEN
+               CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, sU, FF_TIME, U, NX*NY*NZ, NX, NY, NZ, 1)
+               CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, sV, FF_TIME, V, NX*NY*NZ, NX, NY, NZ, 1)
+               CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, sW, FF_TIME, W, NX*NY*NZ, NX, NY, NZ, 1)
+               DO JSV = 1, NSV_FF
+                       CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, cast_char_to_c(CSV(NSV_FFBEG-1+JSV)) &
+                               , FF_TIME, MNHSV(:, :, :, NSV_FFBEG-1+JSV), NX*NY*NZ, NX, NY, NZ, 1)
+               END DO
+       END IF
+       
+       IF ( FF3DOUTPUTSPHYS .AND. FF3DOUT.EQ.1 ) THEN
+               CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, sT, FF_TIME, TH, NX*NY*NZ, NX, NY, NZ, 1)
+               CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, sMoist, FF_TIME, R, NX*NY*NZ, NX, NY, NZ, 1)
+               CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, sP, FF_TIME, PABS, NX*NY*NZ, NX, NY, NZ, 1)
+               CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, sTKE, FF_TIME, TKE, NX*NY*NZ, NX, NY, NZ, 1)
+       END IF
+       
+       IF ( LFFCHEM .AND. FF3DOUTPUTSCHEM .AND. FF3DOUT.EQ.1 ) THEN
+               DO JSV = 1, NFFCHEMVAR
+                       CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, cast_char_to_c(CNAMES(FF_CHEMINDICES(JSV))) &
+                                               , FF_TIME, MNHSV(:, :, :, FF_CHEMINDICES(JSV)), NX*NY*NZ, NX, NY, NZ, 1)
+               END DO
+               DO JSV = 1, NFFCHEMVAROUT
+                       CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, cast_char_to_c(CNAMES(FF_CHEMINDOUT(JSV))) &
+                                               , FF_TIME, MNHSV(:, :, :, FF_CHEMINDOUT(JSV)), NX*NY*NZ, NX, NY, NZ, 1)
+               END DO
+       END IF
+       
+       FF3DOUT = 0
+
+END SUBROUTINE FOREFIRE_DUMP_FIELDS_n
diff --git a/src/LIB/FOREFIRE/init_forefiren.f90 b/src/LIB/FOREFIRE/init_forefiren.f90
new file mode 100644 (file)
index 0000000..00c85c6
--- /dev/null
@@ -0,0 +1,202 @@
+!MNH_LIC Copyright 1994-2014 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_INIT_FOREFIRE_n
+!!    ################################ 
+
+      INTERFACE
+      
+       SUBROUTINE INIT_FOREFIRE_n(KMODEL, KLUOUT, IP, KYEAR, KMONTH, KDAY, PTIME, DT)
+       
+               IMPLICIT NONE
+                       INTEGER, INTENT(IN)     :: KMODEL       ! number of the model in nest hierarchy
+               INTEGER, INTENT(IN)     :: KLUOUT       ! output listing
+                               INTEGER, INTENT(IN)             :: IP                           ! mpi rank of the process
+                               INTEGER, INTENT(IN)     :: KYEAR        ! current year (UTC)
+                               INTEGER, INTENT(IN)     :: KMONTH       ! current month (UTC)
+                               INTEGER, INTENT(IN)     :: KDAY         ! current day (UTC)
+                               REAL, INTENT(IN)                :: PTIME        ! current time since midnight (UTC, s)
+                               REAL, INTENT(IN)                :: DT                   ! time-step of MNH (s)
+                               
+       END SUBROUTINE INIT_FOREFIRE_n
+       
+      END INTERFACE 
+      
+      END MODULE MODI_INIT_FOREFIRE_n
+
+!     ##################################################
+      SUBROUTINE INIT_FOREFIRE_n(KMODEL, KLUOUT, IP, KYEAR, KMONTH, KDAY, PTIME, DT)
+!     ##################################################
+
+!!    AUTHORS
+!!    -------
+!!      P. Tulet  CNRM
+!!      X. Pialat SPE
+
+USE MODD_FOREFIRE
+USE MODD_FOREFIRE_n
+USE MODD_FOREFIRE_FORTRAN_API
+
+USE MODD_DYN_n,                ONLY: NSTOP
+USE MODD_GRID,         ONLY: XLATORI, XLONORI
+USE MODD_GRID_n,       ONLY: XXHAT, XYHAT, XZHAT, XZS, XZZ
+USE MODD_NSV,          ONLY: NSV_CHEMBEG, NSV_CHEMEND, NSV_FF, NSV_FFBEG, NSV_FFEND, CSV
+USE MODD_CH_MNHC_n,    ONLY: LUSECHEM
+USE MODD_CH_M9_n,      ONLY: CNAMES
+
+   INTEGER, INTENT(IN)         :: KMODEL       ! number of the model in nest hierarchy
+   INTEGER, INTENT(IN)         :: KLUOUT       ! output listing
+       INTEGER, INTENT(IN)             :: IP                           ! mpi rank of the process
+       INTEGER, INTENT(IN)     :: KYEAR        ! current year (UTC)
+       INTEGER, INTENT(IN)     :: KMONTH       ! current month (UTC)
+       INTEGER, INTENT(IN)     :: KDAY         ! current day (UTC)
+       REAL, INTENT(IN)                :: PTIME        ! current time since midnight (UTC, s)
+       REAL, INTENT(IN)                :: DT                   ! time-step of MNH (s)
+       
+       INTEGER                 :: IINFO_ll       ! return code of parallel routine
+       INTEGER                                         :: JSV, JCHEMV
+       
+       LOGICAL                                                 :: DUMPEDGRID 
+
+       WRITE (KLUOUT,*)  'COUPLING WITH FOREFIRE IN MODEL ', KMODEL
+       
+       !******************************!
+       !* COMMON PART FOR ALL MODELS *!
+       !******************************!
+       
+       ! INITIALISATION OF THE FOREFIRE SIMULATION
+       !------------------------------------------
+       CALL MNH_TO_FF_INIT(PTIME)
+   
+   ! SIZE OF THE MATRICES TO RETRIEVE THE SURFACE PROPERTIES
+   !--------------------------------------------------------
+   FF_NX = SIZE(XXHAT)
+   FF_NY = SIZE(XYHAT)
+   FF_NZ = SIZE(XZHAT)
+   FF_MATRIXSIZE = FF_NX*FF_NY
+   
+   ! REFERENCE FOR THE OUTPUTS
+   !--------------------------
+       FFNMODEL = KMODEL
+       PROCID = IP
+       FFOUTPUTSUPDATE = FFOUTUPS(KMODEL)
+       IF ( FFOUTPUTSUPDATE .LE. 0 ) THEN
+               FFOUTPUTSUPDATE = 1000000.
+       ELSE
+               CALL MNH_DUMP_DOUBLEARRAY(FFNMODEL, PROCID, sZgrid, FF_TIME, XZZ, FF_NX*FF_NY*FF_NZ, FF_NX, FF_NY, FF_NZ, 1)
+       ENDIF
+   FFREFERENCETIME = PTIME
+   FF_TIME = 0.
+   FFNUMOUT = 0;
+
+   ! ARE FOREFIRE 3D OUTPUTS REQUESTED BY THE USER ?
+   !------------------------------------------------
+   
+   IF ( FLOWOUT(FFNMODEL) .GT. 0 ) THEN
+      FF3DOUTPUTSFLOW = .TRUE.
+   ELSE
+      FF3DOUTPUTSFLOW = .FALSE.
+   END IF
+   IF ( PHYSOUT(FFNMODEL) .GT. 0 ) THEN
+      FF3DOUTPUTSPHYS = .TRUE.
+   ELSE
+      FF3DOUTPUTSPHYS = .FALSE.
+   END IF
+   IF ( CHEMOUT(FFNMODEL) .GT. 0 ) THEN
+      FF3DOUTPUTSCHEM = .TRUE.
+   ELSE
+      FF3DOUTPUTSCHEM = .FALSE.
+   END IF
+       
+       !************************************************!
+       !* SPECIFIC PART IS THE MODEL IS COUPLED TO MNH *!
+       !************************************************!
+  
+   IF ( FFCOUPLING ) THEN 
+       ! CREATING THE FOREFIRE DOMAIN
+       !-----------------------------
+       CALL MNH_TO_FF_CREATEDOMAIN(IP, KYEAR, KMONTH, KDAY, PTIME, XLATORI, XLONORI &
+                       , FF_NX, XXHAT, FF_NY, XYHAT, FF_NZ, FF_NX*FF_NY*FF_NZ, XZZ, DT)
+
+       ! SETTING THE FIRE SIMULATION TO PARALLEL
+       !----------------------------------------
+       CALL MNH_PUT_INT(sParallel, 1)
+
+               ! COMMUNICATING THE NUMBER OF MNH ITERATIONS
+       !-------------------------------------------
+       CALL MNH_PUT_INT(sNumIte, NSTOP)
+       
+          ! COMMUNICATION OF THE OROGRAPHY TO FOREFIRE
+          !-------------------------------------------
+          CALL MNH_PUT_DOUBLEARRAY(sAltitude, FF_TIME, XZS, FF_MATRIXSIZE, 1)
+       
+          ! ALLOCATION OF THE FLUXES STEMMING FROM FOREFIRE
+          !------------------------------------------------
+          ALLOCATE(FF_HEATFLUX(FF_NX, FF_NY))
+               CALL MNH_TO_FF_CHECKLAYER(sHeatFlux)
+          ALLOCATE(FF_VAPORFLUX(FF_NX, FF_NY))
+               CALL MNH_TO_FF_CHECKLAYER(sVaporFlux)
+          ALLOCATE(FF_SVFLUXES(FF_NX, FF_NY, NSV_FF))
+          ALLOCATE(sScalarVariables(NSV_FF))
+          DO JSV = 1, NSV_FF
+                       CSV(NSV_FFBEG+JSV-1) = TRIM(FFSVNAMES(JSV))
+                       sScalarVariables(JSV) = cast_char_to_c(FFSVNAMES(JSV))
+                       CALL MNH_TO_FF_CHECKLAYER(sScalarVariables(JSV))
+               ENDDO
+       
+               ! RETRIEVING INFORMATION IN CASE OF CHEMICAL COUPLING
+               !----------------------------------------------------
+               IF ( LFFCHEM ) THEN
+                       IF ( .NOT.LUSECHEM ) THEN
+                               WRITE(*,*) 'PROBLEM: YOU SWITCHED CHEMISTRY ON IN FOREFIRE WHILE OFF IN MNH'
+                       ENDIF
+                       ALLOCATE(FF_CHEMINDICES(NFFCHEMVAR))
+               ALLOCATE(FF_CVFLUXES(FF_NX, FF_NY, NFFCHEMVAR))
+               ALLOCATE(sChemicalVariables(NFFCHEMVAR))
+                       DO JSV = 1, NFFCHEMVAR
+                               sChemicalVariables(JSV) = cast_char_to_c(FFCVNAMES(JSV))
+                               CALL MNH_TO_FF_CHECKLAYER(sChemicalVariables(JSV))
+                               DO JCHEMV = 1, NSV_CHEMEND-NSV_CHEMBEG
+                               IF ( TRIM(CNAMES(JCHEMV)) == TRIM(FFCVNAMES(JSV)) ) THEN
+                                       FF_CHEMINDICES(JSV) = JCHEMV
+                               END IF
+                               ENDDO
+                       ENDDO
+                       ALLOCATE(FF_CHEMINDOUT(NFFCHEMVAROUT))
+                       DO JSV = 1, NFFCHEMVAROUT
+                               DO JCHEMV = 1, NSV_CHEMEND-NSV_CHEMBEG
+                               IF ( TRIM(CNAMES(JCHEMV)) == TRIM(FFCONAMES(JSV)) ) THEN
+                                       FF_CHEMINDOUT(JSV) = JCHEMV
+                               END IF
+                               ENDDO
+                       ENDDO
+               END IF
+          
+          ! RETRIEVING THE MAXIMUM NUMBER OF FIRENODES PER MNH CELL
+          !--------------------------------------------------------
+          CALL MNH_GET_INT(sNumFNMax, NBFNMAX)
+          FF_PARALMATRIXSIZE = FF_MATRIXSIZE*NBFNMAX
+       
+          ! ALLOCATION OF THE MATRICES FOR FOREFIRE PARALLELISATION
+          !--------------------------------------------------------
+          ALLOCATE(FFNODES_POSX(FF_NX,FF_NY,NBFNMAX))
+          ALLOCATE(FFNODES_POSY(FF_NX,FF_NY,NBFNMAX))
+          ALLOCATE(FFNODES_VELX(FF_NX,FF_NY,NBFNMAX))
+          ALLOCATE(FFNODES_VELY(FF_NX,FF_NY,NBFNMAX))
+          ALLOCATE(FFNODES_TIME(FF_NX,FF_NY,NBFNMAX))
+          ALLOCATE(FFNODES_ID(FF_NX,FF_NY,NBFNMAX))
+          ALLOCATE(FFOUTERWINDU(FF_NX,FF_NY))
+          ALLOCATE(FFOUTERWINDV(FF_NX,FF_NY))
+          FFOUTERWINDU(:,:) = 0.
+          FFOUTERWINDV(:,:) = 0.
+          CALL MNH_GET_INT(sMNHmult, FFMULT)
+               
+               ! PARALLELIZATION PROCESS
+               !------------------------
+               CALL FOREFIRE_SEND_PARAL_n(IINFO_ll)
+   ENDIF
+
+
+END SUBROUTINE INIT_FOREFIRE_n
diff --git a/src/LIB/FOREFIRE/modd_forefire.f90 b/src/LIB/FOREFIRE/modd_forefire.f90
new file mode 100644 (file)
index 0000000..4afe973
--- /dev/null
@@ -0,0 +1,42 @@
+!MNH_LIC Copyright 1994-2014 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.
+!     ######spl
+      MODULE MODD_FOREFIRE
+!     ##################
+!-------------------------------------------------------------------------------
+!***   MODD_LAVA  Declaration of lava module
+!
+!!    AUTHOR
+!!    ------
+!                 : P. Tulet,  LACy / CNRM
+!!            : X. Pialat, SPE
+!      Creation   : 15.02.2012
+!
+!-------------------------------------------------------------------------------
+!
+!
+!*    0. DECLARATIONS
+!        ------------
+! 
+USE MODD_PARAMETERS
+!
+IMPLICIT NONE
+!
+LOGICAL     :: LFOREFIRE = .FALSE.                             ! Switch to activate ForeFire coupling
+REAL                   :: COUPLINGRES = 100.                                   ! Coupling resolution (above the model is not coupled with ForeFire)
+INTEGER                :: NFFSCALARS = 0                                                       ! Number of passive tracers in ForeFire
+CHARACTER(LEN=6), DIMENSION(10)        :: FFSVNAMES    ! Names of the scalar variables
+LOGICAL     :: LFFCHEM = .FALSE.                                       ! Switch to activate chemistry in ForeFire coupling
+INTEGER                :: NFFCHEMVAR = 0                                                       ! Number of chemical variables in ForeFire coupling
+CHARACTER(LEN=6), DIMENSION(10)        :: FFCVNAMES    ! Names of the chemical variables
+INTEGER                :: NFFCHEMVAROUT = 0                                            ! Number of chemical variables for outputs only
+CHARACTER(LEN=6), DIMENSION(10)        :: FFCONAMES    ! Names of the chemical variables
+REAL, DIMENSION(6)                                     :: FFOUTUPS             ! Outputs updates periods for the MNH models
+INTEGER, DIMENSION(6)                          :: FLOWOUT              ! Booleans for flow variables outputs
+INTEGER, DIMENSION(6)                          :: PHYSOUT              ! Booleans for physical variables outputs
+INTEGER, DIMENSION(6)                          :: CHEMOUT              ! Booleans for physical variables outputs
+
+!
+END MODULE MODD_FOREFIRE
diff --git a/src/LIB/FOREFIRE/modd_forefiren.f90 b/src/LIB/FOREFIRE/modd_forefiren.f90
new file mode 100644 (file)
index 0000000..bea6c97
--- /dev/null
@@ -0,0 +1,186 @@
+!MNH_LIC Copyright 1994-2014 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 MODD_FOREFIRE_n
+!!    ############################ 
+!!    AUTHOR
+!!    ------
+!!     P. Tulet     *Meteo France*
+!!
+!!    MODIFICATIONS
+!!    -------------
+!!      Original    07/08
+!-------------------------------------------------------------------------------
+!
+!*       0.   DECLARATIONS
+!             ------------
+!
+USE MODD_PARAMETERS, ONLY: JPMODELMAX
+
+IMPLICIT NONE 
+
+TYPE FOREFIRE_t
+
+       ! Effective coupling for this model
+       LOGICAL         :: FFCOUPLING
+       
+       ! Current time of the simulation
+       REAL                    :: FF_TIME
+       
+       ! Dimensions of the matrices of ForeFire
+       INTEGER                 :: FF_MATRIXSIZE, FF_SVMATRIXSIZE
+       INTEGER                 :: FF_NX, FF_NY, FF_NZ
+       
+       ! Dimensions of the matrices for parallelization
+       INTEGER                 :: FF_PARALMATRIXSIZE
+
+
+       ! INFORMATION TO BE PASSED FROM FOREFIRE TO MNH
+       !----------------------------------------------
+       
+       ! Boolean for dumping 3D outputs through ForeFire
+       INTEGER         :: FFNMODEL
+       INTEGER         :: PROCID
+       INTEGER                 :: FF3DOUT
+       LOGICAL                 :: FF3DOUTPUTSFLOW, FF3DOUTPUTSPHYS, FF3DOUTPUTSCHEM
+       REAL                    :: FFOUTPUTSUPDATE
+       REAL                    :: FFNUMOUT
+       REAL                    :: FFREFERENCETIME
+       
+       ! Maximum number of fire markers in each MNH cell
+       INTEGER                 :: NBFNMAX
+       
+       ! Coefficient for the exchange of information for the outer wind
+       INTEGER                 :: FFMULT
+
+       ! Position and velocity of the fire markers in each MNH cell
+       REAL, DIMENSION(:,:,:), POINTER :: FFNODES_POSX
+       REAL, DIMENSION(:,:,:), POINTER :: FFNODES_POSY
+       REAL, DIMENSION(:,:,:), POINTER :: FFNODES_VELX
+       REAL, DIMENSION(:,:,:), POINTER :: FFNODES_VELY
+       REAL, DIMENSION(:,:,:), POINTER :: FFNODES_TIME
+       REAL, DIMENSION(:,:,:), POINTER :: FFNODES_ID
+       
+       ! Heat flux stemming from ForeFire in each cell
+       REAL, DIMENSION(:,:), POINTER   :: FF_HEATFLUX
+       ! Vapor flux stemming from ForeFire in each cell
+       REAL, DIMENSION(:,:), POINTER   :: FF_VAPORFLUX
+       ! Scalar variables' fluxes stemming from ForeFire in each cell
+       REAL, DIMENSION(:,:,:), POINTER :: FF_SVFLUXES
+       ! Chemical index of the variables in case of chemical coupling
+       INTEGER, DIMENSION(:), POINTER :: FF_CHEMINDICES
+       ! Chemical variables' fluxes stemming from ForeFire in each cell
+       REAL, DIMENSION(:,:,:), POINTER :: FF_CVFLUXES
+       ! Chemical index of the variables for outputs purpose
+       INTEGER, DIMENSION(:), POINTER :: FF_CHEMINDOUT
+       
+       ! Velocities in the outer region of the domain for continuity in the halo
+       REAL, DIMENSION(:,:), POINTER   :: FFOUTERWINDU
+       REAL, DIMENSION(:,:), POINTER   :: FFOUTERWINDV
+
+END TYPE FOREFIRE_t
+
+! Definition of the pointers for all the models
+TYPE(FOREFIRE_t), DIMENSION(JPMODELMAX), TARGET, SAVE :: FOREFIRE_MODEL
+
+! Definition of the current pointers
+! Scalars
+LOGICAL, POINTER       :: FFCOUPLING=>NULL()
+REAL, POINTER          :: FF_TIME=>NULL()
+INTEGER, POINTER       :: FF_MATRIXSIZE=>NULL() 
+INTEGER, POINTER       :: FF_SVMATRIXSIZE=>NULL()
+INTEGER, POINTER       :: FF_NX=>NULL()
+INTEGER, POINTER       :: FF_NY=>NULL()
+INTEGER, POINTER       :: FF_NZ=>NULL()
+INTEGER, POINTER       :: FF_PARALMATRIXSIZE=>NULL()
+INTEGER, POINTER       :: FFNMODEL=>NULL()
+INTEGER, POINTER       :: PROCID=>NULL()
+INTEGER, POINTER       :: FF3DOUT=>NULL()
+LOGICAL, POINTER       :: FF3DOUTPUTSFLOW=>NULL()
+LOGICAL, POINTER       :: FF3DOUTPUTSPHYS=>NULL()
+LOGICAL, POINTER       :: FF3DOUTPUTSCHEM=>NULL()
+REAL, POINTER          :: FFOUTPUTSUPDATE=>NULL()
+REAL, POINTER          :: FFNUMOUT=>NULL()
+REAL, POINTER          :: FFREFERENCETIME=>NULL()
+INTEGER, POINTER       :: NBFNMAX=>NULL()
+INTEGER, POINTER       :: FFMULT=>NULL()
+! Arrays
+REAL, DIMENSION(:,:,:), POINTER        :: FFNODES_POSX=>NULL()
+REAL, DIMENSION(:,:,:), POINTER        :: FFNODES_POSY=>NULL()
+REAL, DIMENSION(:,:,:), POINTER        :: FFNODES_VELX=>NULL()
+REAL, DIMENSION(:,:,:), POINTER        :: FFNODES_VELY=>NULL()
+REAL, DIMENSION(:,:,:), POINTER        :: FFNODES_TIME=>NULL()
+REAL, DIMENSION(:,:,:), POINTER        :: FFNODES_ID=>NULL()
+REAL, DIMENSION(:,:), POINTER  :: FF_HEATFLUX=>NULL()
+REAL, DIMENSION(:,:), POINTER  :: FF_VAPORFLUX=>NULL()
+REAL, DIMENSION(:,:,:), POINTER        :: FF_SVFLUXES=>NULL()
+REAL, DIMENSION(:,:,:), POINTER        :: FF_CVFLUXES=>NULL()
+INTEGER, DIMENSION(:), POINTER :: FF_CHEMINDICES=>NULL()
+INTEGER, DIMENSION(:), POINTER :: FF_CHEMINDOUT=>NULL()
+REAL, DIMENSION(:,:), POINTER  :: FFOUTERWINDU=>NULL()
+REAL, DIMENSION(:,:), POINTER  :: FFOUTERWINDV=>NULL()
+
+CONTAINS
+
+SUBROUTINE FOREFIRE_GOTO_MODEL(KFROM, KTO)
+
+INTEGER, INTENT(IN) :: KFROM, KTO
+
+! Save current state for allocated arrays
+FOREFIRE_MODEL(KFROM)%FFNODES_POSX=>FFNODES_POSX
+FOREFIRE_MODEL(KFROM)%FFNODES_POSY=>FFNODES_POSY
+FOREFIRE_MODEL(KFROM)%FFNODES_VELX=>FFNODES_VELX
+FOREFIRE_MODEL(KFROM)%FFNODES_VELY=>FFNODES_VELY
+FOREFIRE_MODEL(KFROM)%FFNODES_TIME=>FFNODES_TIME
+FOREFIRE_MODEL(KFROM)%FFNODES_ID=>FFNODES_ID
+FOREFIRE_MODEL(KFROM)%FF_HEATFLUX=>FF_HEATFLUX
+FOREFIRE_MODEL(KFROM)%FF_VAPORFLUX=>FF_VAPORFLUX
+FOREFIRE_MODEL(KFROM)%FF_SVFLUXES=>FF_SVFLUXES
+FOREFIRE_MODEL(KFROM)%FF_CHEMINDICES=>FF_CHEMINDICES
+FOREFIRE_MODEL(KFROM)%FF_CHEMINDOUT=>FF_CHEMINDOUT
+FOREFIRE_MODEL(KFROM)%FF_CVFLUXES=>FF_CVFLUXES
+FOREFIRE_MODEL(KFROM)%FFOUTERWINDU=>FFOUTERWINDU
+FOREFIRE_MODEL(KFROM)%FFOUTERWINDV=>FFOUTERWINDV
+
+! Current model is set to model KTO
+! Scalars
+FFCOUPLING=>FOREFIRE_MODEL(KTO)%FFCOUPLING
+FF_TIME=>FOREFIRE_MODEL(KTO)%FF_TIME
+FF_MATRIXSIZE=>FOREFIRE_MODEL(KTO)%FF_MATRIXSIZE
+FF_SVMATRIXSIZE=>FOREFIRE_MODEL(KTO)%FF_SVMATRIXSIZE
+FF_NX=>FOREFIRE_MODEL(KTO)%FF_NX
+FF_NY=>FOREFIRE_MODEL(KTO)%FF_NY
+FF_NZ=>FOREFIRE_MODEL(KTO)%FF_NZ
+FF_PARALMATRIXSIZE=>FOREFIRE_MODEL(KTO)%FF_PARALMATRIXSIZE
+FFNMODEL=>FOREFIRE_MODEL(KTO)%FFNMODEL
+PROCID=>FOREFIRE_MODEL(KTO)%PROCID
+FF3DOUT=>FOREFIRE_MODEL(KTO)%FF3DOUT
+FF3DOUTPUTSFLOW=>FOREFIRE_MODEL(KTO)%FF3DOUTPUTSFLOW
+FF3DOUTPUTSPHYS=>FOREFIRE_MODEL(KTO)%FF3DOUTPUTSPHYS
+FF3DOUTPUTSCHEM=>FOREFIRE_MODEL(KTO)%FF3DOUTPUTSCHEM
+FFOUTPUTSUPDATE=>FOREFIRE_MODEL(KTO)%FFOUTPUTSUPDATE
+FFNUMOUT=>FOREFIRE_MODEL(KTO)%FFNUMOUT
+FFREFERENCETIME=>FOREFIRE_MODEL(KTO)%FFREFERENCETIME
+NBFNMAX=>FOREFIRE_MODEL(KTO)%NBFNMAX
+FFMULT=>FOREFIRE_MODEL(KTO)%FFMULT
+! Arrays
+FFNODES_POSX=>FOREFIRE_MODEL(KTO)%FFNODES_POSX
+FFNODES_POSY=>FOREFIRE_MODEL(KTO)%FFNODES_POSY
+FFNODES_VELX=>FOREFIRE_MODEL(KTO)%FFNODES_VELX
+FFNODES_VELY=>FOREFIRE_MODEL(KTO)%FFNODES_VELY
+FFNODES_TIME=>FOREFIRE_MODEL(KTO)%FFNODES_TIME
+FFNODES_ID=>FOREFIRE_MODEL(KTO)%FFNODES_ID
+FF_HEATFLUX=>FOREFIRE_MODEL(KTO)%FF_HEATFLUX
+FF_VAPORFLUX=>FOREFIRE_MODEL(KTO)%FF_VAPORFLUX
+FF_SVFLUXES=>FOREFIRE_MODEL(KTO)%FF_SVFLUXES
+FF_CHEMINDICES=>FOREFIRE_MODEL(KTO)%FF_CHEMINDICES
+FF_CHEMINDOUT=>FOREFIRE_MODEL(KTO)%FF_CHEMINDOUT
+FF_CVFLUXES=>FOREFIRE_MODEL(KTO)%FF_CVFLUXES
+FFOUTERWINDU=>FOREFIRE_MODEL(KTO)%FFOUTERWINDU
+FFOUTERWINDV=>FOREFIRE_MODEL(KTO)%FFOUTERWINDV
+
+END SUBROUTINE FOREFIRE_GOTO_MODEL
+
+END MODULE MODD_FOREFIRE_n
diff --git a/src/LIB/FOREFIRE/modn_forefire.f90 b/src/LIB/FOREFIRE/modn_forefire.f90
new file mode 100644 (file)
index 0000000..a1e9561
--- /dev/null
@@ -0,0 +1,32 @@
+!MNH_LIC Copyright 1994-2014 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.
+!     ######spl
+      MODULE MODN_FOREFIRE
+!     ##################
+!-------------------------------------------------------------------------------
+!***   MODN_FOREFIRE  Declaration of namelist NAM_FOREFIRE
+!
+!!    AUTHOR
+!!    ------
+!                 : P. Tulet (LACy / CNRM)
+!!              X. Pialat (SPE)
+!      Creation   : 09.10.2010
+!-------------------------------------------------------------------------------
+!
+!
+!*       0.   DECLARATIONS
+!             ------------
+!
+USE MODD_FOREFIRE
+!
+IMPLICIT NONE
+!
+NAMELIST /NAM_FOREFIRE/LFOREFIRE, COUPLINGRES, &
+               NFFSCALARS, FFSVNAMES, &
+               LFFCHEM, NFFCHEMVAR, FFCVNAMES, &
+               NFFCHEMVAROUT, FFCONAMES, &
+               FFOUTUPS, FLOWOUT, PHYSOUT, CHEMOUT
+! 
+END MODULE MODN_FOREFIRE
index 85ede1e..09452c2 100644 (file)
@@ -165,6 +165,7 @@ END MODULE MODI_BOUNDARIES
 !!      Modification    05/06               Remove EPS
 !!      Modification    12/2010  (Chong)    Add boundary condition for ions
 !!                                          (fair weather profiles)
+!!      Modification    07/2013  (Bosseur & Filippi) adds Forefire
 !!      Modification    04/2013  (C.Lac)    Remove instant M               
 !-------------------------------------------------------------------------------
 !
@@ -183,7 +184,10 @@ USE MODD_CONDSAMP,    ONLY : LCONDSAMP
 USE MODD_ELEC_DESCR             
 USE MODD_ELEC_n                 
 USE MODD_REF_n    
-USE MODD_PARAM_n,     ONLY : CELEC 
+USE MODD_PARAM_n,    ONLY : CELEC 
+#ifdef MNH_FOREFIRE
+USE MODD_FOREFIRE,   ONLY : LFOREFIRE
+#endif
 !
 USE MODE_MODELN_HANDLER
 !
@@ -251,14 +255,14 @@ REAL                :: ZTSTEP    ! effective time step
 INTEGER             :: ILBX,ILBY ! size of LB fields' arrays
 LOGICAL, SAVE, DIMENSION(:), ALLOCATABLE :: GCHBOUNDARY, GAERBOUNDARY,&
                     GDSTBOUNDARY, GSLTBOUNDARY, GPPBOUNDARY,          &
-                    GCSBOUNDARY, GICBOUNDARY
+                    GCSBOUNDARY, GICBOUNDARY 
 LOGICAL, SAVE        :: GFIRSTCALL1 = .TRUE.
 LOGICAL, SAVE        :: GFIRSTCALL2 = .TRUE.
 LOGICAL, SAVE        :: GFIRSTCALL3 = .TRUE.
 LOGICAL, SAVE        :: GFIRSTCALL5 = .TRUE. 
 LOGICAL, SAVE        :: GFIRSTCALLPP = .TRUE.                         
 LOGICAL, SAVE        :: GFIRSTCALLCS = .TRUE.                         
-LOGICAL, SAVE        :: GFIRSTCALLIC = .TRUE.                         
+LOGICAL, SAVE        :: GFIRSTCALLIC = .TRUE.                 
 !
 REAL, DIMENSION(SIZE(PLBXWM,1),SIZE(PLBXWM,2),SIZE(PLBXWM,3)) ::  &
                        ZLBXVT,ZLBXWT,ZLBXTHT
@@ -279,6 +283,11 @@ REAL, DIMENSION(SIZE(PLBYSVM,1),SIZE(PLBYSVM,2),SIZE(PLBYSVM,3),SIZE(PLBYSVM,4))
 LOGICAL              :: GCHTMP
 LOGICAL              :: GPPTMP
 LOGICAL              :: GCSTMP
+#ifdef MNH_FOREFIRE
+LOGICAL, SAVE, DIMENSION(:), ALLOCATABLE ::  GFFBOUNDARY
+LOGICAL, SAVE        :: GFIRSTCALLFF = .TRUE.                         
+LOGICAL              :: GFFTMP
+#endif
 !
 !-------------------------------------------------------------------------------
 !
@@ -945,6 +954,33 @@ IF ( LCONDSAMP .AND. IMI == 1) THEN
     ENDIF
   ENDDO
 ENDIF
+#ifdef MNH_FOREFIRE
+!ForeFire 
+IF ( LFOREFIRE .AND. IMI == 1) THEN
+  IF (GFIRSTCALLFF) THEN
+    ALLOCATE(GFFBOUNDARY(NSV_FF))
+    GFIRSTCALLFF = .FALSE.
+    DO JSV=NSV_FFBEG,NSV_FFEND
+      GFFTMP = .FALSE.
+      IF (LWEST_ll().AND.HLBCX(1)=='OPEN') GFFTMP = GFFTMP .OR. ALL(PLBXSVM(1,:,:,JSV)==0)
+      IF (LEAST_ll().AND.HLBCX(2)=='OPEN') GFFTMP = GFFTMP .OR. ALL(PLBXSVM(ILBX,:,:,JSV)==0)
+      IF (LSOUTH_ll().AND.HLBCY(1)=='OPEN') GFFTMP = GFFTMP .OR. ALL(PLBYSVM(:,1,:,JSV)==0)
+      IF (LNORTH_ll().AND.HLBCY(2)=='OPEN') GFFTMP = GFFTMP .OR. ALL(PLBYSVM(:,ILBY,:,JSV)==0)
+      GFFBOUNDARY(JSV-NSV_FFBEG+1) = GFFTMP
+    ENDDO
+  ENDIF
+
+  DO JSV=NSV_FFBEG,NSV_FFEND
+    IF (GFFBOUNDARY(JSV-NSV_FFBEG+1)) THEN
+      IF (SIZE(PSVT)>0) THEN
+       CALL CH_BOUNDARIES (HLBCX,HLBCY,PUT,PVT,PSVT(:,:,:,JSV))
+      ELSE
+!!$        CALL CH_BOUNDARIES (HLBCX,HLBCY,PSVM(:,:,:,JSV),PUM,PVM,PSVM(:,:,:,JSV))
+      ENDIF
+    ENDIF
+  ENDDO
+ENDIF
+#endif
 !
 IF ( CELEC /= 'NONE' .AND. IMI == 1) THEN
   CALL ION_BOUNDARIES (HLBCX,HLBCY,PUT,PVT,PSVT)
index 8b7c65c..93b3cb0 100644 (file)
@@ -205,6 +205,7 @@ END MODULE MODI_DEFAULT_DESFM_n
 !!                   13/01/11           add LCH_RET_ICE
 !!                   01/07/11 (F.Couvreux) Add CONDSAMP
 !!                   01/07/11 (B.Aouizerats) Add CAOP    
+!!                   07/2013  (Bosseur & Filippi) adds Forefire
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -247,6 +248,9 @@ USE MODD_MEAN_FIELD
 USE MODD_DRAGTREE
 USE MODD_LATZ_EDFLX
 USE MODD_2D_FRC
+#ifdef MNH_FOREFIRE
+USE MODD_FOREFIRE
+#endif
 !
 IMPLICIT NONE
 !
@@ -379,6 +383,9 @@ LHORELAX_SVSLT  = .FALSE.
 LHORELAX_SVPP   = .FALSE.
 LHORELAX_SVCS   = .FALSE.
 LHORELAX_SVAER  = .FALSE.
+#ifdef MNH_FOREFIRE
+LHORELAX_SVFF   = .FALSE.
+#endif
 !
 !-------------------------------------------------------------------------------
 !
@@ -1194,6 +1201,21 @@ XUV_FLX1=3.E+14
 XUV_FLX2=0.
 LTH_FLX=.FALSE.
 XTH_FLX=0.75
+#ifdef MNH_FOREFIRE
+!-------------------------------------------------------------------------------
+!
+!*      27.   SET DEFAULT VALUES FOR MODD_FOREFIRE         
+!             ----------------------------------
+!
+! other values initialized in modd_forefire
+!
+IF (KMI == 1) THEN 
+  LFOREFIRE = .FALSE.
+  LFFCHEM = .FALSE.
+  COUPLINGRES = 100.
+  NFFSCALARS = 0
+ENDIF  
+#endif                 
 !-------------------------------------------------------------------------------
 !
 END SUBROUTINE DEFAULT_DESFM_n
index 77140fe..69fe137 100644 (file)
@@ -11,6 +11,7 @@
 !!    MODIFICATIONS
 !!    -------------
 !!      06/12 (Tomasini) Grid-nesting of ADVFRC and EDDY_FLUX
+!!      07/13 (Bosseur & Filippi) adds Forefire
 !-----------------------------------------------------------------
 MODULE MODI_GOTO_MODEL_WRAPPER
 
@@ -61,6 +62,9 @@ USE MODD_PARAM_MFSHALL_n
 USE MODD_PARAM_n
 USE MODD_PARAM_RAD_n
 USE MODD_PASPOL_n
+#ifdef MNH_FOREFIRE
+USE MODD_FOREFIRE_n
+#endif
 USE MODD_PRECIP_n
 USE MODD_ELEC_n
 USE MODD_PROFILER_n
@@ -136,6 +140,9 @@ CALL PARAM_MFSHALL_GOTO_MODEL(KFROM, KTO)
 CALL PARAM_GOTO_MODEL(KFROM, KTO)
 CALL PARAM_RAD_GOTO_MODEL(KFROM, KTO)
 CALL PASPOL_GOTO_MODEL(KFROM, KTO)
+#ifdef MNH_FOREFIRE
+CALL FOREFIRE_GOTO_MODEL(KFROM, KTO)
+#endif
 CALL PRECIP_GOTO_MODEL(KFROM, KTO)
 CALL ELEC_GOTO_MODEL(KFROM, KTO)
 CALL PROFILER_GOTO_MODEL(KFROM, KTO)
index 43df727..ef0cccf 100644 (file)
@@ -103,6 +103,7 @@ END MODULE MODI_GROUND_PARAM_n
 !      (P.Tulet )             01/11/03  externalisation of the surface chemistry!
 !!     (D.Gazen)              01/12/03  change emissions handling for surf. externalization
 !!     (J.escobar)            18/10/2012 missing USE MODI_COUPLING_SURF_ATM_n & MODI_DIAG_SURF_ATM_n
+!      (J.escobar)            2/2014 add Forefire coupling
 !-------------------------------------------------------------------------------
 !
 !*       0.     DECLARATIONS
@@ -112,7 +113,7 @@ USE MODD_CST,        ONLY : XP00, XCPD, XRD, XRV,XRHOLW, XDAY, XPI, XLVTT, XMD,
 USE MODD_PARAMETERS, ONLY : JPVEXT, XUNDEF
 USE MODD_DYN_n,      ONLY : XTSTEP
 USE MODD_CH_MNHC_n,  ONLY : LCH_SURFACE_FLUX
-USE MODD_FIELD_n,    ONLY : XUT, XVT, XWT, XTHT, XRT, XPABST, XSVT
+USE MODD_FIELD_n,    ONLY : XUT, XVT, XWT, XTHT, XRT, XPABST, XSVT, XTKET
 USE MODD_METRICS_n,  ONLY : XDXX, XDYY, XDZZ
 USE MODD_DIM_n,      ONLY : NKMAX
 USE MODD_GRID_n,     ONLY : XLON, XZZ, XDIRCOSXW, XDIRCOSYW, XDIRCOSZW, &
@@ -147,6 +148,12 @@ USE MODI_DIAG_SURF_ATM_n
 !
 USE MODE_ll
 USE MODD_ARGSLIST_ll, ONLY : LIST_ll
+#ifdef MNH_FOREFIRE
+!** MODULES FOR FOREFIRE **!
+USE MODD_FOREFIRE
+USE MODD_FOREFIRE_n
+USE MODI_COUPLING_FOREFIRE_n
+#endif
 !
 USE MODD_TIME_n
 USE MODD_TIME
@@ -517,6 +524,31 @@ END IF
 ! Transform 1D output fields into 2D:
 !
 CALL UNSHAPE_SURF(IDIM1,IDIM2)
+#ifdef MNH_FOREFIRE
+!------------------------!
+! COUPLING WITH FOREFIRE !
+!------------------------!
+       
+IF ( LFOREFIRE ) THEN
+       CALL FOREFIRE_DUMP_FIELDS_n(XUT, XVT, XWT, XSVT&
+                  , XTHT, XRT(:,:,:,1), XPABST, XTKET&
+                  , IDIM1+2, IDIM2+2, NKMAX+2)
+END IF
+
+IF ( FFCOUPLING ) THEN
+
+       CALL SEND_GROUND_WIND_n(XUT, XVT, IKB, IINFO_ll)
+       
+       CALL FOREFIRE_RECEIVE_PARAL_n()
+   
+   CALL COUPLING_FOREFIRE_n(XTSTEP, ZSFTH, ZSFTQ, ZSFTS)
+       
+       CALL FOREFIRE_SEND_PARAL_n(IINFO_ll)
+   
+END IF
+
+FF_TIME = FF_TIME + XTSTEP
+#endif
 !
 ! Friction of components along slope axes (U: largest local slope axis, V: zero slope axis)
 !
index 4ee8f1d..84b4582 100644 (file)
@@ -212,6 +212,7 @@ END MODULE MODI_INI_CPL
 !!      Modification   (Masson)  01/2004 surface externalization, removes 
 !!                                       SST forcing
 !!      Modification             05/2006  Remove KEPS
+!!                     (Escobar) 2/2014 add Forefire
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -234,6 +235,11 @@ USE MODI_TEMPORAL_DIST
 USE MODE_FMREAD
 USE MODI_INI_LS
 USE MODI_INI_LB
+#ifdef MNH_FOREFIRE
+USE MODD_PASPOL
+USE MODD_FOREFIRE
+USE MODD_FOREFIRE_n
+#endif
 !
 IMPLICIT NONE
 !
@@ -505,6 +511,10 @@ CALL INI_LS(CCPLFILE(NCPL_CUR),HLUOUT,HGETRVM,GLSOURCE,PLSUS,PLSVS,PLSWS,PLSTHS,
 !IF ( LUSECHEM .AND. (.NOT. OCH_INIT_FIELD) )  &
 !   YGETSVM(NSV_CHEMBEG: NSV_CHEMEND) = 'INIT'
 !IF (HCONF == 'RESTA')  THEN
+#ifdef MNH_FOREFIRE
+!   IF (LPASPOL) YGETSVM(NSV_PPBEG: NSV_PPEND) = 'INIT'
+!   IF (LFOREFIRE) YGETSVM(NSV_FFBEG: NSV_FFEND) = 'INIT'
+#endif
 !   IF (NSV_USER /= 0) YGETSVM(1/NSV_USER) = 'INIT'
 !   IF (NSV_C2R2 /= 0) YGETSVM(NSV_C2R2BEG: NSV_C2R2END) = 'INIT'
 !   IF (NSV_C1R3 /= 0) YGETSVM(NSV_C1R3BEG: NSV_C1R3END) = 'INIT'
index 0a8f3c8..c5c85d1 100644 (file)
@@ -14,6 +14,9 @@ SUBROUTINE INI_DYNAMICS(HLUOUT,PLON,PLAT,PRHODJ,PTHVREF,PMAP,PZZ,            &
                OHORELAX_SVC2R2,OHORELAX_SVC1R3,OHORELAX_SVELEC,OHORELAX_SVLG,&
                OHORELAX_SVCHEM,OHORELAX_SVAER,OHORELAX_SVDST,OHORELAX_SVSLT, &
                OHORELAX_SVPP,OHORELAX_SVCS,  OHORELAX_SVCHIC,                &
+#ifdef MNH_FOREFIRE
+               OHORELAX_SVFF,                                                &
+#endif
                PRIMKMAX,KRIMX,KRIMY,PALKTOP,PALKGRD,PALZBOT,PALZBAS,         &
                PT4DIFU,PT4DIFTH,PT4DIFSV,                                    &
                PCORIOX,PCORIOY,PCORIOZ,PCURVX,PCURVY,                        &
@@ -85,6 +88,10 @@ LOGICAL,             INTENT(IN):: OHORELAX_SVSLT  ! switch for the
                        ! horizontal relaxation for slt variables
 LOGICAL,             INTENT(IN):: OHORELAX_SVPP   ! switch for the 
                        ! horizontal relaxation for passive pollutants
+#ifdef MNH_FOREFIRE
+LOGICAL,             INTENT(IN):: OHORELAX_SVFF   ! switch for the 
+                       ! horizontal relaxation for ForeFire variables
+#endif
 LOGICAL,             INTENT(IN):: OHORELAX_SVCS   ! switch for the 
                        ! horizontal relaxation for conditional sampling
 REAL,                    INTENT(IN)    :: PRIMKMAX !Max. value of the horiz.
@@ -177,6 +184,9 @@ SUBROUTINE INI_DYNAMICS(HLUOUT,PLON,PLAT,PRHODJ,PTHVREF,PMAP,PZZ,            &
                OHORELAX_SVC2R2,OHORELAX_SVC1R3,OHORELAX_SVELEC,OHORELAX_SVLG,&
                OHORELAX_SVCHEM,OHORELAX_SVAER,OHORELAX_SVDST,OHORELAX_SVSLT, &
                OHORELAX_SVPP,OHORELAX_SVCS,  OHORELAX_SVCHIC,                &
+#ifdef MNH_FOREFIRE
+               OHORELAX_SVFF,                                                &
+#endif
                PRIMKMAX,KRIMX,KRIMY,PALKTOP,PALKGRD,PALZBOT,PALZBAS,         &
                PT4DIFU,PT4DIFTH,PT4DIFSV,                                    &
                PCORIOX,PCORIOY,PCORIOZ,PCURVX,PCURVY,                        &
@@ -266,6 +276,7 @@ SUBROUTINE INI_DYNAMICS(HLUOUT,PLON,PLAT,PRHODJ,PTHVREF,PMAP,PZZ,            &
 !!      Modification    16/01/95  (J.Stein) conditional CALL to trid for 1D case
 !!      Modification    13/08/98  (N.Asencio) add parallel code
 !!      Modification    20/05/06  Remove KEPS
+!!      Modification    07/2013   (Bosseur & Filippi) Adds Forefire
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -345,6 +356,10 @@ LOGICAL,             INTENT(IN):: OHORELAX_SVSLT  ! switch for the
                        ! horizontal relaxation for slt variables
 LOGICAL,             INTENT(IN):: OHORELAX_SVPP   ! switch for the 
                        ! horizontal relaxation for passive pollutants
+#ifdef MNH_FOREFIRE
+LOGICAL,             INTENT(IN):: OHORELAX_SVFF   ! switch for the 
+                       ! horizontal relaxation for ForeFire variables
+#endif
 LOGICAL,             INTENT(IN):: OHORELAX_SVCS   ! switch for the 
                        ! horizontal relaxation for conditional sampling
 REAL,                    INTENT(IN)    :: PRIMKMAX !Max. value of the horiz.
@@ -433,7 +448,11 @@ INTEGER                                    :: ILUOUT,IRESP ! Logical unit number
 INTEGER                                    :: IIU,IJU !  Upper bounds in x,y directions
 LOGICAL                                    :: GHORELAX
 LOGICAL, DIMENSION(7) :: GHORELAXR ! local array of logical
+#ifdef MNH_FOREFIRE
+LOGICAL, DIMENSION(12):: GHORELAXSV! local array of logical
+#else
 LOGICAL, DIMENSION(11):: GHORELAXSV! local array of logical
+#endif
 !
 !-------------------------------------------------------------------------------
 !
@@ -502,6 +521,9 @@ GHORELAXSV(8) = OHORELAX_SVSLT
 GHORELAXSV(9) = OHORELAX_SVPP
 GHORELAXSV(10)= OHORELAX_SVCS
 GHORELAXSV(11) = OHORELAX_SVCHIC
+#ifdef MNH_FOREFIRE
+GHORELAXSV(12) = OHORELAX_SVFF
+#endif
 !
 GHORELAX=ANY(GHORELAXR) .OR. ANY(GHORELAXSV) .OR. ANY(OHORELAX_SV) &
                         .OR. OHORELAX_UVWTH  .OR. OHORELAX_TKE 
index 8e0b3fd..b92924f 100644 (file)
@@ -124,6 +124,7 @@ SUBROUTINE INI_LB(HINIFILE,HLUOUT,OLSOURCE,KSV,                    &
 !!                      20/05/06    Remove KEPS
 !!      C.Lac           20/03/08    Add passive pollutants
 !!      M.Leriche       16/07/10    Add ice phase chemical species
+!!      Pialat/tulet    15/02/12    Add ForeFire scalars 
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -1098,6 +1099,53 @@ DO JSV = NSV_PPBEG, NSV_PPEND
     IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
   END SELECT
 END DO
+#ifdef MNH_FOREFIRE
+! ForeFire scalar variables
+DO JSV = NSV_FFBEG, NSV_FFEND
+  SELECT CASE(HGETSVM(JSV))
+  CASE ('READ')
+    IF ( KSIZELBXSV_ll /= 0 ) THEN
+      YRECFM = 'LBX_FF'
+      YDIRLB='LBX'
+      CALL FMREAD_LB(HINIFILE,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
+           & IGRID,ILENCH,YCOMMENT,IRESP)
+       WRITE(ILUOUT,*) 'ForeFire LBX_FF ', IRESP
+       IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
+        IF (IRESP/=0) THEN
+          IF (PRESENT(PLBXSVMM)) THEN
+            PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
+            WRITE(ILUOUT,*) 'ForeFire pollutant PLBXSVM   will be initialized to 0'
+          ELSE
+            PLBXSVM(:,:,:,JSV)=0.
+            WRITE(ILUOUT,*) 'ForeFire pollutant PLBXSVM   will be initialized to 0'
+          ENDIF
+        END IF
+      END IF
+    END IF
+!
+    IF (KSIZELBYSV_ll  /= 0 ) THEN
+      YRECFM = 'LBY_FF'
+      YDIRLB='LBY'
+      CALL FMREAD_LB(HINIFILE,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
+           & IGRID,ILENCH,YCOMMENT,IRESP)
+      IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
+        IF (IRESP/=0) THEN
+          IF (PRESENT(PLBYSVMM)) THEN
+            PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
+            WRITE(ILUOUT,*) 'ForeFire scalar variable PLBYSVM will be initialized to 0'
+          ELSE
+            PLBYSVM(:,:,:,JSV)=0.
+            WRITE(ILUOUT,*) 'ForeFire scalar variable PLBYSVM will be initialized to 0'
+          ENDIF
+        END IF
+      END IF
+    END IF
+  CASE('INIT')
+    IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
+    IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
+  END SELECT
+END DO
+#endif
 ! Conditional sampling variables
 DO JSV = NSV_CSBEG, NSV_CSEND
   SELECT CASE(HGETSVM(JSV))
index 83c1013..e4c1e90 100644 (file)
@@ -257,6 +257,7 @@ END MODULE MODI_INI_MODEL_n
 !!                   June  2011  (B.Aouizerats) Prognostic aerosols
 !!                   June  2011  (P.Aumond) Drag of the vegetation  
 !!                                         + Mean fields
+!!                   July  2013  (Bosseur & Filippi) Adds Forefire
 !---------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -384,6 +385,11 @@ USE MODI_INI_AEROSET4
 USE MODI_INI_AEROSET5
 USE MODI_INI_AEROSET6
 !
+#ifdef MNH_FOREFIRE
+USE MODD_FOREFIRE
+USE MODD_FOREFIRE_n
+USE MODI_INIT_FOREFIRE_n
+#endif
 USE MODI_INI_LES_N
 USE MODI_GOTO_SURFEX
 USE MODI_INI_SERIES_N
@@ -1743,6 +1749,9 @@ CALL INI_DYNAMICS(HLUOUT,XLON,XLAT,XRHODJ,XTHVREF,XMAP,XZZ,XDXHAT,XDYHAT,     &
              LHORELAX_SVC2R2,LHORELAX_SVC1R3,LHORELAX_SVELEC,LHORELAX_SVLG,   &
              LHORELAX_SVCHEM,LHORELAX_SVAER,LHORELAX_SVDST,LHORELAX_SVSLT,    &
              LHORELAX_SVPP,LHORELAX_SVCS,LHORELAX_SVCHIC,                     &
+#ifdef MNH_FOREFIRE
+             LHORELAX_SVFF,                                                   &
+#endif
              XRIMKMAX,NRIMX,NRIMY,                                            &
              XALKTOP,XALKGRD,XALZBOT,XALZBAS,                                 &
              XT4DIFU,XT4DIFTH,XT4DIFSV,                                       &
@@ -2058,6 +2067,29 @@ CALL INI_AEROSET3
 CALL INI_AEROSET4
 CALL INI_AEROSET5
 CALL INI_AEROSET6
+#ifdef MNH_FOREFIRE
+! 
+!-------------------------------------------------------------------------------
 !
+!*      29.    FOREFIRE initializations
+!              ------------------------
+!
+
+! Coupling with ForeFire if resolution is low enough
+!---------------------------------------------------
+IF ( LFOREFIRE .AND. 0.5*(XXHAT(2)-XXHAT(1)+XYHAT(2)-XYHAT(1)) < COUPLINGRES ) THEN
+       FFCOUPLING = .TRUE.     
+ELSE
+       FFCOUPLING = .FALSE.
+ENDIF
+
+! Initializing the ForeFire variables
+!------------------------------------
+IF ( LFOREFIRE ) THEN
+       CALL INIT_FOREFIRE_n(KMI, ILUOUT, IP &
+               , TDTCUR%TDATE%YEAR, TDTCUR%TDATE%MONTH, TDTCUR%TDATE%DAY, TDTCUR%TIME, XTSTEP)
+END IF
+#endif
+
 END SUBROUTINE INI_MODEL_n
 
index 62f8cd6..83d7f7f 100644 (file)
@@ -58,6 +58,7 @@ END MODULE MODI_INI_NSV
 !!      M. Chong       26/01/10   Add Small ions
 !!      Modification   07/2010   (Leriche) add SV for ice chemistry
 !!      X.Pialat & J.Escobar 11/2012 remove deprecated line NSV_A(KMI) = ISV
+!!      Modification   15/02/12  (Pialat/Tulet) Add SV for ForeFire scalars
 !!                     03/2013   (C.Lac) add supersaturation as 
 !!                               the 4th C2R2 scalar variable
 !! 
@@ -76,6 +77,10 @@ USE MODD_DYN_n,     ONLY : LHORELAX_SV,LHORELAX_SVC2R2,LHORELAX_SVC1R3, &
                           LHORELAX_SVELEC,LHORELAX_SVCHEM,LHORELAX_SVLG, &
                           LHORELAX_SVDST,LHORELAX_SVAER, LHORELAX_SVSLT, &
                           LHORELAX_SVPP,LHORELAX_SVCS, LHORELAX_SVCHIC
+#ifdef MNH_FOREFIRE
+USE MODD_DYN_n,     ONLY : LHORELAX_SVFF
+USE MODD_FOREFIRE
+#endif
 USE MODD_CONF,     ONLY : LLG, CPROGRAM
 USE MODD_LG
 USE MODD_DUST
@@ -386,6 +391,23 @@ ELSE
   NSV_PPEND_A(KMI)= 0
 END IF
 !
+#ifdef MNH_FOREFIRE
+
+! ForeFire tracers
+IF (LFOREFIRE .AND. NFFSCALARS .GT. 0) THEN
+  NSV_FF_A(KMI)    = NFFSCALARS
+  NSV_FFBEG_A(KMI) = ISV+1
+  NSV_FFEND_A(KMI) = ISV+NSV_FF_A(KMI)
+  ISV              = NSV_FFEND_A(KMI)
+ELSE
+  NSV_FF_A(KMI)   = 0
+! force First index to be superior to last index
+! in order to create a null section
+  NSV_FFBEG_A(KMI)= 1
+  NSV_FFEND_A(KMI)= 0
+END IF
+#endif
+!
 IF (LCONDSAMP) THEN
   NSV_CS_A(KMI)   = NCONDSAMP
   NSV_CSBEG_A(KMI)= ISV+1
@@ -438,6 +460,11 @@ LHORELAX_SV(NSV_LGBEG_A(KMI):NSV_LGEND_A(KMI))=LHORELAX_SVLG
 ! Passive pollutants  
 IF (LPASPOL) &
 LHORELAX_SV(NSV_PPBEG_A(KMI):NSV_PPEND_A(KMI))=LHORELAX_SVPP
+#ifdef MNH_FOREFIRE
+! Fire pollutants
+IF (LFOREFIRE) &
+LHORELAX_SV(NSV_FFBEG_A(KMI):NSV_FFEND_A(KMI))=LHORELAX_SVFF
+#endif
 ! Conditional sampling
 IF (LCONDSAMP) &
 LHORELAX_SV(NSV_CSBEG_A(KMI):NSV_CSEND_A(KMI))=LHORELAX_SVCS
@@ -474,7 +501,10 @@ IF ((LSALT).AND.(LDEPOS_SLT(KMI))) &
 XSVMIN(NSV_SLTDEPBEG_A(KMI):NSV_SLTDEPEND_A(KMI))=XMNH_TINY
 IF ((LORILAM).AND.(LDEPOS_AER(KMI))) &
 XSVMIN(NSV_AERDEPBEG_A(KMI):NSV_AERDEPEND_A(KMI))=XMNH_TINY
-IF (LPASPOL) XSVMIN(NSV_PPBEG_A(KMI):NSV_PPEND_A(KMI))=0.          
+IF (LPASPOL) XSVMIN(NSV_PPBEG_A(KMI):NSV_PPEND_A(KMI))=0.    
+#ifdef MNH_FOREFIRE      
+IF (LFOREFIRE) XSVMIN(NSV_FFBEG_A(KMI):NSV_FFEND_A(KMI))=0.
+#endif
 IF (LCONDSAMP) XSVMIN(NSV_CSBEG_A(KMI):NSV_CSEND_A(KMI))=0.          
 !
 !  NAME OF THE SCALAR VARIABLES IN THE DIFFERENT SV GROUPS
index a9b8e45..bad3b6c 100644 (file)
@@ -140,6 +140,7 @@ SUBROUTINE INI_ONE_WAY_n(KDAD,HLUOUT,PTSTEP,KMI,KTCOUNT,                 &
 !!    Modification   05/2006   Remove KEPS
 !!    M. Leriche     11/2009  modify the LB*SVS for the aqueous phase chemistry
 !!                   07/2010  idem for ice phase chemical species
+!!    Bosseur & Filippi 07/2013 Adds Forefire
 !!
 !------------------------------------------------------------------------------
 !
@@ -494,6 +495,13 @@ DO JSV=1,NSV_PP_A(KMI)
   CALL SET_LSFIELD_1WAY_ll(XSVT(:,:,:,JSV-1+NSV_PPBEG_A(KDAD)),&
        &ZTSVM(:,:,:,JSV-1+NSV_PPBEG_A(KMI)),KMI)
 END DO
+#ifdef MNH_FOREFIRE
+! ForeFire variables      
+DO JSV=1,NSV_FF_A(KMI)
+  CALL SET_LSFIELD_1WAY_ll(XSVT(:,:,:,JSV-1+NSV_FFBEG_A(KDAD)),&
+       &ZTSVM(:,:,:,JSV-1+NSV_FFBEG_A(KMI)),KMI)
+END DO
+#endif
 !        1.4  Communication
 !
 CALL LS_FORCING_ll(KMI,IINFO_ll)
index 011e3a4..a29d8c4 100644 (file)
@@ -158,6 +158,7 @@ END MODULE MODI_INI_SEG_n
 !!                       01/2005   add GDUST, GSALT, and GORILAM (P. Tulet)
 !!                       04/2010   add GUSECHAQ, GCH_PH (M. Leriche)
 !!                       09/2010   add GUSECHIC (M. Leriche)
+!!                       02/2012   add GFOREFIRE (Pialat/Tulet)
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -226,6 +227,9 @@ LOGICAL            :: GSALT
 LOGICAL            :: GORILAM
 LOGICAL            :: GLG
 LOGICAL            :: GPASPOL
+#ifdef MNH_FOREFIRE
+LOGICAL            :: GFOREFIRE
+#endif
 LOGICAL            :: GCONDSAMP
                                                   ! These variables
                                                   ! are used to locally store 
@@ -402,7 +406,11 @@ CALL READ_DESFM_n(KMI,YDESFM,HLUOUT,YCONF,GFLAT,GUSERV,GUSERC,              &
                 GUSERR,GUSERI,GUSECI,GUSERS,GUSERG,GUSERH,GUSECHEM,GUSECHAQ,&
                 GUSECHIC,GCH_PH,GCH_CONV_LINOX,GSALT,GDEPOS_SLT,GDUST,      &
                 GDEPOS_DST, GORILAM,  &
-                GDEPOS_AER, GLG, GPASPOL, GCONDSAMP, IRIMX,IRIMY,ISV,       &
+                GDEPOS_AER, GLG, GPASPOL, &
+#ifdef MNH_FOREFIRE
+                GFOREFIRE, &
+#endif
+                GCONDSAMP, IRIMX,IRIMY,ISV,       &
                 YTURB,YTOM,GRMC01,YRAD,YDCONV,YSCONV,YCLOUD,YELEC,YEQNSYS   )
 !
 !
@@ -418,7 +426,11 @@ CALL READ_EXSEG_n(KMI,YEXSEG,HLUOUT,YCONF,GFLAT,GUSERV,GUSERC,              &
                 GUSERR,GUSERI,GUSECI,GUSERS,GUSERG,GUSERH,GUSECHEM,         &
                 GUSECHAQ,GUSECHIC,GCH_PH,                                   &
                 GCH_CONV_LINOX,GSALT,GDEPOS_SLT,GDUST,GDEPOS_DST,           &
-                GORILAM,GDEPOS_AER,GLG,GPASPOL, GCONDSAMP, IRIMX,IRIMY,ISV, &
+                GORILAM,GDEPOS_AER,GLG,GPASPOL, &
+#ifdef MNH_FOREFIRE
+                GFOREFIRE, &
+#endif
+                GCONDSAMP, IRIMX,IRIMY,ISV, &
                 YTURB,YTOM,GRMC01,YRAD,YDCONV,YSCONV,YCLOUD,YELEC,YEQNSYS,  &
                 PTSTEP_ALL,CSTORAGE_TYPE,CINIFILEPGD_n                      )
 !
index f84826d..a7cb043 100644 (file)
@@ -176,6 +176,7 @@ END MODULE MODI_LS_COUPLING
 !!                   22/09/98   (Ducrocq) //,  and introduce INI_LS and INI_LB
 !!                   01/2004    (Masson) removes SST forcing (surface externalization)
 !!                   05/2006    Remove KEPS
+!!                   2/2014     (escobar) add paspol for Forefire
 !! 
 !------------------------------------------------------------------------------
 !
@@ -187,6 +188,9 @@ USE MODD_CTURB
 USE MODD_DYN
 USE MODD_LUNIT_n
 USE MODD_NSV
+#ifdef MNH_FOREFIRE
+USE MODD_PASPOL
+#endif
 USE MODD_CH_MNHC_n
 !
 USE MODE_FMREAD
@@ -326,6 +330,9 @@ GLSOURCE=.TRUE.
 !IF ( LUSECHEM .AND. (.NOT. OCH_INIT_FIELD) ) &
 !    YGETSVM(NSV_CHEMBEG: NSV_CHEMEND) = 'INIT'
 !IF (HCONF == 'RESTA')  THEN
+#ifdef MNH_FOREFIRE
+!   IF (LPASPOL) YGETSVM(NSV_PPBEG: NSV_PPEND) = 'INIT'
+#endif
 !   IF (NSV_USER /= 0) YGETSVM(1/NSV_USER) = 'INIT'
 !   IF (NSV_C2R2 /= 0) YGETSVM(NSV_C2R2BEG: NSV_C2R2END) = 'INIT'
 !   IF (NSV_C1R3 /= 0) YGETSVM(NSV_C1R3BEG: NSV_C1R3END) = 'INIT'
@@ -338,6 +345,9 @@ GLSOURCE=.TRUE.
 !   IF (NSV_SLTDEP /= 0) YGETSVM(NSV_SLTDEPBEG: NSV_SLTDEPEND) = 'INIT'
 !   IF (NSV_PP   /= 0) YGETSVM(NSV_PPBEG: NSV_PPEND) = 'INIT'
 !   IF (NSV_CS   /= 0) YGETSVM(NSV_CSBEG: NSV_CSEND) = 'INIT'
+#ifdef MNH_FOREFIRE
+!   IF (NSV_FF   /= 0) YGETSVM(NSV_FFBEG: NSV_FFEND) = 'INIT'
+#endif
 !END IF
 !
 CALL INI_LB(CCPLFILE(NCPL_CUR),HLUOUT,GLSOURCE,KSV,                   &
index aa00d66..d89a601 100644 (file)
@@ -132,6 +132,9 @@ TYPE DYN_t
   LOGICAL :: LHORELAX_SVSLT
   LOGICAL :: LHORELAX_SVAER
   LOGICAL :: LHORELAX_SVPP 
+#ifdef MNH_FOREFIRE
+  LOGICAL :: LHORELAX_SVFF
+#endif
   LOGICAL :: LHORELAX_SVCS 
   LOGICAL, DIMENSION(:),POINTER :: LHORELAX_SV =>NULL()
 !
@@ -217,6 +220,9 @@ LOGICAL, POINTER :: LHORELAX_SVDST=>NULL()
 LOGICAL, POINTER :: LHORELAX_SVSLT=>NULL()
 LOGICAL, POINTER :: LHORELAX_SVAER=>NULL()
 LOGICAL, POINTER :: LHORELAX_SVPP=>NULL()
+#ifdef MNH_FOREFIRE
+LOGICAL, POINTER :: LHORELAX_SVFF=>NULL()
+#endif
 LOGICAL, POINTER :: LHORELAX_SVCS=>NULL()
 LOGICAL, DIMENSION(:), POINTER :: LHORELAX_SV=>NULL()
 REAL, POINTER :: XRIMKMAX=>NULL()
@@ -320,6 +326,9 @@ LHORELAX_SVDST=>DYN_MODEL(KTO)%LHORELAX_SVDST
 LHORELAX_SVSLT=>DYN_MODEL(KTO)%LHORELAX_SVSLT
 LHORELAX_SVAER=>DYN_MODEL(KTO)%LHORELAX_SVAER
 LHORELAX_SVPP=>DYN_MODEL(KTO)%LHORELAX_SVPP
+#ifdef MNH_FOREFIRE
+LHORELAX_SVFF=>DYN_MODEL(KTO)%LHORELAX_SVFF
+#endif
 LHORELAX_SVCS=>DYN_MODEL(KTO)%LHORELAX_SVCS
 LHORELAX_SV=>DYN_MODEL(KTO)%LHORELAX_SV
 XRIMKMAX=>DYN_MODEL(KTO)%XRIMKMAX
index 27a9dfa..2c0fc55 100644 (file)
@@ -24,6 +24,7 @@
 !!       M. Leriche    12/04/07 add aqueous chemistry
 !!       M. Leriche    08/07/10 add ice phase chemistry
 !!       C.Lac         07/11    add conditional sampling
+!!       Pialat/Tulet  15/02/12 add ForeFire
 !!
 !-------------------------------------------------------------------------------
 !
@@ -112,7 +113,12 @@ INTEGER,DIMENSION(JPMODELMAX)::NSV_PPEND_A = 0 ! NSV_PPBEG_A...NSV_PPEND_A
 INTEGER,DIMENSION(JPMODELMAX)::NSV_CS_A = 0    ! number of condit.samplings
 INTEGER,DIMENSION(JPMODELMAX)::NSV_CSBEG_A = 0 ! with indices in the range :
 INTEGER,DIMENSION(JPMODELMAX)::NSV_CSEND_A = 0 ! NSV_CSBEG_A...NSV_CSEND_A
-
+!
+#ifdef MNH_FOREFIRE
+INTEGER,DIMENSION(JPMODELMAX)::NSV_FF_A = 0    ! number of ForeFire scalar variables
+INTEGER,DIMENSION(JPMODELMAX)::NSV_FFBEG_A = 0 ! with indices in the range :
+INTEGER,DIMENSION(JPMODELMAX)::NSV_FFEND_A = 0 ! NSV_FFBEG_A...NSV_FFEND_A
+#endif
 !
 !###############################################################################
 !
@@ -190,5 +196,11 @@ INTEGER :: NSV_PPEND = 0 ! NSV_PPBEG...NSV_PPEND
 INTEGER :: NSV_CS    = 0 ! number of condit.samplings         
 INTEGER :: NSV_CSBEG = 0 ! with indices in the range :
 INTEGER :: NSV_CSEND = 0 ! NSV_CSBEG...NSV_CSEND
+!
+#ifdef MNH_FOREFIRE
+INTEGER :: NSV_FF    = 0 ! number of ForeFire scalar variables
+INTEGER :: NSV_FFBEG = 0 ! with indices in the range :
+INTEGER :: NSV_FFEND = 0 ! NSV_FFBEG...NSV_FFEND
+#endif
 
 END MODULE MODD_NSV
index db9bc86..1337404 100644 (file)
@@ -1167,6 +1167,11 @@ END DO
 DO JSV = NSV_PPBEG,NSV_PPEND
   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
 END DO
+#ifdef MNH_FOREFIRE
+DO JSV = NSV_FFBEG,NSV_FFEND
+  XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
+END DO
+#endif
 DO JSV = NSV_CSBEG,NSV_CSEND
   XRSVS(:,:,:,JSV) = MAX(XRSVS(:,:,:,JSV),0.)
 END DO
@@ -1207,7 +1212,11 @@ IF(LVE_RELAX .OR. LVE_RELAX_GRD .OR. LHORELAX_UVWTH .OR. LHORELAX_RV .OR.&
                    LHORELAX_SVELEC,LHORELAX_SVLG,                      &
                    LHORELAX_SVCHEM,LHORELAX_SVCHIC,LHORELAX_SVAER,     &
                    LHORELAX_SVDST,LHORELAX_SVSLT,LHORELAX_SVPP,        &
-                   LHORELAX_SVCS, KTCOUNT,NRR,NSV,XTSTEP,XRHODJ,       &
+                   LHORELAX_SVCS,                                      &
+#ifdef MNH_FOREFIRE
+                   LHORELAX_SVFF,                                      &
+#endif
+                   KTCOUNT,NRR,NSV,XTSTEP,XRHODJ,                      &
                    XUT, XVT, XWT, XTHT, XRT, XSVT, XTKET,              &
                    XLSUM, XLSVM, XLSWM, XLSTHM,                        &
                    XLBXUM, XLBXVM, XLBXWM, XLBXTHM,                    &
@@ -1378,6 +1387,13 @@ IF (.NOT. LSTEADYLS) THEN
         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
       ENDDO
       !
+#ifdef MNH_FOREFIRE
+      DO JSV=NSV_FFBEG,NSV_FFEND
+        XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
+        XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
+      ENDDO
+      !
+#endif
       DO JSV=NSV_CSBEG,NSV_CSEND
         XLBXSVS(:,:,:,JSV)=MAX(XLBXSVS(:,:,:,JSV),0.)
         XLBYSVS(:,:,:,JSV)=MAX(XLBYSVS(:,:,:,JSV),0.)
index d5d5756..f43e058 100644 (file)
@@ -54,6 +54,7 @@
 !!      Modifications 16/07/10  (Leriche) add LHORELAX_SVCHIC 
 !!      Modifications 09/06/11  (Barthe)  add LHORELAX_SVELEC in namelist
 !!      Modifications 15/06/11  (Lac)     add LHORELAX for conditional sampling
+!!      Modifications 12/02/12  (Pialat/Tulet) add LHORELAX_SVFF for ForeFire scalar variables
 !-------------------------------------------------------------------------------
 !
 !*       0.   DECLARATIONS
@@ -84,6 +85,9 @@ USE MODD_DYN_n, ONLY : &
          LHORELAX_SVCHIC_n => LHORELAX_SVCHIC, &
          LHORELAX_SVLG_n => LHORELAX_SVLG, &
          LHORELAX_SVPP_n => LHORELAX_SVPP, &
+#ifdef MNH_FOREFIRE
+         LHORELAX_SVFF_n => LHORELAX_SVFF, &
+#endif
          LHORELAX_SVCS_n => LHORELAX_SVCS, &
          LHORELAX_SVDST_n => LHORELAX_SVDST, &
          LHORELAX_SVSLT_n => LHORELAX_SVSLT, &
@@ -123,6 +127,9 @@ LOGICAL, SAVE  :: LHORELAX_SVCHEM
 LOGICAL, SAVE  :: LHORELAX_SVCHIC
 LOGICAL, SAVE  :: LHORELAX_SVLG
 LOGICAL, SAVE  :: LHORELAX_SVPP
+#ifdef MNH_FOREFIRE
+LOGICAL, SAVE  :: LHORELAX_SVFF
+#endif
 LOGICAL, SAVE  :: LHORELAX_SVCS
 LOGICAL, SAVE  :: LHORELAX_SVDST
 LOGICAL, SAVE  :: LHORELAX_SVSLT
@@ -144,6 +151,9 @@ NAMELIST/NAM_DYNn/XTSTEP,CPRESOPT,NITR,LITRADJ,LRES,XRES,XRELAX,LHORELAX_UVWTH,
                   LHORELAX_SVCHEM, LHORELAX_SVCHIC, LHORELAX_SVLG, LHORELAX_SVDST, &
                   LHORELAX_SVSLT, LHORELAX_SVAER, LHORELAX_SVPP, &
                   LHORELAX_SVCS, LHORELAX_SV,LVE_RELAX,LVE_RELAX_GRD,&
+#ifdef MNH_FOREFIRE
+                  LHORELAX_SVFF, &
+#endif
                   NRIMX,NRIMY,XRIMKMAX,XT4DIFU, &
                   XT4DIFTH,XT4DIFSV
 !
@@ -173,6 +183,9 @@ SUBROUTINE INIT_NAM_DYNn
   LHORELAX_SVELEC = LHORELAX_SVELEC_n
   LHORELAX_SVLG = LHORELAX_SVLG_n
   LHORELAX_SVPP = LHORELAX_SVPP_n
+#ifdef MNH_FOREFIRE
+  LHORELAX_SVFF = LHORELAX_SVFF_n
+#endif
   LHORELAX_SVCS = LHORELAX_SVCS_n
   LHORELAX_SVDST = LHORELAX_SVDST_n
   LHORELAX_SVSLT = LHORELAX_SVSLT_n
@@ -212,6 +225,9 @@ SUBROUTINE UPDATE_NAM_DYNn
   LHORELAX_SVELEC_n = LHORELAX_SVELEC
   LHORELAX_SVLG_n = LHORELAX_SVLG
   LHORELAX_SVPP_n = LHORELAX_SVPP
+#ifdef MNH_FOREFIRE
+  LHORELAX_SVFF_n = LHORELAX_SVFF
+#endif
   LHORELAX_SVCS_n = LHORELAX_SVCS
   LHORELAX_SVDST_n = LHORELAX_SVDST
   LHORELAX_SVSLT_n = LHORELAX_SVSLT
index 8af8c96..1160f2e 100644 (file)
@@ -188,6 +188,7 @@ SUBROUTINE ONE_WAY_n(KDAD,HLUOUT,PTSTEP,KMI,KTCOUNT,                     &
 !!                   05/2006  Remove EPS
 !!    M. Leriche     11/2009  modify the LB*SVS for the aqueous phase chemistry
 !!                   07/2010  idem for ice phase chemical species
+!!    Bosseur & Filippi 07/2013 Adds Forefire
 !------------------------------------------------------------------------------
 !
 !*      0.   DECLARATIONS
@@ -572,6 +573,16 @@ DO JSV=1,NSV_PP_A(KMI)
   CALL SET_LSFIELD_1WAY_ll(XSVT(:,:,:,JSV-1+NSV_PPBEG_A(KDAD)),&
        &ZTSVT(:,:,:,JSV-1+NSV_PPBEG_A(KMI)),KMI)
 END DO
+#ifdef MNH_FOREFIRE
+
+!
+! ForeFire variables     
+!
+DO JSV=1,NSV_FF_A(KMI)
+  CALL SET_LSFIELD_1WAY_ll(XSVT(:,:,:,JSV-1+NSV_FFBEG_A(KDAD)),&
+       &ZTSVT(:,:,:,JSV-1+NSV_FFBEG_A(KMI)),KMI)
+END DO
+#endif
 !
 ! Conditional sampling  
 !
index 2147c32..97ba53e 100644 (file)
 !!                  Aou   09, 2005 (D.Barbary) add CDADATMFILE CDADBOGFILE
 !!                   May   2006    Remove KEPS
 !!                  Mar   2012    Add NAM_NCOUT for netcdf output
+!!                  July  2013     (Bosseur & Filippi) Adds Forefire
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -769,6 +770,9 @@ LHORELAX_SVDST  = (NSV_DST > 0)
 LHORELAX_SVSLT  = (NSV_SLT > 0)
 LHORELAX_SVAER  = (NSV_AER > 0)
 LHORELAX_SVPP   = (NSV_PP > 0)
+#ifdef MNH_FOREFIRE
+LHORELAX_SVFF   = (NSV_FF > 0)
+#endif
 LHORELAX_SVCS   = (NSV_CS > 0)
 
 LHORELAX_SVLG   = .FALSE.
index 084cbaf..953cd20 100644 (file)
@@ -17,7 +17,12 @@ INTERFACE
                    OUSERC,OUSERR,OUSERI,OUSECI,OUSERS,OUSERG,OUSERH,             &
                    OUSECHEM,OUSECHAQ,OUSECHIC,OCH_PH,OCH_CONV_LINOX,OSALT,       &
                    ODEPOS_SLT,ODUST,ODEPOS_DST,                                  &
-                   OORILAM,ODEPOS_AER,OLG,OPASPOL,OCONDSAMP,KRIMX,KRIMY,KSV_USER,&
+                   OORILAM,ODEPOS_AER,OLG,OPASPOL,                               &
+#ifdef MNH_FOREFIRE
+                   OFOREFIRE,                                                    &
+#endif
+                   OCONDSAMP,                                                    &
+                   KRIMX,KRIMY,KSV_USER,                                         &
                    HTURB,HTOM,ORMC01,HRAD,HDCONV,HSCONV,HCLOUD,HELEC,HEQNSYS     )
 USE MODD_PARAMETERS
 INTEGER,            INTENT(IN)  :: KMI    ! Model index
@@ -42,6 +47,9 @@ LOGICAL,            INTENT(OUT) :: OLG      ! lagrangian flag
 LOGICAL,            INTENT(OUT) :: OSALT    ! Sea Salt flag
 LOGICAL,            INTENT(OUT) :: ODUST    ! Dust flag
 LOGICAL,            INTENT(OUT) :: OPASPOL  ! Passive pollutant flag
+#ifdef MNH_FOREFIRE
+LOGICAL,            INTENT(OUT) :: OFOREFIRE! ForeFire flag
+#endif
 LOGICAL,            INTENT(OUT) :: OCONDSAMP! Conditional sampling flag
 LOGICAL,            INTENT(OUT) :: OORILAM  ! Orilam flag
 LOGICAL,DIMENSION(JPMODELMAX),INTENT(OUT) :: ODEPOS_DST    ! Dust Wet Deposition flag
@@ -71,7 +79,12 @@ END MODULE MODI_READ_DESFM_n
                    OUSERC,OUSERR,OUSERI,OUSECI,OUSERS,OUSERG,OUSERH,             &
                    OUSECHEM,OUSECHAQ,OUSECHIC,OCH_PH,OCH_CONV_LINOX,OSALT,       &
                    ODEPOS_SLT,ODUST,ODEPOS_DST,                                  &
-                   OORILAM,ODEPOS_AER,OLG,OPASPOL,OCONDSAMP,KRIMX,KRIMY,KSV_USER,&
+                   OORILAM,ODEPOS_AER,OLG,OPASPOL,                               &
+#ifdef MNH_FOREFIRE
+                   OFOREFIRE,                                                    &
+#endif
+                   OCONDSAMP,                                                    &
+                   KRIMX,KRIMY,KSV_USER,                                         &
                    HTURB,HTOM,ORMC01,HRAD,HDCONV,HSCONV,HCLOUD,HELEC,HEQNSYS     )
 !     #########################################################################
 !
@@ -171,6 +184,7 @@ END MODULE MODI_READ_DESFM_n
 !!      Modification   03/2005   (Tulet)  add dust, aerosols
 !!      Modification   03/2006   (O.Geoffroy) Add KHKO scheme
 !!      Modification   04/2010   (M. Leriche) Add aqueous + ice chemistry
+!!      Modification   07/2013   (Bosseur & Filippi) Adds Forefire
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -209,6 +223,9 @@ USE MODN_CH_ORILAM
 USE MODN_DUST
 USE MODN_SALT
 USE MODN_PASPOL
+#ifdef MNH_FOREFIRE
+USE MODN_FOREFIRE
+#endif
 USE MODN_CONDSAMP
 USE MODN_LATZ_EDFLX
 USE MODN_2D_FRC
@@ -258,6 +275,9 @@ CHARACTER (LEN=4),  INTENT(OUT) :: HELEC  ! Kind of electrical scheme
 CHARACTER (LEN=*),  INTENT(OUT) :: HEQNSYS! type of equations' system
 LOGICAL,            INTENT(OUT) :: OSALT    ! Sea Salt flag
 LOGICAL,            INTENT(OUT) :: OPASPOL  ! Passive pollutant flag
+#ifdef MNH_FOREFIRE
+LOGICAL,            INTENT(OUT) :: OFOREFIRE ! ForeFire flag
+#endif
 LOGICAL,            INTENT(OUT) :: OCONDSAMP! Conditional sampling flag
 LOGICAL,            INTENT(OUT) :: ODUST    ! Dust flag
 LOGICAL,            INTENT(OUT) :: OORILAM  ! Dust flag
@@ -440,6 +460,10 @@ IF (KMI == 1) THEN
   IF (GFOUND) READ(UNIT=ILUDES,NML=NAM_SALT)
   CALL POSNAM(ILUDES,'NAM_PASPOL',GFOUND,ILUOUT)
   IF (GFOUND) READ(UNIT=ILUDES,NML=NAM_PASPOL)
+#ifdef MNH_FOREFIRE
+  CALL POSNAM(ILUDES,'NAM_FOREFIRE',GFOUND,ILUOUT)
+  IF (GFOUND) READ(UNIT=ILUDES,NML=NAM_FOREFIRE)
+#endif
   CALL POSNAM(ILUDES,'NAM_CONDSAMP',GFOUND,ILUOUT)
   IF (GFOUND) READ(UNIT=ILUDES,NML=NAM_CONDSAMP)
   CALL POSNAM(ILUDES,'NAM_2D_FRC',GFOUND,ILUOUT)
@@ -478,6 +502,9 @@ OSALT    = LSALT
 OORILAM  = LORILAM
 OLG      = LLG
 OPASPOL  = LPASPOL
+#ifdef MNH_FOREFIRE
+OFOREFIRE  = LFOREFIRE
+#endif
 OCONDSAMP= LCONDSAMP
 KRIMX  = NRIMX
 KRIMY  = NRIMY
@@ -619,6 +646,11 @@ IF (NVERB >= 10) THEN
     WRITE(UNIT=ILUOUT,FMT="('************ PASSIVE POLLUTANT  ***************')")
     WRITE(UNIT=ILUOUT,NML=NAM_PASPOL)
 !
+#ifdef MNH_FOREFIRE
+       WRITE(UNIT=ILUOUT,FMT="('************ FOREFIRE  ***************')")
+       WRITE(UNIT=ILUOUT,NML=NAM_FOREFIRE)
+!
+#endif         
     WRITE(UNIT=ILUOUT,FMT="('************ CONDITIONAL SAMPLING *************')")
     WRITE(UNIT=ILUOUT,NML=NAM_CONDSAMP)
 !
index 9be08b1..5690d0e 100644 (file)
@@ -18,7 +18,12 @@ INTERFACE
                    OUSERC,OUSERR,OUSERI,OUSECI,OUSERS,OUSERG,OUSERH,               &
                    OUSECHEM,OUSECHAQ,OUSECHIC,OCH_PH,OCH_CONV_LINOX,OSALT,         &
                    ODEPOS_SLT, ODUST,ODEPOS_DST,                                   &
-                   OORILAM,ODEPOS_AER, OLG,OPASPOL,OCONDSAMP,KRIMX,KRIMY, KSV_USER,&   
+                   OORILAM,ODEPOS_AER, OLG,OPASPOL,                                &
+#ifdef MNH_FOREFIRE
+                   OFOREFIRE,                                                      &
+#endif
+                   OCONDSAMP,                                                      &
+                   KRIMX,KRIMY, KSV_USER,                                          &
                    HTURB,HTOM,ORMC01,HRAD,HDCONV,HSCONV,HCLOUD,HELEC,              &
                    HEQNSYS,PTSTEP_ALL,HSTORAGE_TYPE,HINIFILEPGD                    )
 INTEGER,            INTENT(IN) :: KMI    ! Model index
@@ -44,6 +49,9 @@ LOGICAL,DIMENSION(:), INTENT(IN)  :: ODEPOS_AER  ! Orilam wet deposition FLAG in
 LOGICAL,            INTENT(IN) :: OSALT          ! Sea Salt FLAG in FMFILE
 LOGICAL,            INTENT(IN) :: OORILAM        ! Orilam FLAG in FMFILE
 LOGICAL,            INTENT(IN) :: OPASPOL        ! Passive pollutant FLAG in FMFILE
+#ifdef MNH_FOREFIRE
+LOGICAL,            INTENT(IN) :: OFOREFIRE      ! ForeFire FLAG in FMFILE
+#endif
 LOGICAL,            INTENT(IN) :: OCONDSAMP      ! Conditional sampling FLAG in FMFILE
 
 LOGICAL,            INTENT(IN) :: OLG            ! lagrangian FLAG in FMFILE
@@ -77,7 +85,12 @@ END MODULE MODI_READ_EXSEG_n
                    OUSERC,OUSERR,OUSERI,OUSECI,OUSERS,OUSERG,OUSERH,               &
                    OUSECHEM,OUSECHAQ,OUSECHIC,OCH_PH,OCH_CONV_LINOX,OSALT,         &
                    ODEPOS_SLT, ODUST,ODEPOS_DST,                                   &
-                   OORILAM,ODEPOS_AER, OLG,OPASPOL,OCONDSAMP,KRIMX,KRIMY, KSV_USER,&   
+                   OORILAM,ODEPOS_AER, OLG,OPASPOL,                                &
+#ifdef MNH_FOREFIRE
+                   OFOREFIRE,                                                      &
+#endif
+                   OCONDSAMP,                                                      &
+                   KRIMX,KRIMY, KSV_USER,                                          &
                    HTURB,HTOM,ORMC01,HRAD,HDCONV,HSCONV,HCLOUD,HELEC,              &
                    HEQNSYS,PTSTEP_ALL,HSTORAGE_TYPE,HINIFILEPGD                    )
 !     #########################################################################
@@ -258,6 +271,7 @@ END MODULE MODI_READ_EXSEG_n
 !!      Modification   09/2011   (J.Escobar) re-add 'ZRESI' choose
 !!      Modification   12/2011   (C.Lac) Adaptation to FIT temporal scheme 
 !!      Modification   12/2012   (S.Bielli) add NAM_NCOUT for netcdf output
+!!      Modification   02/2012   (Pialat/Tulet) add ForeFire
 !!------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -323,6 +337,10 @@ USE MODD_CH_AEROSOL
 USE MODD_DUST
 USE MODD_SALT
 USE MODD_PASPOL
+#ifdef MNH_FOREFIRE
+USE MODD_FOREFIRE
+USE MODN_FOREFIRE
+#endif
 USE MODD_CONDSAMP
 USE MODN_DUST
 USE MODN_SALT
@@ -360,6 +378,9 @@ LOGICAL,DIMENSION(:), INTENT(IN) :: ODEPOS_AER   ! Orilam wet deposition FLAG in
 LOGICAL,            INTENT(IN) :: OSALT          ! Sea Salt FLAG in FMFILE
 LOGICAL,            INTENT(IN) :: OORILAM        ! Orilam FLAG in FMFILE
 LOGICAL,            INTENT(IN) :: OPASPOL        ! Passive pollutant FLAG in FMFILE
+#ifdef MNH_FOREFIRE
+LOGICAL,            INTENT(IN) :: OFOREFIRE      ! ForeFire FLAG in FMFILE
+#endif
 LOGICAL,            INTENT(IN) :: OCONDSAMP      ! Conditional sampling FLAG in FMFILE
 
 LOGICAL,            INTENT(IN) :: OLG            ! lagrangian FLAG in FMFILE
@@ -517,6 +538,10 @@ IF (KMI == 1) THEN
   IF (GFOUND) READ(UNIT=ILUSEG,NML=NAM_SALT)
   CALL POSNAM(ILUSEG,'NAM_PASPOL',GFOUND,ILUOUT)
   IF (GFOUND) READ(UNIT=ILUSEG,NML=NAM_PASPOL)
+#ifdef MNH_FOREFIRE
+  CALL POSNAM(ILUSEG,'NAM_FOREFIRE',GFOUND,ILUOUT)
+  IF (GFOUND) READ(UNIT=ILUSEG,NML=NAM_FOREFIRE)
+#endif
   CALL POSNAM(ILUSEG,'NAM_CONDSAMP',GFOUND,ILUOUT)
   IF (GFOUND) READ(UNIT=ILUSEG,NML=NAM_CONDSAMP)
   CALL POSNAM(ILUSEG,'NAM_DRAGTREE',GFOUND,ILUOUT)
@@ -1639,6 +1664,27 @@ IF (LPASPOL) THEN
   END IF
 END IF
 !
+#ifdef MNH_FOREFIRE
+! ForeFire
+!
+IF (LFOREFIRE) THEN
+  IF (OFOREFIRE) THEN
+!!$    CGETSVM(NSV_FFBEG:NSV_FFEND)='READ'
+    CGETSVT(NSV_FFBEG:NSV_FFEND)='READ'
+    IF(HSTORAGE_TYPE=='TT') THEN
+      CGETSVT(NSV_FFBEG:NSV_FFEND)='INIT'
+!!$      CGETSVM(NSV_FFBEG:NSV_FFEND)='INIT'
+    END IF
+  ELSE
+    WRITE(UNIT=ILUOUT,FMT=9001) KMI
+    WRITE(UNIT=ILUOUT,FMT='("THERE IS NO FOREFIRE SCALAR VARIABLES IN INITIAL FMFILE",/,&
+                       & "THE VARIABLES HAVE BEEN INITIALIZED TO ZERO")')
+!!$    CGETSVM(NSV_FFBEG:NSV_FFEND)='INIT'
+    CGETSVT(NSV_FFBEG:NSV_FFEND)='INIT'
+  END IF
+END IF
+#endif
+!
 ! Conditional sampling case
 !
 IF (LCONDSAMP) THEN
@@ -2115,7 +2161,14 @@ IF (.NOT. LPASPOL .AND. LHORELAX_SVPP) THEN
   WRITE(ILUOUT,FMT=*) 'YOU WANT TO RELAX PASSIVE POLLUTANT FIELD BUT IT DOES NOT EXIST.'
   WRITE(ILUOUT,FMT=*) 'THEREFORE LHORELAX_SVPP=FALSE'
 END IF
-
+#ifdef MNH_FOREFIRE
+IF (.NOT. LFOREFIRE .AND. LHORELAX_SVFF) THEN
+  LHORELAX_SVFF=.FALSE.
+  WRITE(UNIT=ILUOUT,FMT=9002) KMI
+  WRITE(ILUOUT,FMT=*) 'YOU WANT TO RELAX FOREFIRE FLUXES BUT THEY DO NOT EXIST.'
+  WRITE(ILUOUT,FMT=*) 'THEREFORE LHORELAX_SVFF=FALSE'
+END IF
+#endif
 IF (.NOT. LCONDSAMP .AND. LHORELAX_SVCS) THEN
   LHORELAX_SVCS=.FALSE.
   WRITE(UNIT=ILUOUT,FMT=9002) KMI
@@ -2161,6 +2214,9 @@ IF ( (.NOT. LHORELAX_UVWTH) .AND. (.NOT.(ANY(LHORELAX_SV))) .AND.  &
      (.NOT. LHORELAX_SVELEC).AND. (.NOT. LHORELAX_SVCHEM)   .AND.  &
      (.NOT. LHORELAX_SVLG)  .AND. (.NOT. LHORELAX_SVPP)     .AND.  &
      (.NOT. LHORELAX_SVCS)  .AND.                                  &
+#ifdef MNH_FOREFIRE
+     (.NOT. LHORELAX_SVFF)  .AND.                                  &
+#endif
      (.NOT. LHORELAX_RV)    .AND. (.NOT. LHORELAX_RC)       .AND.  &
      (.NOT. LHORELAX_RR)    .AND. (.NOT. LHORELAX_RI)       .AND.  &
      (.NOT. LHORELAX_RS)    .AND. (.NOT. LHORELAX_RG)       .AND.  &
@@ -2176,6 +2232,9 @@ END IF
 !
 IF ((LHORELAX_UVWTH  .OR. LHORELAX_SVPP   .OR.  &
      LHORELAX_SVCS   .OR.                       &
+#ifdef MNH_FOREFIRE
+     LHORELAX_SVFF   .OR.                       &
+#endif
      LHORELAX_SVC2R2 .OR. LHORELAX_SVC1R3 .OR.  &
      LHORELAX_SVELEC .OR. LHORELAX_SVCHEM .OR.  &
      LHORELAX_SVLG   .OR. ANY(LHORELAX_SV) .OR. &
@@ -2196,6 +2255,9 @@ IF ((LHORELAX_UVWTH  .OR. LHORELAX_SVPP   .OR.  &
   WRITE(ILUOUT,FMT=*) "LHORELAX_SVCHIC=",LHORELAX_SVCHIC
   WRITE(ILUOUT,FMT=*) "LHORELAX_SVLG=",LHORELAX_SVLG
   WRITE(ILUOUT,FMT=*) "LHORELAX_SVPP=",LHORELAX_SVPP
+#ifdef MNH_FOREFIRE
+  WRITE(ILUOUT,FMT=*) "LHORELAX_SVFF=",LHORELAX_SVFF
+#endif
   WRITE(ILUOUT,FMT=*) "LHORELAX_SVCS=",LHORELAX_SVCS
   WRITE(ILUOUT,FMT=*) "LHORELAX_SV=",LHORELAX_SV
   WRITE(ILUOUT,FMT=*) "LHORELAX_RV=",LHORELAX_RV
@@ -2217,6 +2279,9 @@ END IF
 ! 
 IF ((LHORELAX_UVWTH  .OR. LHORELAX_SVPP  .OR.   &
      LHORELAX_SVCS   .OR.                       &
+#ifdef MNH_FOREFIRE
+     LHORELAX_SVFF   .OR.                       &
+#endif
      LHORELAX_SVC2R2 .OR. LHORELAX_SVC1R3 .OR.  &
      LHORELAX_SVELEC .OR. LHORELAX_SVCHEM .OR.  &
      LHORELAX_SVLG   .OR. ANY(LHORELAX_SV) .OR. &
index 687aad8..8c70c53 100644 (file)
@@ -223,7 +223,8 @@ END MODULE MODI_READ_FIELD
 !!          M.Tomasini, 
 !!          P. Peyrille   06/12   2D west african monsoon : add reading of ADV forcing and addy fluxes 
 !!          C.Lac       03/13     add prognostic supersaturation for C2R2/KHKO
-!-------------------------------------------------------------------------------
+!!          Bosseur & Filippi 07/13 Adds Forefire
+!!-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
 !              ------------
@@ -238,6 +239,9 @@ USE MODD_NSV
 USE MODD_DUST
 USE MODD_SALT
 USE MODD_PASPOL
+#ifdef MNH_FOREFIRE
+USE MODD_FOREFIRE
+#endif
 USE MODD_CH_AEROSOL
 USE MODD_CH_MNHC_n, ONLY : XCH_PHINIT
 !
@@ -783,6 +787,24 @@ DO JSV = NSV_PPBEG,NSV_PPEND
   END SELECT
 END DO
 !
+#ifdef MNH_FOREFIRE
+DO JSV = NSV_FFBEG,NSV_FFEND
+  SELECT CASE(HGETSVT(JSV))
+  CASE ('READ')
+    WRITE(YRECFM,'(A3,I3.3)')'SVT',JSV
+    CALL FMREAD(HINIFILE,YRECFM,HLUOUT,YDIR,Z3D,IGRID,ILENCH,  &
+         YCOMMENT,IRESP)
+    IF (IRESP == 0) THEN
+       PSVT(:,:,:,JSV) = Z3D(:,:,:)
+    ELSE
+       PSVT(:,:,:,JSV) = 0.
+    END IF
+  CASE ('INIT')
+    PSVT(:,:,:,JSV) = 0.
+  END SELECT
+END DO
+#endif
+!
 DO JSV = NSV_CSBEG,NSV_CSEND
   SELECT CASE(HGETSVT(JSV))
   CASE ('READ')
index 644ae46..687de0f 100644 (file)
@@ -17,6 +17,9 @@ INTERFACE
                              OHORELAX_SVCHEM,OHORELAX_SVCHIC, OHORELAX_SVAER,  &
                              OHORELAX_SVDST, OHORELAX_SVSLT, OHORELAX_SVPP,    &
                              OHORELAX_SVCS,                                    &
+#ifdef MNH_FOREFIRE
+                             OHORELAX_SVFF,                                    &
+#endif
                              KTCOUNT,KRR,KSV,PTSTEP,PRHODJ,                    &
                              PUT, PVT, PWT, PTHT, PRT, PSVT, PTKET,            &
                              PLSUM, PLSVM, PLSWM, PLSTHM,                      &
@@ -73,7 +76,11 @@ LOGICAL,             INTENT(IN):: OHORELAX_SVDST  ! switch for the
 LOGICAL,             INTENT(IN):: OHORELAX_SVSLT  ! switch for the 
                        ! horizontal relaxation for slt variables
 LOGICAL,             INTENT(IN):: OHORELAX_SVPP   ! switch for the 
-                       ! horizontal relaxation for passive scalar 
+                       ! horizontal relaxation for passive scalar
+#ifdef MNH_FOREFIRE
+LOGICAL,             INTENT(IN):: OHORELAX_SVFF   ! switch for the 
+                       ! horizontal relaxation for ForeFire variables 
+#endif
 LOGICAL,             INTENT(IN):: OHORELAX_SVCS   ! switch for the 
                        ! horizontal relaxation for conditional sampling
 INTEGER,                  INTENT(IN)    :: KTCOUNT! Temporal loop counter       
@@ -150,6 +157,9 @@ END MODULE MODI_RELAXATION
                              OHORELAX_SVCHEM,OHORELAX_SVCHIC, OHORELAX_SVAER,  &
                              OHORELAX_SVDST, OHORELAX_SVSLT, OHORELAX_SVPP,    &
                              OHORELAX_SVCS,                                    &
+#ifdef MNH_FOREFIRE
+                             OHORELAX_SVFF,                                    &
+#endif
                              KTCOUNT,KRR,KSV,PTSTEP,PRHODJ,                    &
                              PUT, PVT, PWT, PTHT, PRT, PSVT, PTKET,            &
                              PLSUM, PLSVM, PLSWM, PLSTHM,                      &
@@ -308,7 +318,11 @@ LOGICAL,             INTENT(IN):: OHORELAX_SVDST  ! switch for the
 LOGICAL,             INTENT(IN):: OHORELAX_SVSLT  ! switch for the 
                        ! horizontal relaxation for slt variables
 LOGICAL,             INTENT(IN):: OHORELAX_SVPP   ! switch for the 
-                       ! horizontal relaxation for passive scalar 
+                       ! horizontal relaxation for passive scalar
+#ifdef MNH_FOREFIRE 
+LOGICAL,             INTENT(IN):: OHORELAX_SVFF   ! switch for the 
+                       ! horizontal relaxation for ForeFire variables 
+#endif
 LOGICAL,             INTENT(IN):: OHORELAX_SVCS   ! switch for the 
                        ! horizontal relaxation for conditional sampling
 INTEGER,                  INTENT(IN)    :: KTCOUNT! Temporal loop counter       
@@ -400,7 +414,11 @@ REAL, DIMENSION(SIZE(PUT,1),SIZE(PUT,2),SIZE(PUT,3)) :: ZKHU,ZKHV,ZKHW,       &
 LOGICAL, DIMENSION(SIZE(PUT,1),SIZE(PUT,2),SIZE(PUT,3)) :: GMASK3D_RELAX ! 3D
                              ! mask for hor. relax.
 LOGICAL, DIMENSION(7) :: GHORELAXR ! local array of logical
+#ifdef MNH_FOREFIRE
+LOGICAL, DIMENSION(12) :: GHORELAXSV! local array of logical
+#else
 LOGICAL, DIMENSION(11) :: GHORELAXSV! local array of logical
+#endif
 !  
 !-------------------------------------------------------------------------------
 !
@@ -437,6 +455,9 @@ GHORELAXSV(8) = OHORELAX_SVSLT
 GHORELAXSV(9) = OHORELAX_SVPP
 GHORELAXSV(10) = OHORELAX_SVCS
 GHORELAXSV(11) = OHORELAX_SVCHIC
+#ifdef MNH_FOREFIRE
+GHORELAXSV(12) = OHORELAX_SVFF
+#endif
 !-------------------------------------------------------------------------------
 !
 !*       2.     RELAXATION IN THE UPPER LAYERS
index ef9077d..eeed369 100644 (file)
@@ -137,6 +137,9 @@ END MODULE MODI_SPAWN_FIELD2
 !!      Modification 01/02/01 (D.Gazen)  add module MODD_NSV for NSV variable
 !!      Modification 07/07/05 (D.Barbary) spawn with 2 input files (father+son1)
 !!      Modification 05/06                Remove EPS, Clark and Farley
+!!      Modification 06/12  (M.Tomasini)  Interpolation of turbulent fluxes (EDDY_FLUX)
+!!                                        for 2D west african monsoon
+!!      Modification 07/13  (Bosseur & Filippi) Adds Forefire
 !-------------------------------------------------------------------------------
 !
 !*       0.     DECLARATIONS
@@ -651,6 +654,18 @@ IF (PRESENT(HSONFILE)) THEN
                   YCOMMENT,IRESP)
       IF(IRESP==0) PSVT(KIB2:KIE2,KJB2:KJE2,:,JSV)=ZWORK3D(KIB1:KIE1,KJB1:KJE1,:)
     END DO
+#ifdef MNH_FOREFIRE
+    DO JSV = NSV_FFBEG,NSV_FFEND     ! ForeFire variables
+      WRITE(YRECFM,'(A3,I3.3)')'SVM',JSV
+      CALL FMREAD(HSONFILE,YRECFM,CLUOUT,YDIR,ZWORK3D,IGRID,ILENCH,  &
+                  YCOMMENT,IRESP)
+      IF(IRESP==0) PSVT(KIB2:KIE2,KJB2:KJE2,:,JSV)=ZWORK3D(KIB1:KIE1,KJB1:KJE1,:)
+      WRITE(YRECFM,'(A3,I3.3)')'SVT',JSV
+      CALL FMREAD(HSONFILE,YRECFM,CLUOUT,YDIR,ZWORK3D,IGRID,ILENCH,  &
+                  YCOMMENT,IRESP)
+      IF(IRESP==0) PSVT(KIB2:KIE2,KJB2:KJE2,:,JSV)=ZWORK3D(KIB1:KIE1,KJB1:KJE1,:)
+    END DO
+#endif
     DO JSV = NSV_CSBEG,NSV_CSEND     ! Passive scalar variables
       WRITE(YRECFM,'(A3,I3.3)')'SVT',JSV
       CALL FMREAD(HSONFILE,YRECFM,CLUOUT,YDIR,ZWORK3D,IGRID,ILENCH,  &
@@ -662,6 +677,13 @@ IF (PRESENT(HSONFILE)) THEN
       CALL FMREAD(HSONFILE,YRECFM,CLUOUT,YDIR,ZWORK3D,IGRID,ILENCH,YCOMMENT,IRESP)
       IF(IRESP==0) PATC(KIB2:KIE2,KJB2:KJE2,:,JSV)=ZWORK3D(KIB1:KIE1,KJB1:KJE1,:)
     END DO
+#ifdef MNH_FOREFIRE
+   DO JSV = 1,NSV_FF               ! ForeFire variables
+      YRECFM='ATC'
+      CALL FMREAD(HSONFILE,YRECFM,CLUOUT,YDIR,ZWORK3D,IGRID,ILENCH,YCOMMENT,IRESP)
+      IF(IRESP==0) PATC(KIB2:KIE2,KJB2:KJE2,:,JSV)=ZWORK3D(KIB1:KIE1,KJB1:KJE1,:)
+    END DO
+#endif
   END IF
   !
   ! Secondary pronostic variables
index e6d6530..73c4d21 100644 (file)
@@ -180,6 +180,7 @@ END MODULE MODI_SPAWN_MODEL2
 !!                             Replace DRY_MASS by TOTAL_DMASS
 !!      Modification 06/12  (M.Tomasini) Interpolation of the advective forcing (ADVFRC)
 !!                                       and of the turbulent fluxes (EDDY_FLUX)
+!!      Modification 07/13  (Bosseur & Filippi) Adds Forefire
 !-------------------------------------------------------------------------------
 !
 !*       0.     DECLARATIONS
@@ -608,6 +609,9 @@ IF (NSV_AER  > 0) LHORELAX_SVAER = .TRUE.
 IF (NSV_DST  > 0) LHORELAX_SVDST = .TRUE.
 IF (NSV_SLT  > 0) LHORELAX_SVSLT = .TRUE.
 IF (NSV_PP  > 0) LHORELAX_SVPP   = .TRUE.
+#ifdef MNH_FOREFIRE
+IF (NSV_FF  > 0) LHORELAX_SVFF   = .TRUE.
+#endif
 IF (NSV_CS  > 0) LHORELAX_SVCS   = .TRUE.
 LHORELAX_SVLG   = .FALSE.
 !
index 52bc675..4be8177 100644 (file)
@@ -116,6 +116,7 @@ END MODULE MODI_TWO_WAY_n
 !!      M. Leriche   16/07/10  Add ice phase chemical species
 !!      V.Masson, C.Lac 08/10  Corrections in relaxation
 !!      J. Escobar   27/06/2011 correction for gridnesting with different SHAPE
+!!      Bosseur & Filippi 07/2013 Adds Forefire
 !------------------------------------------------------------------------------
 !
 !*      0.   DECLARATIONS
@@ -604,9 +605,29 @@ DO JVAR=1,NSV_PP_A(KMI)
            &XRHODJ(II1:II2:IDXRATIO,IJ1:IJ2:IDYRATIO,:)*&
            &XSVT(II1:II2:IDXRATIO,IJ1:IJ2:IDYRATIO,:,JVAR-1+NSV_PPBEG_A(IMI))
     END DO
+  END DO 
+END DO
+END IF
+#ifdef MNH_FOREFIRE
+! ForeFire variables
+IF (NSV_FF_A(IMI) > 0) THEN
+DO JVAR=1,NSV_FF_A(KMI)
+  ZTSVM(:,:,:,JVAR-1+NSV_FFBEG_A(KMI)) = 0.
+  DO JX=1,IDXRATIO
+    DO JY=1,IDYRATIO
+      II1 = IIB+JX-1
+      II2 = IIE+JX-IDXRATIO
+      IJ1 = IJB+JY-1
+      IJ2 = IJE+JY-IDYRATIO
+      ZTSVM(3:IDIMX-2,3:IDIMY-2,:,JVAR-1+NSV_FFBEG_A(KMI)) = &
+           &ZTSVM(3:IDIMX-2,3:IDIMY-2,:,JVAR-1+NSV_FFBEG_A(KMI))+&
+           &XRHODJ(II1:II2:IDXRATIO,IJ1:IJ2:IDYRATIO,:)*&
+           &XSVT(II1:II2:IDXRATIO,IJ1:IJ2:IDYRATIO,:,JVAR-1+NSV_FFBEG_A(IMI))
+    END DO
   END DO
 END DO
 END IF
+#endif
 ! Conditional sampling variables
 IF (NSV_CS_A(IMI) > 0) THEN
 DO JVAR=1,NSV_CS_A(KMI)
@@ -1208,6 +1229,15 @@ DO JVAR=NSV_PPBEG_A(KMI),NSV_PPEND_A(KMI)
      -  ZK2W * PRHODJ(IXOR:IXEND,IYOR:IYEND,:) * (PSVM(IXOR:IXEND,IYOR:IYEND,:,JVAR) &
                  -ZSVM(IXOR:IXEND,IYOR:IYEND,:,JVAR)/ZRHODJ(IXOR:IXEND,IYOR:IYEND,:) )
 ENDDO
+#ifdef MNH_FOREFIRE
+
+! ForeFire variables
+DO JVAR=NSV_FFBEG_A(KMI),NSV_FFEND_A(KMI)
+  PRSVS(IXOR:IXEND,IYOR:IYEND,:,JVAR) = PRSVS(IXOR:IXEND,IYOR:IYEND,:,JVAR) &
+     -  ZK2W * PRHODJ(IXOR:IXEND,IYOR:IYEND,:) * (PSVM(IXOR:IXEND,IYOR:IYEND,:,JVAR) &
+                 -ZSVM(IXOR:IXEND,IYOR:IYEND,:,JVAR)/ZRHODJ(IXOR:IXEND,IYOR:IYEND,:) )
+ENDDO
+#endif
 ! Conditional sampling variables
 DO JVAR=NSV_CSBEG_A(KMI),NSV_CSEND_A(KMI)
   PRSVS(IXOR:IXEND,IYOR:IYEND,:,JVAR) = PRSVS(IXOR:IXEND,IYOR:IYEND,:,JVAR) &
index 084f0f2..332e4c3 100644 (file)
@@ -21,6 +21,7 @@ END MODULE MODI_UPDATE_NSV
 !!                   current model. It is intended to be called from 
 !!                   any MesoNH routine WITH or WITHOUT $n before using 
 !!                   the NSV_* variables.
+!!  Modify (Escobar ) 2/2014 : add Forefire var
 USE MODD_CONF, ONLY : NVERB
 USE MODD_NSV
 IMPLICIT NONE 
@@ -85,6 +86,11 @@ NSV_LGEND   = NSV_LGEND_A(KMI)
 NSV_PP      = NSV_PP_A(KMI)
 NSV_PPBEG   = NSV_PPBEG_A(KMI)
 NSV_PPEND   = NSV_PPEND_A(KMI)
+#ifdef MNH_FOREFIRE
+NSV_FF      = NSV_FF_A(KMI)
+NSV_FFBEG   = NSV_FFBEG_A(KMI)
+NSV_FFEND   = NSV_FFEND_A(KMI)
+#endif
 NSV_CS      = NSV_CS_A(KMI)
 NSV_CSBEG   = NSV_CSBEG_A(KMI)
 NSV_CSEND   = NSV_CSEND_A(KMI)
index 10cac4b..3340c80 100644 (file)
@@ -187,6 +187,10 @@ USE MODN_PASPOL
 USE MODN_CONDSAMP
 USE MODN_2D_FRC
 USE MODN_LATZ_EDFLX
+#ifdef MNH_FOREFIRE
+USE MODN_FOREFIRE
+USE MODD_FOREFIRE_n, ONLY : FFCOUPLING
+#endif
 !
 IMPLICIT NONE
 !
@@ -207,6 +211,9 @@ LOGICAL                     ::  GHORELAX_UVWTH,                               &
                                 GHORELAX_RI,  GHORELAX_RS, GHORELAX_RG,       &
                                 GHORELAX_TKE, GHORELAX_SVC2R2, GHORELAX_SVPP, &
                                 GHORELAX_SVCS, GHORELAX_SVCHIC,               &
+#ifdef MNH_FOREFIRE
+                                GHORELAX_SVFF,                                &
+#endif
                                 GHORELAX_SVCHEM, GHORELAX_SVC1R3,GHORELAX_SVELEC
 LOGICAL                     ::  GHORELAX_SVDST, GHORELAX_SVSLT,  GHORELAX_SVAER
 LOGICAL, DIMENSION(JPSVMAX) ::  GHORELAX_SV
@@ -248,6 +255,9 @@ IF (CPROGRAM/='MESONH') THEN   ! impose default value for next simulation
   GHORELAX_SVDST = LHORELAX_SVDST
   GHORELAX_SVSLT = LHORELAX_SVSLT
   GHORELAX_SVPP  = LHORELAX_SVPP 
+#ifdef MNH_FOREFIRE
+  GHORELAX_SVFF  = LHORELAX_SVFF
+#endif
   GHORELAX_SVCS  = LHORELAX_SVCS 
   GHORELAX_SVAER = LHORELAX_SVAER
 !
@@ -267,6 +277,9 @@ IF (CPROGRAM/='MESONH') THEN   ! impose default value for next simulation
   LHORELAX_SVCHIC= .FALSE.
   LHORELAX_SVLG  = .FALSE.
   LHORELAX_SVPP  = .FALSE.
+#ifdef MNH_FOREFIRE
+  LHORELAX_SVFF  = .FALSE.
+#endif
   LHORELAX_SVCS  = .FALSE.
   LHORELAX_SVDST= .FALSE.
   LHORELAX_SVSLT= .FALSE.
@@ -331,6 +344,9 @@ IF(LUSECHEM) WRITE(UNIT=ILUSEG,NML=NAM_CH_SOLVERn)
 IF(LDUST) WRITE(UNIT=ILUSEG,NML=NAM_DUST)
 IF(LSALT) WRITE(UNIT=ILUSEG,NML=NAM_SALT)
 IF(LPASPOL) WRITE(UNIT=ILUSEG,NML=NAM_PASPOL)
+#ifdef MNH_FOREFIRE
+IF(FFCOUPLING) WRITE(UNIT=ILUSEG,NML=NAM_FOREFIRE)
+#endif
 IF(LCONDSAMP) WRITE(UNIT=ILUSEG,NML=NAM_CONDSAMP)
 IF(LORILAM.AND.LUSECHEM) WRITE(UNIT=ILUSEG,NML=NAM_CH_ORILAM)
 !
@@ -510,6 +526,11 @@ IF (NVERB >= 5) THEN
     WRITE(UNIT=ILUOUT,FMT="('********** PASPOL *****************************')")
     WRITE(UNIT=ILUOUT,NML=NAM_PASPOL)
 !
+#ifdef MNH_FOREFIRE
+    WRITE(UNIT=ILUOUT,FMT="('********** FOREFIRE *****************************')")
+    WRITE(UNIT=ILUOUT,NML=NAM_FOREFIRE)
+!
+#endif
     WRITE(UNIT=ILUOUT,FMT="('********** CONDSAMP****************************')")
     WRITE(UNIT=ILUOUT,NML=NAM_CONDSAMP)
 !
@@ -567,6 +588,9 @@ IF (CPROGRAM /='MESONH') THEN !return to previous LHORELAX_
   LHORELAX_SVDST = GHORELAX_SVDST
   LHORELAX_SVSLT = GHORELAX_SVSLT
   LHORELAX_SVPP  = GHORELAX_SVPP 
+#ifdef MNH_FOREFIRE
+  LHORELAX_SVFF  = GHORELAX_SVFF
+#endif
   LHORELAX_SVCS  = GHORELAX_SVCS 
   LHORELAX_SVAER = GHORELAX_SVAER
 ELSE
index 4fe3b34..6caf682 100644 (file)
@@ -825,6 +825,26 @@ END IF ! valeur IMOMENTS
            & IGRID,ILENCH,YCOMMENT,IRESP)
     END IF
   END DO
+#ifdef MNH_FOREFIRE
+  ! ForeFire scalar variables
+  DO JSV = NSV_FFBEG,NSV_FFEND
+    IF(NSIZELBXSV_ll /= 0) THEN
+      YRECFM = 'LBX_FF'
+      WRITE(YCOMMENT,'(A6,A6,I3.3,A8)')'2_Y_Z_','LBX_FF',JSV,' (KG/KG)'
+      ILENCH=LEN(YCOMMENT)
+      CALL FMWRIT_LB(HFMFILE,YRECFM,CLUOUT,"LBX",XLBXSVM(:,:,:,JSV),IRIMX,NSIZELBXSV_ll,&
+           & IGRID,ILENCH,YCOMMENT,IRESP)
+    END IF
+!
+    IF(NSIZELBYSV_ll /= 0) THEN
+      YRECFM = 'LBY_FF'
+      WRITE(YCOMMENT,'(A6,A6,I3.3,A8)')'X_2_Z_','LBY_FF',JSV,' (KG/KG)'
+      ILENCH=LEN(YCOMMENT)
+      CALL FMWRIT_LB(HFMFILE,YRECFM,CLUOUT,"LBY",XLBYSVM(:,:,:,JSV),IRIMY,NSIZELBYSV_ll,&
+           & IGRID,ILENCH,YCOMMENT,IRESP)
+    END IF
+  END DO
+#endif
 END IF
 !
 !-------------------------------------------------------------------------------
index cd2e2c6..dccd3ba 100644 (file)
@@ -152,6 +152,7 @@ END MODULE MODI_WRITE_LFIFM_n
 !!       P.Peyrille    06/12 2D west african monsoon: ADV forcing and fluxes writing
 !!                     AEROSOLS and ozone vertical distribution are also written
 !!       M.Tomasini    06/12 2D west african monsoon: nesting for ADV forcing writing
+!!       Pialat/Tulet  15/02/2012 add ForeFire variables
 !!                   
 !-------------------------------------------------------------------------------
 !
@@ -204,6 +205,9 @@ USE MODD_PREP_REAL, ONLY: CDUMMY_2D, XDUMMY_2D
 USE MODD_DUST
 USE MODD_SALT
 USE MODD_PASPOL
+#ifdef MNH_FOREFIRE
+USE MODD_FOREFIRE
+#endif
 USE MODD_CONDSAMP
 USE MODD_CH_AEROSOL
 !
@@ -927,15 +931,26 @@ IF (NSV >=1) THEN
   ! Passive scalar variables        
  IF (LPASPOL) THEN
   DO JSV = NSV_PPBEG,NSV_PPEND
+      WRITE(YRECFM,'(A3,I3.3)')'SVT',JSV
+      WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (KG/KG)'
+      ILENCH=LEN(YCOMMENT)
+      CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                  YCOMMENT,IRESP)
+      JSA=JSA+1
+    END DO
+  END IF
+#ifdef MNH_FOREFIRE
+  ! ForeFire scalar variables
+ IF ( LFOREFIRE ) THEN
+  DO JSV = NSV_FFBEG,NSV_FFEND
     WRITE(YRECFM,'(A3,I3.3)')'SVT',JSV
     WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (KG/KG)'
     ILENCH=LEN(YCOMMENT)
     CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
                 YCOMMENT,IRESP)
-    JSA=JSA+1
   END DO
  END IF
-!
+#endif
   ! Conditional sampling variables  
  IF (LCONDSAMP) THEN
   DO JSV = NSV_CSBEG,NSV_CSEND
@@ -1263,6 +1278,379 @@ END IF
 CALL WRITE_LB_n(HFMFILE)
 !
 !
+IF (CSTORAGE_TYPE/='TT') THEN
+!
+!*       1.4.2  Time t:
+!   
+YRECFM='UT'
+YCOMMENT='X_Y_Z_U component of wind (m/s)'
+IGRID=2
+ILENCH=LEN(YCOMMENT)
+CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XUT,IGRID,ILENCH,YCOMMENT,IRESP)
+!
+YRECFM='VT'
+YCOMMENT='X_Y_Z_V component of wind (m/s)'
+IGRID=3
+ILENCH=LEN(YCOMMENT)
+CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XVT,IGRID,ILENCH,YCOMMENT,IRESP)
+!
+YRECFM='WT'
+YCOMMENT='X_Y_Z_vertical wind (m/s)'
+IGRID=4
+ILENCH=LEN(YCOMMENT)
+CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XWT,IGRID,ILENCH,YCOMMENT,IRESP)
+!
+YRECFM='THT'
+YCOMMENT='X_Y_Z_potential temperature (K)'
+IGRID=1
+ILENCH=LEN(YCOMMENT)
+CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XTHT,IGRID,ILENCH,YCOMMENT,IRESP)
+!
+IF(CTURB/='NONE') THEN
+  YRECFM='TKET'
+  YCOMMENT='X_Y_Z_Turbulent Kinetic Energy (M**2/S**2)'
+  IGRID=1
+  ILENCH=LEN(YCOMMENT)
+  CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XTKET,IGRID,ILENCH,YCOMMENT,IRESP)
+END IF
+!
+!
+YRECFM='PABST'
+YCOMMENT='X_Y_Z_ABSolute Pressure (Pa)'
+IGRID=1
+ILENCH=LEN(YCOMMENT)
+CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XPABST,IGRID,ILENCH,YCOMMENT,IRESP)
+!
+IF (NRR >=1) THEN
+IRR=0
+  IGRID=1                                    ! individually in file 
+  IF (LUSERV) THEN
+    IRR   = IRR+1 
+    YRECFM= 'RVT'
+    YCOMMENT='X_Y_Z_Vapor mixing Ratio (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XRT(:,:,:,IRR),IGRID,ILENCH,  &
+                YCOMMENT,IRESP)
+  END IF 
+  IF (LUSERC) THEN
+    IRR   = IRR+1 
+    YRECFM= 'RCT'
+    YCOMMENT='X_Y_Z_Cloud mixing Ratio (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XRT(:,:,:,IRR),IGRID,ILENCH,  &
+                YCOMMENT,IRESP)
+  END IF
+  IF (LUSERR) THEN
+    IRR   = IRR+1 
+    YRECFM= 'RRT'
+    YCOMMENT='X_Y_Z_Rain mixing Ratio (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XRT(:,:,:,IRR),IGRID,ILENCH,  &
+                YCOMMENT,IRESP)
+  END IF 
+  IF (LUSERI) THEN
+    IRR   = IRR+1 
+    YRECFM= 'RIT'
+    YCOMMENT='X_Y_Z_Ice mixing Ratio (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XRT(:,:,:,IRR),IGRID,ILENCH,  &
+                YCOMMENT,IRESP)
+    IF ( CPROGRAM == 'MESONH' .AND. CCLOUD(1:3) == 'ICE') THEN
+      YRECFM= 'CIT'
+      YCOMMENT='X_Y_Z_Cloud Ice concentration (/M3)'
+      ILENCH=LEN(YCOMMENT)
+      CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XCIT(:,:,:),   IGRID,ILENCH,  &
+                  YCOMMENT,IRESP)
+    END IF
+ END IF 
+  IF (LUSERS) THEN
+    IRR   = IRR+1 
+    YRECFM= 'RST'
+    YCOMMENT='X_Y_Z_Snow mixing Ratio (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XRT(:,:,:,IRR),IGRID,ILENCH,  &
+                YCOMMENT,IRESP)
+  END IF
+  IF (LUSERG) THEN
+    IRR   = IRR+1 
+    YRECFM= 'RGT'
+    YCOMMENT='X_Y_Z_Graupel mixing Ratio (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XRT(:,:,:,IRR),IGRID,ILENCH,  &
+                YCOMMENT,IRESP)
+  END IF 
+  IF (LUSERH) THEN
+    IRR   = IRR+1 
+    YRECFM= 'RHT'
+    YCOMMENT='X_Y_Z_Hail mixing Ratio (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XRT(:,:,:,IRR),IGRID,ILENCH,  &
+                YCOMMENT,IRESP)
+  END IF 
+END IF
+!
+IF (NSV >=1) THEN
+  IGRID=1                                       ! individually in the file
+  ! User scalar variables
+  DO JSV = 1,NSV_USER
+    WRITE(YRECFM,'(A3,I3.3)')'SVT',JSV
+    WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                YCOMMENT,IRESP)
+  END DO
+  ! microphysical C2R2 scheme scalar variables
+  DO JSV = NSV_C2R2BEG,NSV_C2R2END
+    YRECFM=TRIM(C2R2NAMES(JSV-NSV_C2R2BEG+1))//'T'
+    WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                YCOMMENT,IRESP)
+  END DO
+  ! microphysical C3R5 scheme additional scalar variables
+  DO JSV = NSV_C1R3BEG,NSV_C1R3END
+    YRECFM=TRIM(C1R3NAMES(JSV-NSV_C1R3BEG+1))//'T'
+    WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (/M3)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                YCOMMENT,IRESP)
+  END DO
+  ! electrical scalar variables
+  DO JSV = NSV_ELECBEG,NSV_ELECEND
+    YRECFM=TRIM(CELECNAMES(JSV-NSV_ELECBEG+1))//'T'
+    WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (C/m3)'
+    ILENCH=LEN(YCOMMENT)
+    ZWORK3D(:,:,:) = 0.
+    ZWORK3D(:,:,:) = XSVT(:,:,:,JSV) * XRHODREF(:,:,:) ! C/kg --> C/m3
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,ZWORK3D(:,:,:),IGRID,ILENCH,    &
+                YCOMMENT,IRESP)
+  END DO
+
+  ! Passive scalar variables        
+ IF (LPASPOL) THEN
+  DO JSV = NSV_PPBEG,NSV_PPEND
+    WRITE(YRECFM,'(A3,I3.3)')'SVT',JSV
+    WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                YCOMMENT,IRESP)
+  END DO
+ END IF
+#ifdef MNH_FOREFIRE
+ IF (LFOREFIRE) THEN
+  DO JSV = NSV_FFBEG,NSV_FFEND
+    WRITE(YRECFM,'(A3,I3.3)')'SVT',JSV
+    WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                YCOMMENT,IRESP)
+  END DO
+ END IF
+#endif
+  ! Conditional sampling variables        
+ IF (LCONDSAMP) THEN
+  DO JSV = NSV_CSBEG,NSV_CSEND
+    WRITE(YRECFM,'(A3,I3.3)')'SVT',JSV
+    WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (KG/KG)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                YCOMMENT,IRESP)
+  END DO
+ END IF
+  ! chemical scalar variables
+  IF (LUSECHEM) THEN
+    DO JSV = NSV_CHEMBEG,NSV_CHEMEND
+      YRECFM=TRIM(UPCASE(CNAMES(JSV-NSV_CHEMBEG+1)))//'T'
+      WRITE(YCOMMENT,'(A6,A3,I3.3,A)') 'X_Y_Z_','SVT',JSV,' (ppp)'
+      ILENCH=LEN(YCOMMENT)
+      CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                  YCOMMENT,IRESP)
+    END DO
+    IF (LUSECHIC) THEN
+      DO JSV = NSV_CHICBEG,NSV_CHICEND
+        YRECFM=TRIM(UPCASE(CICNAMES(JSV-NSV_CHICBEG+1)))//'T'
+        WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (ppp)'
+        ILENCH=LEN(YCOMMENT)
+        CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                    YCOMMENT,IRESP)
+      END DO
+    ENDIF
+    IF (LUSECHAQ.AND.LCH_PH) THEN  ! pH values in cloud
+      YRECFM = 'PHC'
+      YCOMMENT='X_Y_Z_PHC'
+      ILENCH=LEN(YCOMMENT)
+      CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XPHC,IGRID,ILENCH,YCOMMENT,IRESP)
+      IF (NRR>=3) THEN
+        YRECFM = 'PHR'
+        YCOMMENT='X_Y_Z_PHR'
+        ILENCH=LEN(YCOMMENT)
+        CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XPHR,IGRID,ILENCH,YCOMMENT,IRESP)
+      ENDIF
+    ENDIF
+   ! linox scalar variables
+  ELSE IF (LCH_CONV_LINOX) THEN
+    DO JSV = NSV_LNOXBEG,NSV_LNOXEND
+      YRECFM='LINOXT'
+      WRITE(YCOMMENT,'(A6,A3,I3.3,A)') 'X_Y_Z_','SVT',JSV,' (ppp)'
+      ILENCH=LEN(YCOMMENT)
+      CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH, &
+                  YCOMMENT,IRESP)
+    END DO
+  ENDIF  
+  ! aerosol scalar variables
+  IF (LORILAM) THEN
+    IF ((CPROGRAM == 'REAL  ').AND.(NSV_AER > 1).AND.(IMI==1))  &
+      CALL CH_AER_REALLFI_n(XSVT(:,:,:,NSV_AERBEG:NSV_AEREND),XSVT(:,:,:,NSV_CHEMBEG-1+JP_CH_CO), XRHODREF)
+    IF ((CPROGRAM == 'IDEAL ').AND.(NSV_AER > 1).AND.(IMI==1))  &
+      CALL CH_AER_REALLFI_n(XSVT(:,:,:,NSV_AERBEG:NSV_AEREND),XSVT(:,:,:,NSV_CHEMBEG-1+JP_CH_CO),  XRHODREF)
+    DO JSV = NSV_AERBEG,NSV_AEREND
+      YRECFM=TRIM(UPCASE(CAERONAMES(JSV-NSV_AERBEG+1)))//'T'
+      WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (ppp)'
+      ILENCH=LEN(YCOMMENT)
+      CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                  YCOMMENT,IRESP)
+    END DO
+    IF (LDEPOS_AER(IMI)) THEN
+      DO JSV = NSV_AERDEPBEG,NSV_AERDEPEND
+        YRECFM=TRIM(CDEAERNAMES(JSV-NSV_AERDEPBEG+1))//'T'
+        WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (ppp)'
+        ILENCH=LEN(YCOMMENT)
+        CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,  &
+                    YCOMMENT,IRESP)
+      END DO   ! Loop on aq dust scalar variables        
+    ENDIF
+  END IF
+   ! dust scalar variables
+  IF (LDUST) THEN
+    IF ((CPROGRAM == 'REAL  ').AND.(NSV_DST > 1).AND.(IMI==1).AND.(LDSTINIT)) &
+      CALL DUSTLFI_n(XSVT(:,:,:,NSV_DSTBEG:NSV_DSTEND), XRHODREF)
+    IF ((CPROGRAM == 'IDEAL ').AND.(NSV_DST > 1).AND.(IMI==1)) &
+      CALL DUSTLFI_n(XSVT(:,:,:,NSV_DSTBEG:NSV_DSTEND), XRHODREF)
+    !At this point, we have the tracer array in order of importance, i.e.
+    !if mode 2 is most important it will occupy place 1-3 of XSVM  
+    IF ((CPROGRAM == 'REAL  ').OR.(CPROGRAM == 'IDEAL ')) THEN
+      ! In this case CDUSTNAMES is not allocated. We will use YPDUST_INI,
+      !but remember that this variable does not follow JPDUSTORDER
+      IMOMENTS = INT(NSV_DSTEND - NSV_DSTBEG+1)/NMODE_DST  
+      !Should equal 3 at this point
+      IF (IMOMENTS > 3) THEN
+        WRITE(ILUOUT,*) 'Error in write_lfin: number of moments must be 3'
+        WRITE(ILUOUT,*) NSV_DSTBEG, NSV_DSTEND,NMODE_DST,IMOMENTS
+ !callabortstop
+        CALL CLOSE_ll(CLUOUT,IOSTAT=IRESP)
+        CALL ABORT
+        STOP
+      END IF
+      DO JMODE=1, NMODE_DST
+        DO JMOM = 1, IMOMENTS
+          !Index from which names are picked
+          ISV_NAME_IDX = (JPDUSTORDER(JMODE)-1)*IMOMENTS + JMOM 
+          !Index which counts in the XSVT
+          JSV = (JMODE-1)*IMOMENTS      & !Number of moments previously counted
+               + JMOM                   & !Number of moments in this mode
+               + (NSV_DSTBEG -1)          !Previous list of tracers 
+          YRECFM = TRIM(YPDUST_INI(ISV_NAME_IDX))//'T'  !The refererence which will be written to file
+          WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (ppp)'
+          ILENCH=LEN(YCOMMENT)
+          CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH, &
+                      YCOMMENT,IRESP)
+        END DO ! Loop on moments
+      END DO   ! Loop on modes
+      !
+    ELSE 
+      ! We are in the subprogram MESONH, CDUSTNAMES are allocated and are 
+      !in the same order as the variables in XSVM (i.e. following JPDUSTORDER)
+      DO JSV = NSV_DSTBEG,NSV_DSTEND
+        YRECFM=TRIM(CDUSTNAMES(JSV-NSV_DSTBEG+1))//'T'
+        WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (ppp)'
+        ILENCH=LEN(YCOMMENT)
+        CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,  &
+                    YCOMMENT,IRESP)
+      END DO   ! Loop on dust scalar variables
+    END IF 
+  ! Loop on aq dust scalar variables
+    IF (LDEPOS_DST(IMI)) THEN
+      DO JSV = NSV_DSTDEPBEG,NSV_DSTDEPEND
+        YRECFM=TRIM(CDEDSTNAMES(JSV-NSV_DSTDEPBEG+1))//'T'
+        WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (ppp)'
+        ILENCH=LEN(YCOMMENT)
+        CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,  &
+                    YCOMMENT,IRESP)
+      END DO   ! Loop on aq dust scalar variables        
+    ENDIF
+  ENDIF  
+  !
+   ! sea salt scalar variables
+  IF (LSALT) THEN
+    IF ((CPROGRAM == 'REAL  ').AND.(NSV_SLT > 1).AND.(IMI==1)) &
+      CALL SALTLFI_n(XSVT(:,:,:,NSV_SLTBEG:NSV_SLTEND), XRHODREF)
+    IF ((CPROGRAM == 'IDEAL ').AND.(NSV_SLT > 1).AND.(IMI==1)) &
+      CALL SALTLFI_n(XSVT(:,:,:,NSV_SLTBEG:NSV_SLTEND), XRHODREF)
+    !At this point, we have the tracer array in order of importance, i.e.
+    !if mode 2 is most important it will occupy place 1-3 of XSVM  
+    IF ((CPROGRAM == 'REAL  ').OR.(CPROGRAM == 'IDEAL ')) THEN
+      ! In this case CSALTNAMES is not allocated. We will use YPSALT_INI,
+      !but remember that this variable does not follow JPSALTORDER
+      IMOMENTS = INT(NSV_SLTEND - NSV_SLTBEG+1)/NMODE_SLT  
+      !Should equal 3 at this point
+      IF (IMOMENTS .NE. 3) THEN
+        WRITE(ILUOUT,*) 'Error in write_lfin: number of moments must be 3'
+        WRITE(ILUOUT,*) NSV_SLTBEG, NSV_SLTEND,NMODE_SLT,IMOMENTS
+ !callabortstop
+        CALL CLOSE_ll(CLUOUT,IOSTAT=IRESP)
+        CALL ABORT
+        STOP
+      END IF
+      DO JMODE=1, NMODE_SLT
+        DO JMOM = 1, IMOMENTS
+          !Index from which names are picked
+          ISV_NAME_IDX = (JPSALTORDER(JMODE)-1)*IMOMENTS + JMOM 
+          !Index which counts in the XSVT
+          JSV = (JMODE-1)*IMOMENTS      & !Number of moments previously counted
+               + JMOM                   & !Number of moments in this mode
+               + (NSV_SLTBEG -1)          !Previous list of tracers 
+          YRECFM = TRIM(YPSALT_INI(ISV_NAME_IDX))//'T'  !The refererence which will be written to file
+          WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (ppp)'
+          ILENCH=LEN(YCOMMENT)
+          CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH, &
+                      YCOMMENT,IRESP)
+        END DO ! Loop on moments
+      END DO   ! Loop on modes
+      !
+    ELSE 
+      ! We are in the subprogram MESONH, CSALTNAMES are allocated and are 
+      !in the same order as the variables in XSVM (i.e. following JPSALTORDER)
+      DO JSV = NSV_SLTBEG,NSV_SLTEND
+        YRECFM=TRIM(CSALTNAMES(JSV-NSV_SLTBEG+1))//'T'
+        WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (ppp)'
+        ILENCH=LEN(YCOMMENT)
+        CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,  &
+                    YCOMMENT,IRESP)
+      END DO   ! Loop on sea salt scalar variables
+    END IF 
+    IF (LDEPOS_SLT(IMI)) THEN
+      DO JSV = NSV_SLTDEPBEG,NSV_SLTDEPEND
+        YRECFM=TRIM(CDESLTNAMES(JSV-NSV_SLTDEPBEG+1))//'T'
+        WRITE(YCOMMENT,'(A6,A3,I3.3,A8)')'X_Y_Z_','SVT',JSV,' (ppp)'
+        ILENCH=LEN(YCOMMENT)
+        CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,  &
+                    YCOMMENT,IRESP)
+      END DO   ! Loop on aq dust scalar variables        
+    ENDIF
+  ENDIF  
+  !
+   ! lagrangian variables
+  DO JSV = NSV_LGBEG,NSV_LGEND
+    YRECFM=TRIM(CLGNAMES(JSV-NSV_LGBEG+1))//'T'
+    WRITE(YCOMMENT,'(A6,A3,I3.3,A)') 'X_Y_Z_','SVT',JSV,' (M)'
+    ILENCH=LEN(YCOMMENT)
+    CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XSVT(:,:,:,JSV),IGRID,ILENCH,    &
+                YCOMMENT,IRESP)
+  END DO
+END IF
+!
+END IF ! test on CSTORAGE_TYPE
+!
 YRECFM='DRYMASST'
 YDIR='--'
 YCOMMENT='Total Dry Mass (KG)'
@@ -1687,6 +2075,17 @@ IF (CDCONV /= 'NONE' .OR. CSCONV == 'KAFR') THEN
       CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XDSVCONV(:,:,:,JSV),          &
            IGRID,ILENCH,YCOMMENT,IRESP)
     END DO
+#ifdef MNH_FOREFIRE
+    IF (LFOREFIRE) THEN
+     DO JSV = NSV_FFBEG, NSV_FFEND
+      WRITE(YRECFM,'(A7,I3.3)')'DSVCONV',JSV
+      WRITE(YCOMMENT,'(A6,A7,I3.3,A6)')'X_Y_Z_','DSVCONV',JSV,' (1/S)'
+     ILENCH = LEN(YCOMMENT)
+     CALL FMWRIT(HFMFILE,YRECFM,CLUOUT,YDIR,XDSVCONV(:,:,:,JSV),          &
+       IGRID,ILENCH,YCOMMENT,IRESP)
+     END DO
+    END IF
+#endif
     IF (LUSECHEM) THEN
       DO JSV = NSV_CHEMBEG, NSV_CHEMEND
         YRECFM = 'DSVCONV_'//TRIM(UPCASE(CNAMES(JSV-NSV_CHEMBEG+1)))
index abb294b..420b2f0 100644 (file)
@@ -175,6 +175,18 @@ VPATH               += $(DIR_NEWLFI)
 #ARCH_XYZ    := $(ARCH_XYZ)-$(VER_NEWLFI)
 endif
 ##########################################################
+#           Source FOREFIRE                              #
+##########################################################
+ifdef MNH_FOREFIRE
+DIR_FOREFIRE          += LIB/FOREFIRE
+INC_FOREFIRE           = -I$(B)$(DIR_FOREFIRE)
+DIR_MASTER            += $(DIR_FOREFIRE)
+OBJS_LISTE_MASTER     += C_ForeFire_Interface.o
+INC                   += $(INC_FOREFIRE)
+VPATH                 += $(DIR_FOREFIRE)
+CPPFLAGS              += -DMNH_FOREFIRE
+endif
+##########################################################
 #           Source MPIVIDE                               #
 ##########################################################
 #