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/2014/dev_r4743_NOC2_ZTS/NEMOGCM/CONFIG – NEMO

source: branches/2014/dev_r4743_NOC2_ZTS/NEMOGCM/CONFIG/makenemo @ 4837

Last change on this file since 4837 was 4837, checked in by acc, 10 years ago

Branch 2014/dev_r4743_NOC2_ZTS. Added makenemo changes and associated COMPILE scripts to provide options for unsupported (external) configurations. This is not yet widely tested but should not interfer with existing options. See ticket #1367.

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