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

source: branches/DEV_r1879_FCM/NEMOGCM/CONFIG/makenemo @ 2158

Last change on this file since 2158 was 2158, checked in by rblod, 14 years ago

FCM branch, improve clean option

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 6.2 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 -t 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%/NEMOGCM*}/NEMOGCM
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
87declare -a TAB
88#-
89#- FCM and functions location ---
90export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH
91
92#-
93#- Choice of the options ---
94x_d="";
95x_n="";
96x_r="";
97x_m="";
98x_t="";
99x_c="";
100x_j=1;
101while getopts :hd:n:r:m:j:t: V
102  do
103    case $V in
104      (h)  echo "Usage   : "${b_n} \
105                " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-j No]";
106           echo " -h  : help";
107           echo " -n name : config name, [-n help] to list existing configurations";
108           echo " -m arch : choose compiler, [-m help] to list exiting compilers";
109           echo " -d dir  : choose NEMO sub-directories";
110           echo " -r conf : choose reference configuration";
111           echo " -j No  : number of processes used to compile (0=nocompilation)";
112           echo " -t dir  : remporary directory for compilation"
113           echo "";
114           echo "Example to install a new configuration MY_CONFIG";
115           echo "with OPA_SRC and LIM_SRC_2 ";
116           echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\"";
117           echo "";
118                          echo "Available configurations :"; cat ${COMPIL_DIR}/cfg.txt;
119           echo "";
120                          . ${COMPIL_DIR}/Flist_archfile.sh  ;
121                          echo "";
122                          echo "Default : previous configuration and compiler";
123           exit 0;;
124      (d)  x_d=${OPTARG};;
125      (n)  x_n=${OPTARG};;
126      (r)  x_r=${OPTARG};;
127      (m)  x_m=${OPTARG};;
128      (j)  x_j=${OPTARG};;
129      (t)  x_t=${OPTARG};;
130      (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
131           exit 2;;
132      (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
133           exit 2;;
134    esac
135  done
136shift $(($OPTIND-1));
137
138#-
139#- Get the clean option
140[[ "${#@}" -ne 0 && "${@}" != clean ]] && echo "Invalid option "$@" " && exit
141[ "${#@}" -ne 0 ] && x_c="--$@"
142
143#-
144#- Go to NEMOGCM/config directory ---
145cd ${CONFIG_DIR}
146
147#-
148#- Initialisation from input ---
149export NEW_CONF=${x_n}
150NBR_PRC=${x_j}
151CMP_NAM=${x_m}
152NEM_SUBDIR=${x_d}
153REF_CONF=${x_r}
154NEMO_TDIR=${x_t:-$NEMO_TDIR}
155export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR}
156
157#- Check if the tool or the compiler exist or list it
158if [ "${NEW_CONF}" == help ] ; then
159 echo "Available configurations :" 
160 cat ${COMPIL_DIR}/cfg.txt
161exit
162fi
163[ "${CMP_NAM}" ==  help ] && . ${COMPIL_DIR}/Flist_archfile.sh && exit
164
165#- When used for the first time, choose a compiler ---
166. ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm ${CMP_NAM} || exit
167
168#-
169#- Choose a default configuration if needed ---
170#- ORCA2_LIM or last one used ---
171. ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit
172
173if [ ${#NEW_CONF} -eq 0 ] ; then
174   if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then
175      echo "You are  installing a new configuration"
176      ind=0
177      . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC   YES
178      . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2   YES
179      . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3    NO 
180      . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC    NO 
181      . ${COMPIL_DIR}/Fread_dir.sh C1D_SRC   YES
182      . ${COMPIL_DIR}/Fread_dir.sh NST_SRC   YES
183      . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC    NO 
184      REF_CONF=ORCA2_LIM
185   elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then
186      echo "You are  installing a new configuration"
187      TAB=( ${NEM_SUBDIR} )
188      REF_CONF=ORCA2_LIM
189   elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then
190      echo "You are  installing a new configuration based on ${REF_CONF}"
191      . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} 
192   fi
193   NEW_CONF=${x_n}
194    . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF}
195else
196   sed -e "/${NEW_CONF} /d"  ${COMPIL_DIR}/cfg.txt >  ${COMPIL_DIR}/cfg.tmp
197   \m${COMPIL_DIR}/cfg.tmp  ${COMPIL_DIR}/cfg.txt
198fi
199
200#-
201#- Save new configuration and directories names ---
202echo ${NEW_CONF} ${TAB[*]} >> ${COMPIL_DIR}/cfg.txt
203
204#-
205#- Create the WORK ---
206#- Clean links and librairies ---
207#- Creating the good links, at first on OPA_SRC ---
208. ${COMPIL_DIR}/Fmake_WORK.sh ${NEW_CONF} ${TAB[*]} || exit
209
210. ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF}  ${NEMO_TDIR} || exit
211
212#- At this stage the configuration has beeen chosen
213#- We look after agrif
214grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1
215. ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit
216
217#-
218#_ END OF CONFIGURATION PHASE
219#_
220
221#-
222#- Compile ---
223
224if [ "${NBR_PRC}" -gt 0 ]; then
225   cd ${NEMO_TDIR}/${NEW_CONF} || cd -
226
227   #if AGRIF we do a first preprocessing
228   if [ ${#x_c} -eq 0 ]; then
229      [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${COMPIL_DIR}/bld.cfg
230      [ "$AGRIFUSE" == 1 ] && rm -rf  ${NEMO_TDIR}/${NEW_CONF}/BLD/*
231   fi
232   fcm build ${x_c} --ignore-lock -v 1 -j ${NBR_PRC} ${COMPIL_DIR}/bld.cfg || cd -
233   [ -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
234   [ -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
235fi
236
237#-
238#- Come back to original directory ---
239cd -
240
241#-
242#- Unset variables
243${COMPIL_DIR}/Fclean_var.sh
244
245
246exit 0;
Note: See TracBrowser for help on using the repository browser.