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

source: branches/nemo_v3_3_beta/NEMOGCM/CONFIG/makenemo @ 2302

Last change on this file since 2302 was 2302, checked in by flavoni, 14 years ago

add options: add_key and del_key to makenemo script, see ticket #740

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.4 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#- Local variables ---
80b_n=$(basename ${0})
81export MAIN_DIR=${PWD%/CONFIG*}
82export CONFIG_DIR=${MAIN_DIR}/CONFIG
83export TOOLS_DIR=${MAIN_DIR}/TOOLS
84export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE
85export NEMO_DIR=${MAIN_DIR}/NEMO
86export AGRIFUSE=10
87
88declare -a TAB
89#-
90#- FCM and functions location ---
91export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH
92
93#-
94#- Choice of the options ---
95x_d="";
96x_n="";
97x_r="";
98x_m="";
99x_t="";
100x_c="";
101x_j=1;
102while getopts :hd:n:r:m:j:t: V
103  do
104    case $V in
105      (h)  echo "Usage   : "${b_n} \
106                " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-j No]";
107           echo " -h  : help";
108           echo " -n name : config name, [-n help] to list existing configurations";
109           echo " -m arch : choose compiler, [-m help] to list existing compilers";
110           echo " -d dir  : choose NEMO sub-directories";
111           echo " -r conf : choose reference configuration";
112           echo " -j No  : number of processes used to compile (0=nocompilation)";
113           echo " -t dir  : temporary directory for compilation"
114           echo "";
115           echo "Example to install a new configuration MY_CONFIG";
116           echo "with OPA_SRC and LIM_SRC_2 ";
117           echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\"";
118           echo "";
119                          echo "Available configurations :"; cat ${COMPIL_DIR}/cfg.txt;
120           echo "";
121           echo "Example to remove bad configuration ";
122           echo "./makenemo -n MY_CONFIG clean_config";
123                          echo "";
124           echo "Example to clean ";
125           echo "./makenemo clean";
126                          echo "";
127           echo "Example to add and remove keys ";
128           echo "./makenemo add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" ";
129                          echo "";
130                          . ${COMPIL_DIR}/Flist_archfile.sh  ;
131                          echo "";
132                          echo "Default : previous configuration and compiler";
133           exit 0;;
134      (d)  x_d=${OPTARG};;
135      (n)  x_n=${OPTARG};;
136      (r)  x_r=${OPTARG};;
137      (m)  x_m=${OPTARG};;
138      (j)  x_j=${OPTARG};;
139      (t)  x_t=${OPTARG};;
140      (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
141           exit 2;;
142      (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
143           exit 2;;
144    esac
145  done
146shift $(($OPTIND-1));
147
148while [ ${#1} -gt 0 ]   # Get clean, clean_config options
149do
150    case "$1" in
151   clean)
152      x_c="--$1"
153         ;;
154   clean_config)
155      . ${COMPIL_DIR}/Fclean_config.sh
156      exit
157         ;;
158   add_key)
159      list_add_key=$2
160      export ${list_add_key}
161      shift
162         ;;
163   del_key)
164      list_del_key=$2
165      export ${list_del_key}
166      shift
167         ;;
168   *)
169         echo "BAD OPTION" 
170      exit
171         ;;
172
173   esac
174shift
175done
176
177
178#-
179#- Go to NEMOGCM/config directory ---
180cd ${CONFIG_DIR}
181
182#-
183#- Initialisation from input ---
184export NEW_CONF=${x_n}
185NBR_PRC=${x_j}
186CMP_NAM=${x_m}
187NEM_SUBDIR=${x_d}
188REF_CONF=${x_r}
189NEMO_TDIR=${x_t:-$NEMO_TDIR}
190export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR}
191
192#- Check if the tool or the compiler exist or list it
193if [ "${NEW_CONF}" == help ] ; then
194 echo "Available configurations :" 
195 cat ${COMPIL_DIR}/cfg.txt
196exit
197fi
198[ "${CMP_NAM}" ==  help ] && . ${COMPIL_DIR}/Flist_archfile.sh && exit
199
200#- When used for the first time, choose a compiler ---
201. ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm ${CMP_NAM} || exit
202
203#-
204#- Choose a default configuration if needed ---
205#- ORCA2_LIM or last one used ---
206. ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit
207
208if [ ${#NEW_CONF} -eq 0 ] ; then
209   if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then
210      echo "You are  installing a new configuration"
211      ind=0
212      . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC   YES
213      . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2   YES
214      . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3    NO 
215      . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC    NO 
216      . ${COMPIL_DIR}/Fread_dir.sh C1D_SRC   YES
217      . ${COMPIL_DIR}/Fread_dir.sh NST_SRC   YES
218      . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC    NO 
219      REF_CONF=ORCA2_LIM
220   elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then
221      echo "You are  installing a new configuration"
222      TAB=( ${NEM_SUBDIR} )
223      REF_CONF=ORCA2_LIM
224   elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then
225      echo "You are  installing a new configuration based on ${REF_CONF}"
226      . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} 
227   fi
228   NEW_CONF=${x_n}
229    . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF}
230else
231   sed -e "/${NEW_CONF} /d"  ${COMPIL_DIR}/cfg.txt >  ${COMPIL_DIR}/cfg.tmp
232   \m${COMPIL_DIR}/cfg.tmp  ${COMPIL_DIR}/cfg.txt
233fi
234
235#-
236#- Save new configuration and directories names ---
237echo ${NEW_CONF} ${TAB[*]} >> ${COMPIL_DIR}/cfg.txt
238
239#-
240#- Create the WORK ---
241#- Clean links and librairies ---
242#- Creating the good links, at first on OPA_SRC ---
243. ${COMPIL_DIR}/Fmake_WORK.sh ${NEW_CONF} ${TAB[*]} || exit
244
245. ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF}  ${NEMO_TDIR} || exit
246
247#- At this stage new configuration has been added,
248#- We add or remove keys
249if [ ${#list_add_key} -ne 0 ] ; then
250   . ${COMPIL_DIR}/Fadd_keys.sh ${list_add_key} 
251fi
252
253if [ ${#list_del_key} -ne 0 ] ; then
254   . ${COMPIL_DIR}/Fdel_keys.sh
255fi
256
257#- At this stage the configuration has beeen chosen
258#- We look after agrif
259grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1
260. ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit
261
262#- and test whether we need to build the ioserver
263export USEBLD=bldxio.cfg
264grep key_iomput ${COMPIL_DIR}/cpp.fcm && export USEBLD=bld.cfg
265
266#-
267#_ END OF CONFIGURATION PHASE
268#_
269
270#-
271#- Compile ---
272
273if [ "${NBR_PRC}" -gt 0 ]; then
274   cd ${NEMO_TDIR}/${NEW_CONF} || cd -
275
276   #if AGRIF we do a first preprocessing
277   if [ ${#x_c} -eq 0 ]; then
278      [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${COMPIL_DIR}/$USEBLD 
279      [ "$AGRIFUSE" == 1 ] && rm -rf  ${NEMO_TDIR}/${NEW_CONF}/BLD/*
280   fi
281   fcm build ${x_c} --ignore-lock -v 1 -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd -
282   [ -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
283   [ -f ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/server.exe ] && ln -sf ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/server.exe  ${CONFIG_DIR}/${NEW_CONF}/EXP00/server.exe
284
285   #add remove for clean option
286   if  [ ${#x_c} -ne 0 ]; then
287   rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK
288   rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD
289   rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa
290   rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/server.exe
291   echo "cleaning ${NEW_CONF} WORK, BLD"
292  fi
293     
294fi
295
296#-
297#- Come back to original directory ---
298cd -
299
300#-
301#- Unset variables
302${COMPIL_DIR}/Fclean_var.sh
303
304
305exit 0;
Note: See TracBrowser for help on using the repository browser.