#!/bin/bash # $Id: makelmdz_fcm 3406 2018-10-23 09:16:41Z jyg $ # This is a script in Bash. # FH : on ne cr\'ee plus le fichier arch.mk qui est suppos\'e exister par # FH : ailleurs. # FH : ulterieurement, ce fichier sera pr\'e-existant pour une s\'erie # FH : de configurations en versions optimis\'ees et debug qui seront # FH : li\'es (ln -s) avec arch.mk en fonction de l'architecture. # FH : Pour le moment, cette version est en test et on peut cr\'eer les # FH : arch.mk en lan\c{}cant une premi\`ere fois makegcm. # ##set -x set -e ######################################################################## # options par defaut pour la commande make ######################################################################## dim="96x72x19" physique=lmd filtre=filtrez grille=reg couple=false veget=false sisvat=false rrtm=false dust=false strataer=false chimie=false parallel=none paramem="par" compil_mod=prod io=ioipsl LIBPREFIX="" cosp=false job=1 full='' libphy=false arch_defined="FALSE" arch_path="arch" arch_default_path="arch" LMDGCM=`/bin/pwd` LIBOGCM=$LMDGCM/libo LIBFGCM=$LMDGCM/libf DYN_COMMON_PATH=$LIBFGCM/dyn3d_common # path for optional packages, but default set to ".void_dir" FILTRE_PATH=$LMDGCM/.void_dir DYN_PHYS_PATH=$LMDGCM/.void_dir DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir PHY_COMMON_PATH=$LMDGCM/.void_dir RRTM_PATH=$LMDGCM/.void_dir DUST_PATH=$LMDGCM/.void_dir STRATAER_PATH=$LMDGCM/.void_dir SISVAT_PATH=$LMDGCM/.void_dir COSP_PATH=$LMDGCM/.void_dir fcm_path=$LMDGCM/tools/fcm/bin ######################################################################## # Quelques initialisations de variables du shell. ######################################################################## CPP_KEY="" INCLUDE="" LIB="" adjnt="" COMPIL_FFLAGS="%PROD_FFLAGS" PARA_FFLAGS="" PARA_LD="" EXT_SRC="" ######################################################################## # lecture des options de mymake ######################################################################## while (($# > 0)) do case $1 in "-h") cat < .void_file rm -rf .void_dir mkdir .void_dir if [[ "$arch_defined" == "TRUE" ]] then rm -f arch.path rm -f arch.fcm rm -f arch.env if test -f $arch_path/arch-${arch}.path then ln -s $arch_path/arch-${arch}.path arch.path elif test -f $arch_default_path/arch-${arch}.path then ln -s $arch_default_path/arch-${arch}.path arch.path fi if test -f $arch_path/arch-${arch}.fcm then ln -s $arch_path/arch-${arch}.fcm arch.fcm elif test -f $arch_default_path/arch-${arch}.fcm then ln -s $arch_default_path/arch-${arch}.fcm arch.fcm fi if test -f $arch_path/arch-${arch}.env then ln -s $arch_path/arch-${arch}.env arch.env elif test -f $arch_default_path/arch-${arch}.env then ln -s $arch_default_path/arch-${arch}.env arch.env else ln -s .void_file arch.env fi # source architecture PATH and ENV files set +e source arch.env source arch.path set -e else echo "You must define a target architecture" exit 1 fi ######################################################################## # Definition des clefs CPP, des chemins des includes et modules # et des libraries ######################################################################## if [[ "$compil_mod" == "prod" ]] then COMPIL_FFLAGS="%PROD_FFLAGS" elif [[ "$compil_mod" == "dev" ]] then COMPIL_FFLAGS="%DEV_FFLAGS" elif [[ "$compil_mod" == "debug" ]] then COMPIL_FFLAGS="%DEBUG_FFLAGS" fi phys_root=$physique if [[ "${physique:0:3}" == "lmd" ]] ; then phys_root=lmd ; fi if [[ "${physique:0:4}" == "mars" ]] ; then phys_root=mars ; fi if [[ "${physique:0:3}" == "std" ]] ; then phys_root=std ; fi if [[ "${physique:0:5}" == "venus" ]] ; then phys_root=venus ; fi if [[ "${physique:0:5}" == "titan" ]] ; then phys_root=titan ; fi if [[ "${physique:0:3}" == "mar" ]] ; then phys_root=mar ; fi if [[ "${physique:0:3}" == "dev" ]] ; then phys_root=dev ; fi if [[ "$physique" != "nophys" ]] then #We'll use some physics CPP_KEY="$CPP_KEY CPP_PHYS" if [[ "${phys_root}" == "lmd" ]] then #For lmd physics, default planet type is Earth CPP_KEY="$CPP_KEY CPP_EARTH" fi # set physics common utilities path PHY_COMMON_PATH="${LIBFGCM}/phy_common" # set the dyn/phys interface path DYN_PHYS_PATH="${LIBFGCM}/dynphy_lonlat" DYN_PHYS_SUB_PATH="${LIBFGCM}/dynphy_lonlat/phy${phys_root}" fi if [[ "$filtre" == "filtrez" ]] then FILTRE_PATH=${LIBFGCM}/$filtre fi if [[ "$chimie" == "INCA" ]] then CPP_KEY="$CPP_KEY INCA" INCLUDE="$INCLUDE -I${INCA_INCDIR}" LIB="$LIB -L${INCA_LIBDIR} ${INCA_LIB}" fi if [[ "$couple" != "false" ]] then if [[ "$couple" == "MPI1" ]] then CPP_KEY="$CPP_KEY CPP_COUPLE" export OASIS_INCDIR=$LMDGCM/../../prism/X64/build/lib/psmile.MPI1 export OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib INCLUDE="$INCLUDE -I${OASIS_INCDIR}" LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}" else CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT" INCLUDE="$INCLUDE -I${OASIS_INCDIR}" LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}" fi fi if [[ "$parallel" == "mpi" ]] then CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI" PARA_FFLAGS="%MPI_FFLAGS" PARA_LD="%MPI_LD" elif [[ "$parallel" == "omp" ]] then CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP" PARA_FFLAGS="%OMP_FFLAGS" PARA_LD="%OMP_LD" elif [[ "$parallel" == "mpi_omp" ]] then CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP" PARA_FFLAGS="%MPI_FFLAGS %OMP_FFLAGS" PARA_LD="%MPI_LD %OMP_LD" fi if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \ && "$compil_mod" == "debug" ]] then echo "Usually, parallelization with OpenMP requires some optimization." echo "We suggest switching to \"-dev\"." fi if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" ] then #NB: option 'true': for backward compatibility. To be used with ORCHIDEE tag 1.9-1.9.6 # For this case, cpp flag ORCHIDEE_NOOPENMP must be added to the makelmdz_fcm arguments # option orchidee1.9 : Compile with ORCHIDEE version up to the inclusion of OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6 INCLUDE="${INCLUDE} ${ORCHIDEE_INCDIR}" CPP_KEY="$CPP_KEY CPP_VEGET" # temporary, for Orchidee versions 1.9.* (before openmp activation) if [[ "$veget" == "orchidee1.9" ]] ; then CPP_KEY="$CPP_KEY ORCHIDEE_NOOPENMP" fi if [[ "$veget" == "orchidee2.0" ]] ; then orch_libs="sechiba parameters stomate parallel orglob orchidee" else orch_libs="sechiba parameters stomate parallel orglob" fi LIB="${LIB} -L${ORCHIDEE_LIBDIR} ${ORCHIDEE_LIB}" elif [[ "$veget" != "false" ]] ; then echo "Option -v $veget does not exist" echo "Use ./makelmdz_fcm -h for more information" exit fi if [[ "$sisvat" == "true" ]] then CPP_KEY="$CPP_KEY CPP_SISVAT" SISVAT_PATH="$LIBFGCM/%PHYS/sisvat" fi if [[ "$rrtm" == "true" ]] then CPP_KEY="$CPP_KEY CPP_RRTM" RRTM_PATH="$LIBFGCM/%PHYS/rrtm" fi if [[ "$dust" == "true" ]] then CPP_KEY="$CPP_KEY CPP_Dust" DUST_PATH="$LIBFGCM/%PHYS/Dust" fi if [[ "$strataer" == "true" ]] then CPP_KEY="$CPP_KEY CPP_StratAer" STRATAER_PATH="$LIBFGCM/%PHYS/StratAer" fi if [[ $io == ioipsl ]] then CPP_KEY="$CPP_KEY CPP_IOIPSL" INCLUDE="$INCLUDE ${IOIPSL_INCDIR}" LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB}" elif [[ $io == mix ]] then # For now, xios implies also using ioipsl CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS" INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}" LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}" elif [[ $io == xios ]] then # For now, xios implies also using ioipsl CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS CPP_IOIPSL_NO_OUTPUT" INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}" LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}" fi if [[ "$cosp" == "true" ]] then CPP_KEY="$CPP_KEY CPP_COSP" COSP_PATH="$LIBFGCM/phylmd/cosp" # LIB="${LIB} -l${LIBPREFIX}cosp" fi # NETCDF library include/library paths INCLUDE="$INCLUDE ${NETCDF_INCDIR}" LIB="$LIB ${NETCDF_LIBDIR} ${NETCDF_LIB}" ######################################################################## # calcul du nombre de dimensions ######################################################################## dim_full=$dim dim=`echo $dim | sed -e 's/[^0-9]/ /g'` set $dim dimc=$# echo calcul de la dimension echo dim $dim echo dimc $dimc ######################################################################## # Gestion des dimensions du modele. # on cree ou remplace le fichier des dimensions ######################################################################## cd $LIBFGCM/grid if [[ -f dimensions.h ]] then echo 'ATTENTION: vous etes sans doute en train de compiler le modele par ailleurs' echo "Attendez que la premiere compilation soit terminee pour relancer la suivante." echo "Si vous etes sur que vous ne compilez pas le modele par ailleurs," echo vous pouvez continuer en repondant oui. echo "Voulez-vous vraiment continuer?" echo "" echo "WARNING: you are probably already compiling the model somewhere else." echo "Wait until the first compilation is finished before launching this one." echo "If you are sure that you are not compiling elsewhere, just answer " echo "yes (or 'oui') to the question below to proceed." echo "Do you wish to continue?" read reponse if [[ $reponse == "oui" || $reponse == "yes" ]] then \rm -f $LIBFGCM/grid/dimensions.h else exit fi fi cd $LIBFGCM/grid/dimension ./makdim $dim cat $LIBFGCM/grid/dimensions.h cd $LMDGCM ######################################################################## # Differentes dynamiques (3d, 2d, 1d) ######################################################################## dimension=`echo $dim | wc -w` echo dimension $dimension if (( $dimension == 3 )) then cd $LIBFGCM/grid \rm fxyprim.h cp -p fxy_${grille}.h fxyprim.h #else # echo "Probleme dans les dimensions de la dynamique !!" # echo "Non reactive pour l'instant !!!" fi if (( $dimension == 1 )) then CPP_KEY="$CPP_KEY CPP_1D" ##in 1D, add dyn3d to include path (because main prog is in physics) INCLUDE="$INCLUDE -Ilibf/dyn3d -Ilibf/dyn3d_common" ## no filtre in 1d: FILTRE_PATH=$LMDGCM/.void_dir ## no need to compile all routines in dyn3d_common either: DYN_COMMON_PATH=$LMDGCM/.void_dir ## no need to compile all routines in dynlmdz_phy... ; ## (because key ones are included in 1D main program) DYN_PHYS_PATH=$LMDGCM/.void_dir DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir fi ###################################################################### # Traitement special pour le nouveau rayonnement de Laurent Li. # ---> YM desactive pour le traitemement en parallele ###################################################################### #if [[ -f $libf/phy$physique/raddim.h ]] #then # if [[ -f $libf/phy$physique/raddim.$dimh.h ]] #then # \rm -f $libf/phy$physique/raddim.h # cp -p $libf/phy$physique/raddim.$dimh.h $libf/phy$physique/raddim.h # echo $libf/phy$physique/raddim.$dimh.h # cat $libf/phy$physique/raddim.h # else # echo On peut diminuer la taille de l executable en creant # echo le fichier $libf/phy$physique/raddim.$dimh.h # \cp -p $libf/phy$physique/raddim.defaut.h $libf/phy$physique/raddim.h # fi #fi ###################################################################### # Gestion du filtre qui n'existe qu'en 3d. ###################################################################### if (( `expr $dimc \> 2` == 1 )) then filtre="FILTRE=$filtre" else filtre="FILTRE= L_FILTRE= " fi echo MACRO FILTRE $filtre echo $dimc ###################################################################### # Creation du suffixe de la configuration ###################################################################### SUFF_NAME=_${dim_full} SUFF_NAME=${SUFF_NAME}_phy${physique} if [[ "$parallel" != "none" ]] then SUFF_NAME=${SUFF_NAME}_para DYN=dyn${dimc}d${paramem} if [[ "$paramem" == "mem" ]] then SUFF_NAME=${SUFF_NAME}_${paramem} else echo "The version of the dynamics in dyn3dpar is no longer updated." echo "You should use option \"-mem\"." exit 1 fi else SUFF_NAME=${SUFF_NAME}_seq if (( $dimension == 1 )) then # dynamics-related routines in"dyn1d" subdirectory of phy${physique} DYN=phy${physique}/dyn1d else DYN=dyn${dimc}d fi fi if [[ $veget != "false" ]] then SUFF_NAME=${SUFF_NAME}_orch fi if [[ $couple != "false" ]] then SUFF_NAME=${SUFF_NAME}_couple fi if [[ $chimie == "INCA" ]] then SUFF_NAME=${SUFF_NAME}_inca fi if [[ $libphy == "true" ]] then # special case where we compile only the physics DYN=$LMDGCM/.void_dir DYN_COMMON_PATH=$LMDGCM/.void_dir FILTRE_PATH=$LMDGCM/.void_dir DYN_PHYS_PATH=$LMDGCM/.void_dir DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir #and there is no main program to generate code="" SUFF_NAME="" else SUFF_NAME=${SUFF_NAME}.e fi cd $LMDGCM config_fcm="config.fcm" rm -f $config_fcm touch $config_fcm rm -f bin/${code}${SUFF_NAME}.e rm -f arch.fcm rm -f arch.opt echo "%ARCH $arch" >> $config_fcm echo "%INCDIR $INCLUDE" >> $config_fcm echo "%LIB $LIB" >> $config_fcm echo "%ROOT_PATH $PWD" >> $config_fcm echo "%LIBF $LIBFGCM" >> $config_fcm echo "%LIBO $LIBOGCM" >> $config_fcm echo "%DYN $DYN" >> $config_fcm echo "%DYN_COMMON $DYN_COMMON_PATH" >> $config_fcm echo "%PHY_COMMON $PHY_COMMON_PATH" >> $config_fcm echo "%FILTRE $FILTRE_PATH" >> $config_fcm echo "%PHYS phy${physique}" >> $config_fcm echo "%DYN_PHYS $DYN_PHYS_PATH" >> $config_fcm echo "%DYN_PHYS_SUB $DYN_PHYS_SUB_PATH" >> $config_fcm echo "%RRTM $RRTM_PATH" >> $config_fcm echo "%DUST $DUST_PATH" >> $config_fcm echo "%STRATAER $STRATAER_PATH" >> $config_fcm echo "%SISVAT $SISVAT_PATH" >> $config_fcm echo "%COSP $COSP_PATH" >> $config_fcm echo "%CPP_KEY $CPP_KEY" >> $config_fcm echo "%EXEC $code" >> $config_fcm echo "%SUFF_NAME $SUFF_NAME" >> $config_fcm echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> $config_fcm echo "%PARA_FFLAGS $PARA_FFLAGS" >> $config_fcm echo "%PARA_LD $PARA_LD" >> $config_fcm echo "%EXT_SRC $EXT_SRC" >> $config_fcm ln -s arch/arch-${arch}.fcm arch.fcm if test -f arch/arch-${arch}.opt && [ $compil_mod = "prod" ] then ln -s arch/arch-${arch}.opt arch.opt else ln -s .void_file arch.opt fi rm -f $LIBOGCM/${arch}${SUFF_NAME}/.config/fcm.bld.lock set +e ./build_gcm ${fcm_path} -j $job $full status=$? rm -rf tmp_src rm -rf config ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config config ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config/ppsrc tmp_src if [[ -r $LIBFGCM/grid/dimensions.h ]] then # Cleanup: remove dimension.h file \rm -f $LIBFGCM/grid/dimensions.h fi if [ $status -ne 0 ]; then exit $status fi