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 @ 2318

Last change on this file since 2318 was 2318, checked in by flavoni, 13 years ago

change script to add and remove keys for new configurations and old ones

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