New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
makenemo in branches/2011/dev_r2802_MERCATOR9_floats/NEMOGCM/CONFIG – NEMO

source: branches/2011/dev_r2802_MERCATOR9_floats/NEMOGCM/CONFIG/makenemo @ 2845

Last change on this file since 2845 was 2731, checked in by rblod, 13 years ago

Changes for Agrif in MPI

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1#!/bin/bash
2#set -x
3set -o posix
4#set -u
5#set -e
6#+
7#
8# ===============
9# makenemo
10# ===============
11#
12# --------------------------
13# Compile NEMO
14# --------------------------
15#
16# SYNOPSIS
17# ========
18#
19# ::
20#
21#  $ makenemo
22#
23#
24# DESCRIPTION
25# ===========
26#
27#
28# This script aims :
29#
30# - to choose MYCONFIG
31# - to choose compiler options 
32# - to create the CONFIG/MYCONFIG/WORK directory
33# - to compile this configuration
34#
35#  Variables used :
36#
37#  From user input
38#
39# - NEW_CONF    : configuration to be created
40# - REF_CONF    : reference configuration to build the new one
41# - CMP_NAM     : compiler name
42# - NBR_PRC     : number of processes used to compile 
43# - NEM_SUBDIR  : NEMO subdirectory used (specified)
44#
45#  Locally defined :
46#
47# - TAB         : NEMO subdirectory used (read) 
48# - MAIN_DIR    : self explaining
49# - CONFIG_DIR  :   "    "    "   
50# - MODELES_DIR :   "    "    "
51# - TOOLS_DIR   :   "    "    "
52# - NEMO_DIR    :   "    "    "
53#
54# EXAMPLES
55# ========
56#
57# ::
58#
59#  $ ./makenemo -m ifort_osx - j3 -n ORCA2_LIM
60#
61#
62# TODO
63# ====
64#
65# option debug
66#
67#
68# EVOLUTIONS
69# ==========
70#
71# $Id$
72#
73#
74#
75#   * creation
76#
77#-
78
79#- Local variables ---
80b_n=$(basename ${0})
81OPTIND=1
82MAIN_DIR=$(cd $(dirname "$0"); pwd)
83MAIN_DIR=${MAIN_DIR%/SETTE*}
84MAIN_DIR=${MAIN_DIR%/TOOLS*}
85MAIN_DIR=${MAIN_DIR%/CONFIG*}
86export MAIN_DIR
87#
88export CONFIG_DIR=${MAIN_DIR}/CONFIG
89export TOOLS_DIR=${MAIN_DIR}/TOOLS
90export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE
91export NEMO_DIR=${MAIN_DIR}/NEMO
92export AGRIFUSE=10
93
94declare -a TAB
95#-
96#- FCM and functions location ---
97export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH
98
99#-
100#- Choice of the options ---
101x_d="";
102x_n="";
103x_r="";
104x_m="";
105x_t="";
106x_c="";
107x_j=1;
108while getopts :hd:n:r:m:j:t: V
109do
110    case $V in
111   (h)  echo "Usage   : "${b_n} \
112       " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-j No]";
113   echo " -h    : help";
114   echo " -n name : config name, [-n help] to list existing configurations";
115   echo " -m arch : choose compiler, [-m help] to list existing compilers";
116   echo " -d dir  : choose NEMO sub-directories";
117   echo " -r conf : choose reference configuration";
118   echo " -j No    : number of processes used to compile (0=nocompilation)";
119   echo " -t dir  : temporary directory for compilation"
120   echo "";
121   echo "Example to install a new configuration MY_CONFIG";
122   echo "with OPA_SRC and LIM_SRC_2 ";
123   echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\"";
124   echo "";
125   echo "Available configurations :"; cat ${COMPIL_DIR}/cfg.txt;
126   echo "";
127   echo "Example to remove bad configuration ";
128   echo "./makenemo -n MY_CONFIG clean_config";
129   echo "";
130   echo "Example to clean ";
131   echo "./makenemo clean";
132   echo "";
133   echo "Example to add and remove keys";
134   echo "./makenemo add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" ";
135   echo "";
136   echo "Example to add and remove keys for a new configuration, and do not compile";
137   echo "./makenemo -n MY_CONFIG -j0 add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" ";
138   echo "";
139   . ${COMPIL_DIR}/Flist_archfile.sh  ;
140   echo "";
141   echo "Default : previous configuration and compiler";
142   exit 0;;
143   (d)  x_d=${OPTARG};;
144   (n)  x_n=${OPTARG};;
145   (r)  x_r=${OPTARG};;
146   (m)  x_m=${OPTARG};;
147   (j)  x_j=${OPTARG};;
148   (t)  x_t=${OPTARG};;
149   (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
150   exit 2;;
151   (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
152   exit 2;;
153    esac
154done
155shift $(($OPTIND-1));
156
157while [ ${#1} -gt 0 ]   # Get clean, clean_config options
158do
159    case "$1" in
160   clean)
161       x_c="--$1"
162       ;;
163   clean_config)
164       . ${COMPIL_DIR}/Fclean_config.sh
165       exit
166       ;;
167   add_key)
168       list_add_key=$2
169       export ${list_add_key}
170       shift
171       ;;
172   del_key)
173       list_del_key=$2
174       export ${list_del_key}
175       shift
176       ;;
177   *)
178       echo " \"$1\" BAD OPTION" 
179       exit
180       ;;
181   
182    esac
183    shift
184done
185
186
187#-
188#- Go to NEMOGCM/config directory ---
189cd ${CONFIG_DIR}
190
191#-
192#- Initialisation from input ---
193export NEW_CONF=${x_n}
194NBR_PRC=${x_j}
195CMP_NAM=${x_m}
196NEM_SUBDIR=${x_d}
197REF_CONF=${x_r}
198NEMO_TDIR=${x_t:-$NEMO_TDIR}
199export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR}
200
201#- Check if the tool or the compiler exist or list it
202if [ "${NEW_CONF}" == help ] ; then
203    echo "Available configurations :" 
204    cat ${COMPIL_DIR}/cfg.txt
205    exit
206fi
207[ "${CMP_NAM}" ==  help ] && . ${COMPIL_DIR}/Flist_archfile.sh && exit
208
209#- When used for the first time, choose a compiler ---
210. ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm ${CMP_NAM} || exit
211
212#-
213#- Choose a default configuration if needed ---
214#- ORCA2_LIM or last one used ---
215. ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit
216
217
218if [ ${#NEW_CONF} -eq 0 ] ; then
219    if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then
220   echo "You are  installing a new configuration"
221   ind=0
222   . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC    YES
223   . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2   YES
224   . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3   NO 
225   . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC    NO 
226   . ${COMPIL_DIR}/Fread_dir.sh NST_SRC    YES
227   . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC    NO 
228   REF_CONF=ORCA2_LIM
229    elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then
230   echo "You are  installing a new configuration"
231   TAB=( ${NEM_SUBDIR} )
232   REF_CONF=ORCA2_LIM
233    elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then
234   echo "You are  installing a new configuration based on ${REF_CONF}"
235   . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} 
236    fi
237    NEW_CONF=${x_n}
238    . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF}
239else
240    sed -e "/${NEW_CONF} /d"  ${COMPIL_DIR}/cfg.txt >  ${COMPIL_DIR}/cfg.tmp
241    \m${COMPIL_DIR}/cfg.tmp  ${COMPIL_DIR}/cfg.txt
242fi
243
244#-
245#- Save new configuration and directories names ---
246echo ${NEW_CONF} ${TAB[*]} >> ${COMPIL_DIR}/cfg.txt
247
248#-
249#- Create the WORK ---
250#- Clean links and librairies ---
251#- Creating the good links, at first on OPA_SRC ---
252. ${COMPIL_DIR}/Fmake_WORK.sh ${NEW_CONF} ${TAB[*]} || exit
253
254. ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF}  ${NEMO_TDIR} || exit
255
256#- At this stage new configuration has been added,
257#- We add or remove keys
258if [ ${#list_add_key} -ne 0 ] ; then
259    . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key} 
260fi
261
262if [ ${#list_del_key} -ne 0 ] ; then
263    . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key}
264fi
265
266#- At this stage the configuration has beeen chosen
267#- We coose the default light file
268export USEBLD=bldxioxag.cfg
269
270#- We look after agrif
271grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/}
272. ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit
273
274#- and test whether we need to build the ioserver
275grep key_iomput ${COMPIL_DIR}/cpp.fcm && export USEBLD=${USEBLD/xio/}
276
277#-
278#_ END OF CONFIGURATION PHASE
279#_
280
281#-
282#- Compile ---
283
284if [ "${NBR_PRC}" -gt 0 ]; then
285    cd ${NEMO_TDIR}/${NEW_CONF} || cd -
286
287#if AGRIF we do a first preprocessing
288    if [ ${#x_c} -eq 0 ]; then
289        [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${COMPIL_DIR}/$USEBLD
290        [ "$AGRIFUSE" == 1 ] && rm -rf  ${NEMO_TDIR}/${NEW_CONF}/BLD/*
291    fi
292    fcm build ${x_c} --ignore-lock -v 1 -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd -
293    [ -f ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe ] && ln -sf ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe  ${CONFIG_DIR}/${NEW_CONF}/EXP00/opa
294    [ -f ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/server.exe ] && ln -sf ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/server.exe  ${CONFIG_DIR}/${NEW_CONF}/EXP00/server.exe
295
296#add remove for clean option
297    if  [ ${#x_c} -ne 0 ]; then
298        rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK
299        rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD
300        rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa
301        rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/server.exe
302        echo "cleaning ${NEW_CONF} WORK, BLD"
303    fi
304
305fi
306
307#- Come back to original directory ---
308cd -
309
310#-
311#- Unset variables
312${COMPIL_DIR}/Fclean_var.sh
313
314
Note: See TracBrowser for help on using the repository browser.