skeleton.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. # Function leap days calculates the number of leap days (29th of Februrary) in
  2. # a time intervall between two dates.
  3. #
  4. # Usage leap_days START_DATE END_DATE
  5. #TODO: simplify this
  6. function leap_days()
  7. {
  8. local ld=0
  9. local frstYYYY=$(date -ud "$1" +%Y)
  10. local lastYYYY=$(date -ud "$2" +%Y)
  11. set +e
  12. # Check first year for leap day between start and end date
  13. $(date -ud "${frstYYYY}-02-29" > /dev/null 2>&1) \
  14. && (( $(date -ud "$1" +%s) < $(date -ud "${frstYYYY}-03-01" +%s) )) \
  15. && (( $(date -ud "$2" +%s) > $(date -ud "${lastYYYY}-02-28" +%s) )) \
  16. && (( ld++ ))
  17. # Check intermediate years for leap day
  18. for (( y=(( ${frstYYYY}+1 )); y<=(( ${lastYYYY}-1 )); y++ ))
  19. do
  20. $(date -ud "$y-02-29" > /dev/null 2>&1) && (( ld++ ))
  21. done
  22. # Check last year (if different from first year) for leap day between start
  23. # and end date
  24. (( $lastYYYY > $frstYYYY )) \
  25. && $(date -ud "${lastYYYY}-02-29" > /dev/null 2>&1) \
  26. && (( $(date -ud "$1" +%s) < $(date -ud "${frstYYYY}-03-01" +%s) )) \
  27. && (( $(date -ud "$2" +%s) > $(date -ud "${lastYYYY}-02-28" +%s) )) \
  28. && (( ld++ ))
  29. set -e
  30. echo "$ld"
  31. }
  32. function mlpy () {
  33. if [[ `hostname` == "ozone" ]]; then
  34. module purge
  35. module load Python
  36. PYTHONPATH="/elic/home/pelletie/.local/lib/python3.6/site-packages:${PYTHONPATH}"
  37. elif [[ ${USER} == "vsc"????? ]]; then
  38. module purge
  39. module load Python
  40. PYTHONPATH="/user/leuven/327/vsc32749/.local/bin:/user/leuven/327/vsc32749/.local/lib/python3.7/site-packages:${PYTHONPATH}"
  41. else
  42. echo "Nothing detected ${USER}" > ${start_dir}/tmpout
  43. exit 0
  44. fi
  45. }
  46. [[ $@ == *verbose* ]] && set -x
  47. module purge
  48. module load ${module_list:?}
  49. export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${extralibs_list}"
  50. #
  51. # Create run directory
  52. # Copy executables
  53. # Copy XIOS XML files into run directory
  54. # Copy namelist files into run directory
  55. #
  56. if [ ! -d ${run_dir:?} ]
  57. then
  58. mkdir -p ${run_dir}
  59. if $special_restart
  60. then
  61. rsync -av --delete ${run_dir}/../${special_restart_from}/ --exclude log --exclude output --exclude restart --exclude="${special_restart_from}_*" --exclude="ocean*" --exclude="restart_*" --exclude="debug.*" --exclude="output.*" ${run_dir}
  62. cp -f ${nem_exe_file} ${run_dir}
  63. cp -f ${xio_exe_file} ${run_dir}
  64. special_year=${special_restart_date:0:4}
  65. sed -i "/$special_year/q" ${run_dir}/${info_file}
  66. . ${run_dir}/${info_file}
  67. special_restart_leg=$(printf %03d $((leg_number+1)))
  68. # PUT HERE THE INSTRUCTIONS TO COPY THE restart files
  69. cd ${run_dir}/../../archive/${special_restart_from}/restart/${special_restart_leg}
  70. for f in *.nc; do
  71. nf=${exp_name}${f:4}
  72. cp $f ${run_dir}/$nf
  73. done
  74. cd -
  75. cd ${run_dir}
  76. for f in ${exp_name}_????????_restart_???_????.nc; do
  77. nf=${f:14}
  78. ln -s $f $nf
  79. done
  80. cd -
  81. fi
  82. fi
  83. cd ${start_dir}
  84. cp -u xios_config/*xml "${run_dir}"
  85. cp -u namelists/* "${run_dir}"
  86. cd "${run_dir}"
  87. # cp -u "${nem_exe_file:?}" .
  88. # cp -u "${xio_exe_file:?}" .
  89. # Write fake file for previous fresh water budget adjustment (nn_fwb==2 in namelist)
  90. [[ ! -f EMPave_old.dat ]] && echo " 0 0.0000000000000000E+00 0.0000000000000000E+00" > EMPave_old.dat
  91. #TODO: Enquiry about this
  92. #
  93. # Link data files into run directory
  94. # Attention: no space in filenames allowed!
  95. # (No protection against word splitting by design)
  96. #
  97. for file in "${ic_files[@]}"; do
  98. [[ ! -e ${file#*> } ]] && ln -sf $(sed 's/ *=> */ /' <<< "${ini_data_dir}/${ic_subdir}/${nem_grid}/$file")
  99. done
  100. for file in "${forcing_files[@]}"; do
  101. [[ ! -e ${file#*> } || "$file" == \** ]] && ln -sf $(sed 's/ *=> */ /' <<< "${ini_data_dir}/${forcing_subdir}/${nem_forcing_set}/$file")
  102. done
  103. for file in "${shared_files[@]}"; do
  104. [[ ! -e ${file#*> } ]] && ln -sf $(sed 's/ *=> */ /' <<< "${shared_dir}/$file")
  105. done
  106. if [ "${isfcpl}" == "1" ]; then
  107. length_cut_pref=$(( ${#exp_name} + 4 ))
  108. rebuild_nemo_exe=${nemo_src_dir}/TOOLS/REBUILD_NEMO/rebuild_nemo
  109. if [ -f ${start_dir}/isfcpl.track ]; then
  110. source ${start_dir}/isfcpl.track
  111. # printf "\n" >> isfcpl.track
  112. # rm -f isfcpl.track
  113. fi
  114. cp -f ${fetish_src_dir}/* ${run_dir}
  115. iscpl_nm=.true.
  116. else
  117. iscpl_nm=.false.
  118. fi
  119. #
  120. # Normalize date formats
  121. #
  122. run_start_date=$(date -uR -d "${run_start_date}")
  123. run_end_date="${run_start_date} + ${run_duration:?}"
  124. run_end_date=$(date -uR -d "${run_end_date}")
  125. run_start_epoch=$(date -u -d"${run_start_date}" +%s)
  126. run_end_epoch=$(date -u -d"${run_end_date}" +%s)
  127. for (( ; run_num_legs>0 ; run_num_legs-- ))
  128. do
  129. #
  130. # Initialize variables (using restart file if it exists)
  131. # Variables ending in '_date' are in RFC2822
  132. # Variables ending in '_epoch' are in nb of seconds since 1970-01-01
  133. #
  134. [[ -r "${info_file:?}" ]] && source "${info_file:?}"
  135. leg_start_date=${leg_end_date:-$run_start_date}
  136. leg_number=$((${leg_number:=0}+1))
  137. leg_start_epoch=$(date -u -d "${leg_start_date}" +%s)
  138. leg_end_epoch=$(date -u -d "${leg_start_date:?} + ${rst_freq:=$run_duration}" +%s)
  139. leg_end_date=$(date -uR -d@"${leg_end_epoch}")
  140. leg_length_sec=$(( leg_end_epoch - leg_start_epoch ))
  141. leg_start_sec=$(( leg_start_epoch - run_start_epoch ))
  142. leg_end_sec=$(( leg_end_epoch - run_start_epoch ))
  143. leg_beforestart_epoch=$(( ${leg_start_epoch} - 43200 ))
  144. leg_beforestart_date=$(date -uR -d@"${leg_beforestart_epoch}")
  145. leg_almostend_epoch=$(( ${leg_end_epoch} - 43200 ))
  146. leg_almostend_date=$(date -uR -d@"${leg_almostend_epoch}")
  147. run_start_date_yyyymmdd=$(date -u -d "${run_start_date}" +%Y%m%d) # FIXME appears unused
  148. run_end_date_yyyymmdd=$(date -u -d "${run_end_date}" +%Y%m%d) # FIXME appears unused
  149. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d) # FIXME appears unused
  150. leg_almostend_date_yyyymmdd=$(date -u -d "${leg_almostend_date}" +%Y%m%d) # FIXME appears unused
  151. leg_beforestart_date_yyyymmdd=$(date -u -d "${leg_beforestart_date}" +%Y%m%d) # FIXME appears unused
  152. # run_start_date_yyyymm="${run_start_date_yyyymmdd::-2}"
  153. # run_end_date_yyyymm="${run_end_date_yyyymmdd::-2}"
  154. # leg_start_date_yyyymm="${leg_start_date_yyyymmdd::-2}"
  155. # leg_almostend_date_yyyymm="${leg_almostend_date_yyyymmdd::-2}"
  156. # leg_beforestart_date_yyyymm="${leg_beforestart_date_yyyymmdd::-2}"
  157. if [ "${isfcpl}" == "1" ]; then
  158. # Check if a monthly "icesheet" output file has indeed been asked.
  159. tmp_check=$(grep -nri "file id=\"file.*\".*name_suffix=\"_icesheet\"" ${run_dir}/file_def.xml | wc -l)
  160. if (( tmp_check == 0 )); then
  161. echo "file_def.xml does not look like you have asked for an icesheet output file! Exiting."
  162. exit 2
  163. elif (( tmp_check > 1 )); then
  164. echo "file_def.xml contains at least 2 icesheet output files! This is ambiguous. Exiting."
  165. exit 2
  166. fi
  167. if (( leg_number == 1 )); then
  168. mkdir -p ${archive_dir}/isfcpl
  169. rm -f ${start_dir}/isfcpl.track
  170. # Counter for the number of restart since last file exchange with fETISh.
  171. cnt_res_isfcpl=0
  172. isfcpl_window_days=$(echo "(${n_res_perisfcpl} * ${leg_length_sec}) / 86400" | bc)
  173. if (( isfcpl_window_days >= 28 && isfcpl_window_days <= 31 )); then
  174. n_month_isfcpl=1
  175. elif (( isfcpl_window_days >= 336 && isfcpl_window_days <= 372 )); then
  176. n_month_isfcpl=12
  177. else
  178. echo "Can't figure out how many month long is the coupling window."
  179. exit 2
  180. fi
  181. n_month_full_run=$(( $(( 12 * $(( ${run_end_date_yyyymmdd::4} - ${run_start_date_yyyymmdd::4} )) )) + $(( ${run_end_date_yyyymmdd:4:2} - ${run_start_date_yyyymmdd:4:2} )) ))
  182. if (( $(( ${n_month_full_run} % ${n_month_isfcpl} )) != 0 )); then
  183. echo "n_month_full_run=${n_month_full_run} is not a multiple of n_month_isfcpl=${n_month_isfcpl}."
  184. exit 2
  185. else
  186. n_isfcpl_window=$(echo "${n_month_full_run} / ${n_month_isfcpl}" | bc)
  187. fi
  188. tmp=`readlink -f isf_draft_meter.nc`
  189. tmp2=`readlink -f bathy_meter.nc`
  190. if [ "${tmp}" != "${tmp2}" ]; then
  191. echo "Error. At initialization, isf_draft_meter.nc and bathy_meter.nc do not point to the same file."
  192. exit 1
  193. fi
  194. init_bathy_file=`basename ${tmp}`
  195. cp -f ${tmp} ${archive_dir}/isfcpl
  196. cp -f ${tmp} ${run_dir}/init_NEMO_bathy.nc
  197. printf "# Information for the ice sheet model\n" > ${start_dir}/isfcpl.track
  198. printf "run_name=${exp_name}\n" >> ${start_dir}/isfcpl.track
  199. printf "initial_date=${run_start_date_yyyymmdd}\n" >> ${start_dir}/isfcpl.track
  200. printf "n_month_isfcpl=${n_month_isfcpl}\n" >> ${start_dir}/isfcpl.track
  201. printf "n_isfcpl_window=${n_isfcpl_window}\n" >> ${start_dir}/isfcpl.track
  202. printf "date_beg_isfcpl=YYYYMMDD\n" >> ${start_dir}/isfcpl.track
  203. printf "date_end_isfcpl=YYYYMMDD\n\n" >> ${start_dir}/isfcpl.track
  204. printf "# Information for NEMO to keep up\n" >> ${start_dir}/isfcpl.track
  205. printf "cnt_res_isfcpl=0\n" >> ${start_dir}/isfcpl.track
  206. printf "init_geom=1\n" >> ${start_dir}/isfcpl.track
  207. printf "init_bathy=1\n" >> ${start_dir}/isfcpl.track
  208. printf "curr_bathy_file=${init_bathy_file}\n" >> ${start_dir}/isfcpl.track
  209. init_geom=1
  210. init_bathy=1
  211. curr_bathy_file=${init_bathy_file}
  212. ln -sf ${run_dir}/fETISh_8km_geometry_init.nc ${run_dir}/fETISh_8km_geometry_curr.nc
  213. fi
  214. ln -sf ${curr_bathy_file} ${run_dir}/bathy_meter.nc
  215. ln -sf ${curr_bathy_file} ${run_dir}/isf_draft_meter.nc
  216. if (( $(( ${leg_number} - 1 )) % ${n_res_perisfcpl} == 0 )); then
  217. date_beg_isfcpl=${leg_start_date_yyyymmdd}
  218. sed -i "s/.*date_beg_isfcpl=.*/date_beg_isfcpl=${date_beg_isfcpl}/" ${start_dir}/isfcpl.track
  219. if (( leg_number > 1 )); then
  220. # leg number at which NEMO is supposed to receive updated geometry from fETISh.
  221. # We need to pre-treat fETISh outputs in order to make them readable by NEMO.
  222. # new fETISh output should be ${run_dir}/fETISh_8km_geometry_curr.nc
  223. module purge
  224. mlpy
  225. module load CDO
  226. ${pp_fetish_call}
  227. # Copy (for initial) or move (non initial) previous bathymetry file to archive and link new one to what NEMO will read.
  228. new_bathy_file="fETISh_eORCA025-SO_bathymetry_${leg_beforestart_date_yyyymmdd}.nc"
  229. mv -f fETISh_new_8km_eORCA025-bathymetry_curr.nc ${new_bathy_file}
  230. old_bathy=`readlink -f ${run_dir}/bathy_meter.nc`
  231. if [ "${init_bathy}" == 0 ]; then
  232. mv -f ${old_bathy} ${archive_dir}/isfcpl
  233. else
  234. init_bathy=0
  235. sed -i "s/^init_bathy=.*$/init_bathy=0/g" ${start_dir}/isfcpl.track
  236. cp -f ${old_bathy} ${archive_dir}/isfcpl
  237. fi
  238. curr_bathy_file=${new_bathy_file}
  239. sed -i "s/.*curr_bathy_file=.*/curr_bathy_file=${curr_bathy_file}/" ${start_dir}/isfcpl.track
  240. ln -sf ${new_bathy_file} ${run_dir}/bathy_meter.nc
  241. ln -sf ${new_bathy_file} ${run_dir}/isf_draft_meter.nc
  242. module purge
  243. module load ${module_list:?}
  244. export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${extralibs_list}"
  245. fi
  246. fi
  247. fi
  248. # Correct for leap days because NEMO standalone uses no-leap calendar
  249. if (( leap_years == 0 )); then
  250. leg_length_sec=$(( leg_length_sec - $(leap_days "${leg_start_date}" "${leg_end_date}")*24*3600 ))
  251. leg_start_sec=$(( leg_start_sec - $(leap_days "${run_start_date}" "${leg_start_date}")*24*3600 ))
  252. leg_end_sec=$(( leg_end_sec - $(leap_days "${run_start_date}" "${leg_end_date}")*24*3600 ))
  253. fi
  254. (( leg_number > 1 )) && leg_is_restart=true || leg_is_restart=false
  255. #
  256. # Compute leg end-date and trim if necessary
  257. #
  258. (( leg_end_epoch > run_end_epoch )) && leg_end_date=${run_end_epoch}
  259. #
  260. # Check whether there is some work left to do
  261. #
  262. if (( leg_start_epoch >= run_end_epoch ))
  263. then
  264. echo "Leg start date equal to or after end of simulation."
  265. echo "Nothing left to do. Cleaning and exiting."
  266. for (( n=0 ; n<nem_numproc ; n++ ))
  267. do
  268. np=$(printf %04d ${n})
  269. rm -f "${run_dir}/restart_oce_${np}.nc"
  270. rm -f "${run_dir}/restart_ice_${np}.nc"
  271. done
  272. exit 0
  273. fi
  274. #
  275. # Update namelist
  276. #
  277. source build_namelist_cfg.sh > namelist_cfg
  278. # Link the restart files
  279. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  280. if ((leg_start_sec > 0 )); then
  281. for (( n=0 ; n<nem_numproc ; n++ ))
  282. do
  283. np=$(printf %04d ${n})
  284. [[ -f "${exp_name:?}_${ns}_restart_oce_${np}.nc" ]] || { echo "Error: restart file not found." ; exit 2 ; }
  285. ln -fs "${exp_name:?}_${ns}_restart_oce_${np}.nc" "restart_oce_${np}.nc"
  286. [[ -f "${exp_name:?}_${ns}_restart_ice_${np}.nc" ]] || { echo "Error: restart file not found." ; exit 2 ; }
  287. ln -fs "${exp_name:?}_${ns}_restart_ice_${np}.nc" "restart_ice_${np}.nc"
  288. done
  289. fi
  290. # Stop here is preponly was specified
  291. [[ $@ == *preponly* ]] && exit 0
  292. #
  293. # Run nemo
  294. #
  295. if [[ "$@" == *"dbg"* ]]; then
  296. echo $HOSTNAME
  297. sleep 10000000000000
  298. fi
  299. time_begin=$(date +%s)
  300. mpirun -np "${xio_numproc:?}" "${xio_exe_file:?}" : -np "${nem_numproc:?}" "${nem_exe_file:?}"
  301. time_end=$(date +%s)
  302. if (( isfcpl == 1 )); then
  303. module purge
  304. module load CDO
  305. fmt_res_isfcpl=$(printf "%02d" ${cnt_res_isfcpl})
  306. in_stencil="${exp_name}_1m_${leg_start_date_yyyymmdd}_${leg_almostend_date_yyyymmdd}_icesheet"
  307. out_stencil="${exp_name}_icesheet_res${fmt_res_isfcpl}"
  308. # Renaming.
  309. for((prc=0;prc<xio_numproc;prc++)); do
  310. fmt_xio=$(printf "%04d" ${prc})
  311. infile="${in_stencil}_${fmt_xio}.nc"
  312. # echo "mv -f ${infile} ./${out_stencil}_${fmt_xio}.nc"
  313. mv -f ${infile} ${out_stencil}_${fmt_xio}.nc
  314. done
  315. # Rebuilding it.
  316. module purge
  317. module load ${module_list:?}
  318. export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${extralibs_list}"
  319. ${rebuild_nemo_exe} ${out_stencil} ${xio_numproc}
  320. rm -f ${out_stencil}_????.nc
  321. # Counter increase (NEMO restart index within ice sheet / ocean coupling window).
  322. cnt_res_isfcpl=$(( ${cnt_res_isfcpl} + 1 ))
  323. sed -i "s/.*cnt_res_isfcpl=.*/cnt_res_isfcpl=${cnt_res_isfcpl}/" ${start_dir}/isfcpl.track
  324. if (( ${leg_number} % ${n_res_perisfcpl} == 0 )); then
  325. # We have just ended one NEMO leg which closes an ice sheet / ocean coupling window.
  326. date_end_isfcpl=${leg_almostend_date_yyyymmdd}
  327. sed -i "s/.*date_end_isfcpl=.*/date_end_isfcpl=${date_end_isfcpl}/" ${start_dir}/isfcpl.track
  328. cp -f ${start_dir}/isfcpl.track ${start_dir}/tmp/isfcpl.old
  329. ${rebuild_nemo_exe} mesh_mask ${nem_numproc}
  330. module purge; module load CDO
  331. # Concatenate all icesheet files from all legs contained within this coupling window
  332. tmpfile_eos80="curr_ocean2ice_EOS80.nc"
  333. tmpfile_teos10="curr_ocean2ice_TEOS10.nc"
  334. outfile="${exp_name}_ocean2ice_${date_beg_isfcpl}-${date_end_isfcpl}.nc"
  335. cdo -O copy "${out_stencil::-2}??.nc" ${tmpfile_teos10}
  336. module purge
  337. mlpy
  338. ${pp_nemo_to_fetish_call}
  339. mv -f ${tmpfile_eos80} ${outfile}
  340. mv -f mesh_mask.nc ${archive_dir}/isfcpl/mesh_mask_${date_beg_isfcpl}-${date_end_isfcpl}.nc
  341. # CALL FETISH
  342. module purge
  343. cp -f ${start_dir}/isfcpl.track ${run_dir}
  344. module load ${fetish_modules}
  345. ${fetish_call}
  346. mv -f ${exp_name}_fETISh*.mat ${archive_dir}/isfcpl
  347. ln -sf ${archive_dir}/isfcpl/*.mat ./
  348. module purge
  349. # mv ocean2ice file to arch dir
  350. mv -f ${outfile} ${archive_dir}/isfcpl
  351. new_geom_file="${exp_name}_ice2ocean_${date_end_isfcpl}.nc"
  352. # module load NCO
  353. # ncks -C -v B ${init_fetish_file} -A ${new_geom_file}
  354. # module purge
  355. old_geom=`readlink -f fETISh_8km_geometry_curr.nc`
  356. if [ "${init_geom}" == 0 ]; then
  357. mv -f ${old_geom} ${archive_dir}/isfcpl
  358. else
  359. init_geom=0
  360. sed -i "s/.*init_geom=.*/init_geom=0/" ${start_dir}/isfcpl.track
  361. cp -f ${old_geom} ${archive_dir}/isfcpl
  362. fi
  363. ln -sf ${new_geom_file} fETISh_8km_geometry_curr.nc
  364. cnt_res_isfcpl=0
  365. printf "# Information for the ice sheet model\n" > ${start_dir}/isfcpl.track
  366. printf "run_name=${exp_name}\n" >> ${start_dir}/isfcpl.track
  367. printf "initial_date=${run_start_date_yyyymmdd}\n" >> ${start_dir}/isfcpl.track
  368. printf "n_month_isfcpl=${n_month_isfcpl}\n" >> ${start_dir}/isfcpl.track
  369. printf "n_isfcpl_window=${n_isfcpl_window}\n" >> ${start_dir}/isfcpl.track
  370. printf "date_beg_isfcpl=YYYYMMDD\n" >> ${start_dir}/isfcpl.track
  371. printf "date_end_isfcpl=YYYYMMDD\n\n" >> ${start_dir}/isfcpl.track
  372. printf "# Information for NEMO to keep up\n" >> ${start_dir}/isfcpl.track
  373. printf "cnt_res_isfcpl=0\n" >> ${start_dir}/isfcpl.track
  374. printf "init_geom=${init_geom}\n" >> ${start_dir}/isfcpl.track
  375. printf "init_bathy=${init_bathy}\n" >> ${start_dir}/isfcpl.track
  376. printf "curr_bathy_file=${curr_bathy_file}\n" >> ${start_dir}/isfcpl.track
  377. module purge
  378. module load ${module_list:?}
  379. export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${extralibs_list}"
  380. fi
  381. fi
  382. #############################
  383. formatted_leg_number=$(printf %03d $((leg_number)))
  384. #
  385. # Move NEMO output files to archive directory
  386. #
  387. outdir="${archive_dir:?}/output/${formatted_leg_number}"
  388. mkdir -p "${outdir}"
  389. shopt -s nullglob
  390. for v in grid_U grid_V grid_W grid_T icemod icemoa SBC SBC_scalar scalar fwfisf
  391. do
  392. for f in ${exp_name}_??_????????_????????_${v}_????.nc
  393. do
  394. mv "$f" "$outdir/"
  395. done
  396. for f in ${exp_name}_??_????????_????????_${v}.nc
  397. do
  398. mv "$f" "$outdir/"
  399. done
  400. for f in ${exp_name}_??_${v}.nc
  401. do
  402. mv "$f" "$outdir/"
  403. done
  404. done
  405. #
  406. # Move NEMO restart files from previous run to archive directory
  407. #
  408. outdir="$archive_dir/restart/${formatted_leg_number}"
  409. mkdir -p "${outdir}"
  410. for f in ${exp_name}_${ns}_restart_???_????.nc
  411. do
  412. [ -f "$f" ] && mv "$f" "${outdir}"
  413. done
  414. #
  415. # Move log files to archive directory
  416. #
  417. outdir="$archive_dir/log/${formatted_leg_number}"
  418. mkdir -p "${outdir}"
  419. for f in ocean.output time.step solver.stat ; do mv "${f}" "${outdir}"; done
  420. shopt -u nullglob
  421. #
  422. # Write checkpoint control file
  423. # TODO: enquiry why 0 -1 +2 rather than 2- 1
  424. #
  425. tr=$(date -d "0 -$time_begin sec + $time_end sec" +%T)
  426. current_date=$(date +'%F %T')
  427. {
  428. echo "#"
  429. echo "# Finished leg at ${current_date} after ${tr} (hh:mm:ss)"
  430. echo "leg_number=${leg_number}"
  431. echo "leg_start_date=\"${leg_start_date}\""
  432. echo "leg_end_date=\"${leg_end_date}\""
  433. } | tee -a "${info_file}"
  434. special_restart=false
  435. done
  436. #
  437. # Move back to submission directory
  438. #
  439. cd - >/dev/null
  440. #
  441. # Check whether there is some work left to do in a further job
  442. #
  443. [[ $@ == *noresubmit* ]] && exit 0
  444. if (( leg_end_epoch < run_end_epoch )) ; then
  445. echo "Leg end earlier than end of simulation."
  446. echo "Submitting another job."
  447. #[[ $@ == *local* ]] && exec $0 $@ || scontrol requeue $SLURM_JOB_ID #TODO: factorize this
  448. if [[ "$@" == *"local"* ]] ; then
  449. cd ${start_dir}
  450. sleep 2
  451. ./run.sh local && exit 0
  452. #exec "$0" "$@"
  453. elif [ "${submit_command}" == *sbatch* ] ; then
  454. sbatch $0 $@ | awk '{print $4}' >> ${run_dir}/.coral_jobs
  455. elif [[ $USER == "vsc"* ]]; then
  456. if [ -f ${PBS_O_WORKDIR-$PWD}/tmp/credits_file ]; then
  457. credits=`cat ${PBS_O_WORKDIR-$PWD}/tmp/credits_file`
  458. else
  459. #logfiletmp=`echo ${PBS_O_WORKDIR-$PWD} | rev | cut -d'/' -f1 | rev`
  460. #logfiletmp2=`echo $logfiletmp | cut -d'_' -f1`
  461. #logfile=`ls ${PBS_O_WORKDIR-$PWD}"/"$logfiletmp2*.o*`
  462. #credits=`grep "account string:" $logfile | sed 's/^.*: //'`
  463. credits_tmp=`grep "account string:" ${PBS_O_WORKDIR-$PWD}/*.o* -R | sed 's/^.*: //'`
  464. credits=`echo $credits_tmp | awk '{ print $1 }'`
  465. mkdir -p tmp
  466. echo ${credits} > tmp/credits_file
  467. fi
  468. script_name=`cat ${PBS_O_WORKDIR-$PWD}/tmp/script_name`
  469. run_path=`cat ${PBS_O_WORKDIR-$PWD}/tmp/address`
  470. ssh login2 "cd $run_path; qsub -A $credits $script_name | tee -a coral_jobs"
  471. sleep 2
  472. jobid=`cat coral_jobs`
  473. rm -f coral_jobs
  474. jobid=${jobid%%.*}
  475. echo "${jobid}" >> "${run_dir}"/.coral_jobs ;
  476. else
  477. "qsub" -v PBS_OPTIONS="$@" "$0" | tee -a coral_jobs
  478. sleep 2
  479. jobid=`cat coral_jobs`
  480. rm -f coral_jobs
  481. jobid=${jobid%.*}
  482. echo "${jobid}" >> "${run_dir}"/.coral_jobs
  483. fi
  484. else
  485. if [[ $USER == "vsc"* ]]; then
  486. run_path=`cat ${PBS_O_WORKDIR-$PWD}/tmp/address`
  487. rm -rf $run_path/tmp
  488. fi
  489. echo "Nothing left to do. Cleaning and exiting." # FIXME Factorize this (we have two exit points)
  490. for (( n=0 ; n<nem_numproc ; n++ ))
  491. do
  492. np=$(printf %04d ${n})
  493. rm -f "restart_oce_${np}.nc"
  494. rm -f "restart_ice_${np}.nc"
  495. done
  496. fi
  497. exit 0