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/2013/dev_LOCEAN_2013/NEMOGCM/CONFIG – NEMO

source: branches/2013/dev_LOCEAN_2013/NEMOGCM/CONFIG/makenemo @ 4153

Last change on this file since 4153 was 4148, checked in by cetlod, 10 years ago

merge in trunk changes between r3853 and r3940 and commit the changes, see ticket #1169

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 9.3 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#-
80#- Initialization of the options ---
81x_d="";
82x_h="";
83x_n="";
84x_r="";
85x_m="";
86x_t="";
87x_c="";
88x_j=1;
89x_e="none";
90x_s=NEMO;
91x_v=1;
92
93#- Local variables ---
94b_n=$(basename ${0})
95OPTIND=1
96MAIN_DIR=$(cd $(dirname "$0"); pwd)
97MAIN_DIR=${MAIN_DIR%/SETTE*}
98MAIN_DIR=${MAIN_DIR%/TOOLS*}
99MAIN_DIR=${MAIN_DIR%/CONFIG*}
100export MAIN_DIR
101#
102export CONFIG_DIR=${MAIN_DIR}/CONFIG
103export TOOLS_DIR=${MAIN_DIR}/TOOLS
104export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE
105export NEMO_DIR=${MAIN_DIR}/${x_s}
106export AGRIFUSE=10
107declare -a TAB
108list_key=0
109chk_key=1
110#-
111#- FCM and functions location ---
112export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH
113
114#-
115#- Choice of the options ---
116while getopts :hd:n:r:m:j:e:s:v:t:k: V
117do
118    case $V in
119   (h) x_h=${OPTARG};
120        echo "Usage   : "${b_n} \
121       " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-s Path] [-e Path] [-j No] [-v No] [-k 0/1]";
122   echo " -h           : help";
123   echo " -h institute : specific help for consortium members";
124   echo " -n name      : config name, [-n help] to list existing configurations";
125   echo " -m arch      : choose compiler, [-m help] to list existing compilers";
126   echo " -d dir       : choose NEMO sub-directories";
127   echo " -r conf      : choose reference configuration";
128        echo " -s Path      : choose alternative location for NEMO main directory";
129        echo " -e Path      : choose alternative location for MY_SRC directory";
130        echo " -j No        : number of processes used to compile (0=nocompilation)";
131        echo " -v No        : set verbosity level for compilation [0-3]";
132        echo " -k 0/1       : used cpp keys check (default = 1 -> check activated)";
133   echo " -t dir       : temporary directory for compilation"
134   echo "";
135   echo "Example to install a new configuration MY_CONFIG";
136   echo "with OPA_SRC and LIM_SRC_2 ";
137   echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\"";
138   echo "";
139   echo "Available configurations :"; cat ${CONFIG_DIR}/cfg.txt;
140   echo "";
141   echo "Example to remove bad configuration ";
142   echo "./makenemo -n MY_CONFIG clean_config";
143   echo "";
144   echo "Example to clean ";
145   echo "./makenemo clean";
146   echo "";
147   echo "Example to list the available keys of a CONFIG ";
148   echo "./makenemo list_key";
149   echo "";
150   echo "Example to add and remove keys";
151   echo "./makenemo add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" ";
152   echo "";
153   echo "Example to add and remove keys for a new configuration, and do not compile";
154   echo "./makenemo -n MY_CONFIG -j0 add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" ";
155   echo "";
156   . ${COMPIL_DIR}/Flist_archfile.sh ${x_h}  ;
157   echo "";
158   echo "Default : previous configuration and compiler";
159   exit 0;;
160   (d)  x_d=${OPTARG};;
161   (n)  x_n=${OPTARG};;
162   (r)  x_r=${OPTARG};;
163   (m)  x_m=${OPTARG};;
164   (j)  x_j=${OPTARG};;
165   (t)  x_t=${OPTARG};;
166   (e)  x_e=${OPTARG};;
167   (s)  x_s=${OPTARG};;
168   (v)  x_v=${OPTARG};;
169   (k)  chk_key=${OPTARG};;
170   (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
171   exit 2;;
172   (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
173   exit 2;;
174    esac
175done
176shift $(($OPTIND-1));
177
178while [ ${#1} -gt 0 ]   # Get clean, clean_config options
179do
180    case "$1" in
181   clean)
182       x_c="--$1"
183       ;;
184   clean_config)
185       . ${COMPIL_DIR}/Fclean_config.sh
186       exit
187       ;;
188   add_key)
189       list_add_key=$2
190       export ${list_add_key}
191       shift
192       ;;
193   del_key)
194       list_del_key=$2
195       export ${list_del_key}
196       shift
197       ;;
198   list_key)
199       list_key=1
200       ;;
201   *)
202       echo " \"$1\" BAD OPTION"
203       exit
204       ;;
205
206    esac
207    shift
208done
209
210
211#-
212#- Go to NEMOGCM/config directory ---
213cd ${CONFIG_DIR}
214
215#-
216#- Initialisation from input ---
217export NEW_CONF=${x_n}
218NBR_PRC=${x_j}
219CMP_NAM=${x_m}
220NEM_SUBDIR=${x_d}
221REF_CONF=${x_r}
222NEMO_TDIR=${x_t:-$NEMO_TDIR}
223export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR}
224export NEMO_DIR=${MAIN_DIR}/${x_s}
225
226#- Check if the tool or the compiler exist or list it
227if [ "${NEW_CONF}" == help ] ; then
228    echo "Available configurations :"
229    cat ${CONFIG_DIR}/cfg.txt
230    exit
231fi
232[ "${CMP_NAM}" ==  help ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit
233
234#-
235#- Choose a default configuration if needed ---
236#- ORCA2_LIM or last one used ---
237. ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit
238
239if [ ${#NEW_CONF} -eq 0 ] ; then
240    if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then
241   echo "You are  installing a new configuration"
242   ind=0
243   . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC    YES
244   . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2   YES
245   . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3   NO
246   . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC    NO
247   . ${COMPIL_DIR}/Fread_dir.sh NST_SRC    YES
248   . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC    NO
249   REF_CONF=ORCA2_LIM
250    elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then
251   echo "You are  installing a new configuration"
252   TAB=( ${NEM_SUBDIR} )
253   REF_CONF=ORCA2_LIM
254    elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then
255   echo "You are  installing a new configuration based on ${REF_CONF}"
256   . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF}
257    fi
258    NEW_CONF=${x_n}
259    . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF}
260else
261    sed -e "/${NEW_CONF} /d"  ${CONFIG_DIR}/cfg.txt >  ${COMPIL_DIR}/cfg.tmp
262    \m${COMPIL_DIR}/cfg.tmp  ${CONFIG_DIR}/cfg.txt
263fi
264
265#-
266#- Save new configuration and directories names ---
267echo ${NEW_CONF} ${TAB[*]} >> ${CONFIG_DIR}/cfg.txt
268
269#-
270#- Create the WORK ---
271#- Clean links and librairies ---
272#- Creating the good links, at first on OPA_SRC ---
273. ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${TAB[*]} || exit
274
275. ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF}  ${NEMO_TDIR} || exit
276
277# build the complete list of the cpp keys of this configuration
278if [ $chk_key -eq 1 ] ; then
279    for i in $( grep "^ *#.* key_" ${NEW_CONF}/WORK/* ) 
280    do
281   echo $i | grep key_ | sed -e "s/=.*//"
282    done | sort -d | uniq > ${COMPIL_DIR}/full_key_list.txt
283    if [ $list_key -eq 1 ]; then
284   cat ${COMPIL_DIR}/full_key_list.txt
285   exit 0
286    fi
287fi
288
289#- At this stage new configuration has been added,
290#- We add or remove keys
291if [ ${#list_add_key} -ne 0 ] ; then
292    . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key}
293fi
294
295if [ ${#list_del_key} -ne 0 ] ; then
296    . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key}
297fi
298
299#- check that all keys are really existing...
300if [ $chk_key -eq 1 ] ; then
301    for kk in $( cat ${NEW_CONF}/cpp_${NEW_CONF}.fcm )
302    do
303   if [ "$( echo $kk | cut -c 1-4 )" == "key_" ]; then
304       kk=${kk/=*/}
305       nb=$( grep -c $kk ${COMPIL_DIR}/full_key_list.txt )
306       if [ $nb -eq 0 ]; then
307      echo
308      echo "E R R O R : key "$kk" is not found in ${NEW_CONF}/WORK routines..."
309      echo "we stop..."
310      echo
311      exit 1
312       fi
313   fi
314    done
315fi
316
317#- At this stage cpp keys have been updated. we can check the arch file
318#- When used for the first time, choose a compiler ---
319. ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm cpp.fcm ${CMP_NAM} || exit
320
321#- At this stage the configuration has beeen chosen
322#- We coose the default light file
323export USEBLD=bldxag.cfg
324
325#- We look after agrif
326grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/}
327. ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit
328
329#-
330#_ END OF CONFIGURATION PHASE
331#_
332
333#-
334#- Compile ---
335
336if [ "${NBR_PRC}" -gt 0 ]; then
337    cd ${NEMO_TDIR}/${NEW_CONF} || cd -
338
339#if AGRIF we do a first preprocessing
340    if [ ${#x_c} -eq 0 ]; then
341       if [ "$AGRIFUSE" == 1 ]; then
342          fcm build --ignore-lock  -j 1 ${COMPIL_DIR}/bld_preproagr.cfg ||{ cd - ; exit ;}
343          echo ""
344          echo "---------------------------------"
345          echo "CONV preprocessing successfull !!"
346          echo "---------------------------------"
347          echo ""
348       fi
349    fi
350    fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd -
351    [ -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
352
353#add remove for clean option
354    if  [ ${#x_c} -ne 0 ]; then
355        rm -rf ${NEMO_TDIR}/${NEW_CONF}/OPAFILES
356        rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK
357        rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD
358        rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa
359        rm -f ${COMPIL_DIR}/*history ${COMPIL_DIR}/*fcm ${COMPIL_DIR}/*txt
360        echo "cleaning ${NEW_CONF} WORK, BLD"
361    fi
362
363fi
364
365#- Come back to original directory ---
366cd -
367
368#-
369#- Unset variables
370${COMPIL_DIR}/Fclean_var.sh
371
372
Note: See TracBrowser for help on using the repository browser.