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

source: branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/CONFIG/makenemo @ 4093

Last change on this file since 4093 was 4093, checked in by andrewryan, 11 years ago

Added a symbolic link of the offline obs_oper executable to the EXP00 directory when a build is succesful and the offline obs_oper is selected

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