#!/bin/bash

#############################################################
#  General script running the CHIMERE model                 #
#                                                           #
#  SOFTWARE REQUIRED:                                       #
#     gawk, gmake, netcdf, lam-mpi,                         #
#     a fortran 90 compiler.                                #
#     CHIMERE works without modifications with compilers :  #
#                        - ifort                            #
#                        - pgf90                            #
#                        - g95                              #
#                                                           #
#       *** ONLY TESTED ON i386 architecture ***            #
#                   under GNU/Linux                         #
#                                                           #
#  http://euler.lmd.polytechnique.fr/chimere                #
#                                                           #
#  Questions: chimere@lmd.polytechnique                     #
#                                                           #
#  LAST REVISION  : NOVEMBER 2005                           #
############################################################# 

# EXAMPLE OF AUTOMATIC RUN.
#
# This script assumes an already existing data base of MM5 runs.


################################
#      Timing of the run       #
################################
#
hour=00                      # Starting hour
nhours=120                   # Number of simulation hours


di=20030730                  # Initial date in YYYYMMDD format


# If you prefer to have the initial date "di" passed as an argument
# to this script, uncomment the two following lines :

#[ $# -ne 1 ] && { echo "usage : $0 YYYYMMDD" ; exit 1; }
#di=$1

# This is an example for a 5 days run
# Edit script_functions/calc_dates.sh if you want to change the length
# of the runs.
# Time boundaries should match the MM5 runs data base.
# Here we derive some useful dates from "di"

. script_functions/calc_dates.sh

################################
#          Files               #
################################

##### Simulation label
# Choose a label to uniquely identify this run
lab=heat-wave

##### CHIMERE data base files

# Vertical hybrid coordinates file (in data/vgrid)
vcoord=VCOORD.8GEOM

# Coarse-run Vertical hybrid coordinates file (if nested run)
cvcoord=VCOORD.8GEOM

# Ouptut species file (in data/output_species)
output_species=OUTPUT_SPECIES.MELCHIOR.aero.tonest

# Anthropic emissions files
# standard
emissdir_std=/COMPERES/pub/chimere/emiEMEP-200411/EMI_aero_2002/2LEVELS
# if you want to use Airparif emission files (restricted access)
emissdir_airparif=/COMPERES/priv/chimere/emiAIRPARIF-200412/EMI_aero_2004

# Directories for boundary conditions
mozart2dir=/COMPERES/pub/chimere/MOZART2
lmdzinca2dir=/pollution1/pollux/CHIMERE/LMDZINCA
gocartdir=/COMPERES/pub/chimere/GOCART



##### Meteorological data (MM5 raw binary outputs)

mm5fil=/COMPERES/pub/MM5/AVN/${year}/EUR1/MMOUT_EUR1_${di}_${de}_S



##### Outputs directories and files

# Directory where the output files of this run will be written
simuldir=`pwd`/OUTPUTS

# If this run is a nested one, boundary conditions will be obtained
# from this coarse run output :
coarsefile=`pwd`/OUTCOARSE/out.20041226_20041230_coarse.nc

# If this run is a continuation one, initial conditions will be
# obtained from the "end" file in this directory
psimuldir=`pwd`/OUTPUTS



#######################
# Temporary directory #
#######################

chimere_tmp=`pwd`/$$
                             # All operations are done in a temporary directory.
                             # CHIMERE_TMP is the temporary directory. Give a name where
                             # there is a lot of temporary disk space
                             # The size of the directory is typically 100 mo but
                             # can be much more in high-resolution simulations
                             # CHIMERE is exectuted in this directory.
                             # !!!! This name must be an absolute path (not ./mydir ...) !!!!
clean=yes
                             # clean=no:    The entire directory is kept intact.
                             # clean=light: Only small files are kept.
                             # clean=full:  The directory is removed at the end.
                             # By setting a CHIMERE_TMP directory name that depends
                             # on process number ($$), it is possible
                             # to perform several simulations simultaneously
                             # without undesired interactions




################################
# Parameters of the simulation #
################################

aerosols=1                   # 0 for gas version
                             # 1 for aerosol version without sea salts
                             # 2 for aerosol version with sea salts
                             # 3 for aerosol version with inert sea salts

meca=MELCHIOR2               # Chemical mechanism (MELCHIOR2 or MELCHIOR1)
                             # MELCHIOR2 is the fast, reduced version of MELCHIOR1

dom=CONT3                    # Domain name, as specified in file names
                             # of the "domains" directory

levout=1                     # Number of layers in output files (starting from bottom)

ivs=1                        # Emission sublayer (2) or not (1).
                             # *** USE IVS=2 ONLY FOR THE SMALLEST DOMAIN, DO NOT NEST ANY
                             # DOMAIN WITHIN A DOMAIN WITH IVS=2

############
# Numerics #
############


phys=6                       # Frequency of physics calculation (number per hour)

step=1                       # Refined time step relative to physics calculation
                             # 1/(phys*step) is the time step in hours
                             # Down to 1/4 degree resolution, phys=6 and step=1 is fine
                             # For finer grids (5-10 kms), take at least step=4
                             # For grids of 2-5 kms, try step=6 or more

ngs=1                        # Number of Gauss-Seidel iterations in the TWOSTEP solver.
                             # Take 1 for model testing, 2 for higher accuracy.

nsu=5                        # Number of Gauss-Seidel iterations in the TWOSTEP solver during 
                             # Spin up

irs=1                        # Number of hours for Spin up 

nequil=0                     # 1 : online coupling with ISORROPIA
                             # 0 : ISORROPIA tabulation

npeq=1                       # Compute equilibrium each "npeq" physical time step : < 5

nsconcs=${nhours}            # Save all concentrations every ... hours (file end....)

nsdepos=12                   # Save all cumulated deposition every ... houres (file dep...)

###########################################
# Meteorological information  and options #
###########################################

meteo=mm5                    # Name of meteo interface. A BASH script named
                             # interf-<meteo> must be present in the meteo
                             # directory for the preparation of meteo data
                             # This script has a certain number of arguments
                             # which are passed below in this script.
                             # From these arguments, the script interf-<meteo>
                             # Must construct input files to the diagmet.f program
                             # "metargs" is the list of these arguments

mm5dom=MM5EUR1

upblmin=0     # Urban correction : Minimal urban PBL height.    Set 0 if not used
uflxadd=0     # Urban correction : Additional urban heat flux.  Set 0 if not used
uwinfac=1     # Urban correction : Urban wind factor in the SL. Set 1 if not used


###################################
# Anthropic emissions information #
###################################

emis=std                     # Anthropic emission interface: std only available at present
                             # User can define its own interface. This assumes the
                             # definition of command lines added below below the
                             # comment "Hourly anthropic emissions"
                             # std emissions are given for each model species in an ascii
                             # files containing 3 types of day per month and 12 months.

nlevemis=2                   # Number of emission levels

flatreduc=1.00               # Flat reduction of emissions (multiplication factor), which
                             # can be used for extrapolating emissions in time for another year


#################################################
# Options for boundary conditions; available :  #
# MOZART2:      For gas-phase only (monthly av) #
# LMDZINCA2:    For gas-phase only (monthly av) #
# GOCART:       For aerosols  only (monthly av) #
# set nothing if initialized to zero            #
# set latnest/topnest to "yes" if nest run      #
#################################################

latnest=no
latboungas=LMDZINCA2
latbounaer=GOCART
topnest=no 
topboungas=LMDZINCA2
topbounaer=GOCART


#############################################
# Informations about the coarse simulation  #
# only required if simulation is a nest run #
#############################################

# Coarse domain
cdom=CONT3                   # Make sure the COORD_<cdom> file is present in domains dir.


######################
# Initial conditions #
######################

init=0                       # Initialization with previous run (1) or interpolation
                             # of boundary conditions (0)



##################################
# Biogenic emissions information #
##################################

iopt_eros=1                  # Optional wind erosion dust emissions (0/1)
iopt_resu=0                  # Optional resuspension parameterization (0/1)
                             # The resuspension parameterization is
                             # to be considered as "in test"


#####################################
# End of user configurable section  #
#####################################

sim=${di}_${de}_${lab}       # Simulation label: 
                             # output files will be named out.<sim>

psim=${dib}_${deb}_${lab}    # Simulation label of previous run (if continuation run)

case ${emis} in
  std) emissdir=$emissdir_std ;;
  airparif) emissdir=$emissdir_airparif ;;
  *)   echo "*** INTERFACE ${emis} UNDEFINED"; exit 1 ;;
esac

. script_functions/chimere-mm5.exec.sh
