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

source: trunk/NEMOGCM/CONFIG/makenemo @ 3922

Last change on this file since 3922 was 3922, checked in by smasson, 11 years ago

trunk:compilation enhancements, see ticket #1117

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