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

source: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/makenemo @ 7188

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