#!/bin/bash
#
# define_config.sh is called from the main compilation script compile_ipslcm7.sh
# The script will define which components to compile.
# By default all availble components are compiled.
#
# Step 1: The avaible components are defined. 
# Step 2: Define which components to compile. If argument [-subconfig subconfig] is set 
#         to the main compilation script, a control if the components needed are avaiable. 
#         If argument is subconfig is not set, the components defined in step 1 will be defined.


### Step 1: Check available components possible to compile
# LMDZ, ORCHIDEE and XIOS are considered mandatory and will not be checked.

if [ -d ../../modeles/NEMO ] ; then
    compnemo=y
else
    compnemo=n
fi

if [ -d ../../modeles/INCA ] ; then
    compinca=y
else
    compinca=n
fi

if [ -d ../../modeles/DYNAMICO ] ; then
    compdyna=y
else
    compdyna=n
fi

if [ -d ../../oasis3-mct ] ; then
    compoasis=y
else
    compoasis=n
fi



### Step 2: Define which components to compile. Check if the configuration set as argument is possible
if [ $subconfig == default ] ; then
    echo ; echo Compilation of all availble components will be done:
    echo compinca=$compinca compnemo=$compnemo compoasis=$compoasis compdyna=$compdyna complmdz=y comporch=y compxios=y
elif [ $subconfig == ICOLMDZORINCA ] ; then
    if [ $compinca == n ] || [ $compdyna == n ] ; then
	echo ; echo It is not possible to compile ICOLMDZORINCA.
	echo INCA or DYNAMICO source code is missing
        exit
    else
	echo Compilation of ICOLMDZORINCA configuration will be done
    fi	
elif [ $subconfig == ICOLMDZOR ] ; then
    if [ $compdyna == n ] ; then
	echo ; echo It is not possible to compile ICOLMDZOR
	echo DYNAMICO source code is missing
        exit
    else
	echo Compilation of ICOLMDZOR configuration will be done
    fi
elif [ $subconfig == LMDZORINCA ] ; then
    if [ $compinca == n ] ; then
	echo ; 	echo It is not possible to compile LMDZORINCA.
	echo INCA source code is missing
        exit
    else
	regular_latlon=yes
	echo Compilation of regular LMDZORINCA configuration for grid $resol_atm will be done 
    fi	
elif [ $subconfig == LMDZOR ] ; then
    regular_latlon=yes
    # We always suppose that LMDZ and ORCHIDEE are extracted. No check needs to be done.
    echo Compilation of regular LMDZOR configuration for grid $resol_atm will be done
else
    echo ; echo The configuration $subconfig is not available
    echo Choose between ICOLMDZORINCA ICOLMDZOR LMDZORINCA or LMDZOR 
    echo Exit now
    exit
fi
echo ;

