#!/bin/sh

###########################################################
#  General script calculating meteo, bio emissions etc... #
#  and running the CTM at REGIONAL-IDF scale. The user    #
#  must fill the form below. This script works only for   #
#  SIMULATION and NOT FORECAST.                           #
#  *** This version works only with ECMWF data for the    #
#  *** SUMMER period (april to september), deposition     #
#  *** parameters must be changed for winter              #
#                                                         #
#  SOFTWARE REQUIRED: g77, m4, gawk                       #
#                                                         #
#  LAST REVISION : DECEMBER 2000                          #
#                                                         #
#  AUTHORS: H. SCHMIDT, C. DEROGNAT, J. ROUX, M. BEEKMANN #
#           N. BLOND, R. VAUTARD                          #
#         - INSTITUT PIERRE-SIMON LAPLACE -               #
########################################################### 

#  Fill this form. The values below are just examples

# Year of the period to be simulated

year=1999

# Directory where to find ECMWF grib data

ecmwfdir=/home/vautard/MERLIN/ECMWF/SUMMER${year}

# Directory where to find processed meteo data (continental meteo recalculated)

meteodir=/home/vautard/MERLIN/chimere-r/ESQUIF/METEO

# Directory where to find continental output data

contdir=/home/vautard/MERLIN/chimere-c/CONT200012_s1999

# Directory where model outputs are placed (as well as initial conditions)

modeldir=/home/vautard/MERLIN/chimere-r/ESQUIF/VOCS

# Directory where to find emission data

emissdir=/p9/vautard/ESQUIF/VOCS/EMIS

# Month of first simulation day (must have 2 digits)

month=$5

# Day of the first simulation day (must have 2 digits)

day=$2

# Number of simulation days (<11 days; simulations must start at 0z)

ndays=$1

# A suffix label for naming the simulations (output file will be out.LABEL)

sim=$4

# Initialization option: 0 means no initialization (interpolation of boundary
# conditions), 1 means reading initial concentrations in a file.

init=$3

# Meteo preprocessing

echo "Preparing meteo files..."

# Meteo at Continental scale: this stage can be omitted if data already present

# prepmet $year ${year}${month}${day}00 $ndays $sim $ecmwfdir $meteodir

# Meteo at regional scale: just a bilinear interpolation

# compile exreg
# echo "3 '"${meteodir}/BE.${sim}"' '"${meteodir}/BE-IDF.${sim}"'" | exreg.e
# echo "5 '"${meteodir}/DE.${sim}"' '"${meteodir}/DE-IDF.${sim}"'" | exreg.e
# echo "4 '"${meteodir}/CL.${sim}"' '"${meteodir}/CL-IDF.${sim}"'" | exreg.e
# echo "5 '"${meteodir}/LH.${sim}"' '"${meteodir}/LH-IDF.${sim}"'" | exreg.e
# echo "1 '"${meteodir}/MH.${sim}"' '"${meteodir}/MH-IDF.${sim}"'" | exreg.e
# echo "5 '"${meteodir}/MW.${sim}"' '"${meteodir}/MW-IDF.${sim}"'" | exreg.e
# echo "5 '"${meteodir}/SH.${sim}"' '"${meteodir}/SH-IDF.${sim}"'" | exreg.e
# echo "5 '"${meteodir}/TE.${sim}"' '"${meteodir}/TE-IDF.${sim}"'" | exreg.e
# echo "5 '"${meteodir}/ZW.${sim}"' '"${meteodir}/ZW-IDF.${sim}"'" | exreg.e
# echo "2 '"${meteodir}/RI.${sim}"' '"${meteodir}/RI-IDF.${sim}"'" | exreg.e

# Extraction of boundary conditions

echo "Extraction of boundary conditions..."
compile exboun
echo "70 '"${contdir}/out.$sim"' '"BOUNDARIES"'" | exboun.e

# Filling information in the INFOS file concerning the simulation. This file
# will be read at the beginning of simulation.

echo "Building the INFOS file..."
m4 -D_METEODIR_=$meteodir -D_EMISSDIR_=$emissdir -D_MODELDIR_=$modeldir -D_SIM_=$sim -D_MONTH_=$month -D_DAYS_=$ndays -D_INIT_=$init -D_INITI_DATE_=${year}${month}${day}00 INFOS.m4 > INFOS

# Compiling of libraries and main program

echo "Compiling the chimere code..."
compile chimere

# Runinng the model

echo "Model running..."
chimere.e
