ece-ifs+nemo.sh.tmpl 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. #!/usr/bin/env bash
  2. #PBS -q large
  3. #PBS -r y
  4. #PBS -W group_list=ecearth
  5. #PBS -l walltime=23:50:00
  6. #PBS -l select=16:ncpus=24:mem=63000mb:mpiprocs=24:ompthreads=1
  7. #PBS -M pierre-yves.barriat@uclouvain.be
  8. #PBS -m abe
  9. exec > ${PBS_O_WORKDIR-$PWD}/${PBS_JOBNAME-"local"}_${PBS_JOBID-"id"}.log
  10. echo "------------------ Job Info --------------------"
  11. echo "jobid : $PBS_JOBID"
  12. echo "jobname : $PBS_JOBNAME"
  13. echo "job type : $PBS_ENVIRONMENT"
  14. echo "submit dir : $PBS_O_WORKDIR"
  15. echo "queue : $PBS_O_QUEUE"
  16. echo "user : $PBS_O_LOGNAME"
  17. echo "threads : $OMP_NUM_THREADS"
  18. set -ue
  19. # Directories
  20. start_dir=${PBS_O_WORKDIR-$PWD}
  21. # librunscript defines some helper functions
  22. . ${start_dir}/librunscript.sh
  23. # =============================================================================
  24. # *** BEGIN User configuration
  25. # =============================================================================
  26. # -----------------------------------------------------------------------------
  27. # *** General configuration
  28. # -----------------------------------------------------------------------------
  29. # Component configuration
  30. # (for syntax of the $config variable, see librunscript.sh)
  31. config="ifs nemo:elpin lim3 rnfmapper xios:detached oasis"
  32. # Experiment name (exactly 4 letters!)
  33. exp_name=[[[MOD:GENERAL:EXP_NAME]]]
  34. # Simulation start and end date. Use any (reasonable) syntax you want.
  35. run_start_date="[[[MOD:GENERAL:RUN_START_DATE]]]"
  36. run_end_date="[[[MOD:GENERAL:RUN_END_DATE]]]"
  37. # Set $force_run_from_scratch to 'true' if you want to force this run to start
  38. # from scratch, possibly ignoring any restart files present in the run
  39. # directory. Leave set to 'false' otherwise.
  40. # NOTE: If set to 'true' the run directory $run_dir is cleaned!
  41. force_run_from_scratch=[[[MOD:GENERAL:FORCE_RUN_FROM_SCRATCH]]]
  42. special_restart=false
  43. special_restart_from=ECE3
  44. special_restart_date="1995-01-01"
  45. # Resolution
  46. ifs_grid=[[[MOD:IFS:GRID]]]
  47. nem_grid=[[[MOD:NEM:GRID]]]
  48. # Restart frequency. Use any (reasonable) number and time unit you want.
  49. # For runs without restart, leave this variable empty
  50. rst_freq="[[[MOD:GENERAL:RST_FREQ]]]"
  51. # Number of restart legs to be run in one go
  52. run_num_legs=[[[MOD:GENERAL:RUN_NUM_LEGS]]]
  53. # Coupling frequency between atmosphere and ocean (in seconds)
  54. cpl_freq_atm_oce_sec=[[[MOD:OASIS:CPL_FREQ_ATM_OCE_SEC]]]
  55. # Directories
  56. #start_dir=${PWD}
  57. ctrl_file_dir=${start_dir}/ctrl
  58. # Architecture
  59. build_arch=[[[PLT:ACTIVE:BUILD_ARCH]]]
  60. # This file is used to store information about restarts
  61. ece_info_file="ece.info"
  62. # -----------------------------------------------------------------------------
  63. # *** Read platform dependent configuration
  64. # -----------------------------------------------------------------------------
  65. . ${start_dir}/ecconf.cfg
  66. configure
  67. # -----------------------------------------------------------------------------
  68. # *** IFS configuration
  69. # -----------------------------------------------------------------------------
  70. ifs_version=36r4
  71. ifs_time_step_sec=[[[MOD:IFS:TIME_STEP_SEC]]]
  72. # list of desired IFS output frequencies in hours (e.g. "6 3")
  73. # make sure that the list is in DESCENDING order and that the values are multiples
  74. # of the IFS timestep
  75. ifs_output_freq_h="6 3"
  76. for hfreq in $ifs_output_freq_h
  77. do
  78. sfreq=$(( hfreq * 3600 ))
  79. if (( $(( sfreq % ifs_time_step_sec )) ))
  80. then
  81. error "Output frequency $hfreq [hrs] is not a multiple of IFS timestep $ifs_time_step_sec [s]"
  82. fi
  83. done
  84. ifs_output_freq=$(( ${ifs_output_freq_h##* } * 3600 / ifs_time_step_sec ))
  85. ifs_di_freq=$(( 24 * 3600 / ifs_time_step_sec ))
  86. ifs_ddh_freq=$(( 120 * 3600 / ifs_time_step_sec ))
  87. ifs_res_hor=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\1:')
  88. ifs_res_ver=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\2:')
  89. ifs_numproc=[[[MOD:IFS:NUMPROC]]]
  90. ifs_exe_file=${ecearth_src_dir}/ifs-${ifs_version}/bin/ifsmaster-${build_arch}
  91. ifs_lastout=false
  92. ifs_cmip5=[[[MOD:IFS:CMIP5]]]
  93. ifs_cmip5_rcp=[[[MOD:IFS:CMIP5_RCP]]]
  94. ifs_cmip_fixyear=[[[MOD:IFS:CMIP_FIXYEAR]]]
  95. ifs_mac2sp=[[[MOD:IFS:MAC2SP]]]
  96. ifs_cmip6piaer=[[[MOD:IFS:CMIP6PIAER]]]
  97. ifs_cmip6=[[[MOD:IFS:CMIP6]]]
  98. lcmip6_strat_simp=[[[MOD:IFS:CMIP6]]]
  99. ifs_A4xCO2=[[[MOD:IFS:CMIP6_A4xCO2]]]
  100. ifs_1PCTCO2=[[[MOD:IFS:CMIP6_1PCTCO2]]]
  101. # Time-varying orbital forcing (Qiong Zhang, SU-2013-09)
  102. # https://dev.ec-earth.org/projects/ecearth3/wiki/Orbital_forcing_in_EC-Earth_3
  103. #
  104. # ifs_orb_switch=FALSE, no orbital calculations applied
  105. # ifs_orb_switch=TRUE, use orbital calculations according to ifs_orb_mode
  106. # ifs_orb_mode="fixed_year", or "variable_year", or "fixed_parameters"
  107. # fixed_year: calculate the orbital parameters at ifs_orb_iyear, e.g.,1850
  108. # variable_year: calculate orbital parameters annually start from ifs_orb_iyear
  109. # fixed_parameters: prescribe orbital parameters for given year
  110. ifs_orb_switch=FALSE
  111. ifs_orb_mode="variable_year"
  112. ifs_orb_iyear=$(date -u -d "${run_start_date}" +%Y)
  113. # -----------------------------------------------------------------------------
  114. # *** IFS tuning (the commented values are EC-Earth 3.2beta and IFS cy36r4)
  115. # -----------------------------------------------------------------------------
  116. # ECE32b IFS cy36r4
  117. RPRCON=1.41E-3 # 1.2E-3 1.4E-3
  118. RVICE=0.125 # 0.13 0.15
  119. RLCRITSNOW=3.9E-5 # 3.0E-5 5.0E-5
  120. RSNOWLIN2=0.035 # 0.035 0.025
  121. ENTRORG=1.49E-4 # 1.5E-4 1.8E-4
  122. DETRPEN=0.7E-4 # 0.75E-4 0.75E-4
  123. ENTRDD=3.6E-4 # 3.0E-4 2.0E-4
  124. RMFDEPS=0.3 # 0.3 0.35
  125. RCLDIFF=3.E-6 # 3.E-6
  126. RCLDIFFC=5.0 # 5.0
  127. # -----------------------------------------------------------------------------
  128. # *** NEMO/LIM configuration
  129. # -----------------------------------------------------------------------------
  130. nem_time_step_sec=[[[MOD:NEM:NEM_TIME_STEP_SEC]]]
  131. lim_time_step_sec=[[[MOD:NEM:LIM_TIME_STEP_SEC]]]
  132. # This is only needed if the experiment is started from an existing set of NEMO
  133. # restart files
  134. nem_restart_file_path=${start_dir}/nemo-rst
  135. nem_restart_offset=0
  136. nem_res_hor=$(echo ${nem_grid} | sed 's:ORCA\([0-9]\+\)L[0-9]\+:\1:')
  137. nem_exe_file=${ecearth_src_dir}/nemo-3.6/CONFIG/${nem_grid}_LIM3/BLD/bin/nemo.exe
  138. nem_numproc=[[[MOD:NEM:NUMPROC]]]
  139. # Remove land grid-points
  140. if $(has_config nemo:elpin)
  141. then
  142. jpns=($(${ecearth_src_dir}/util/ELPiN/Launcher -e ORCA${nem_res_hor} ${nem_numproc}))
  143. info "nemo domain decompostion from ELpIN: ${jpns[@]}"
  144. nem_numproc=${jpns[0]}
  145. nem_jpni=${jpns[1]}
  146. nem_jpnj=${jpns[2]}
  147. else
  148. info "nemo original domain decomposition (not using ELPiN)"
  149. fi
  150. # -----------------------------------------------------------------------------
  151. # *** Runoff mapper configuration
  152. # -----------------------------------------------------------------------------
  153. rnf_exe_file=${ecearth_src_dir}/runoff-mapper/bin/runoff-mapper.exe
  154. rnf_numproc=1
  155. # -----------------------------------------------------------------------------
  156. # *** OASIS configuration
  157. # -----------------------------------------------------------------------------
  158. # Restart files for the coupling fields (note 8 character limit in OASIS)
  159. # rstas.nc : atmoshpere single-category fields
  160. # rstam.nc : atmoshpere multi-category fields
  161. # rstos.nc : ocean single-category fields
  162. # rstom.nc : ocean multi-category fields
  163. oas_rst_files="rstas.nc rstos.nc"
  164. # Decide whether the OASIS weight files for interpolation should be linked from
  165. # the setup directory (true) or not (false). In the latter case, the weights
  166. # are re-computed at the start of the run.
  167. oas_link_weights=true
  168. # Flux correction for runoff (not calving) sent from Oasis to ocean.
  169. # 1.07945 is computed to compensate for a P-E=-0.016 mm/day
  170. oas_mb_fluxcorr=1.07945
  171. # -----------------------------------------------------------------------------
  172. # *** XIOS configuration
  173. # -----------------------------------------------------------------------------
  174. xio_exe_file=${ecearth_src_dir}/xios-2/bin/xios_server.exe
  175. xio_numproc=[[[MOD:XIO:NUMPROC]]]
  176. # =============================================================================
  177. # *** END of User configuration
  178. # =============================================================================
  179. # =============================================================================
  180. # *** This is where the code begins ...
  181. # =============================================================================
  182. # -----------------------------------------------------------------------------
  183. # *** Create the run dir if necessary and go there
  184. # Everything is done from here.
  185. # -----------------------------------------------------------------------------
  186. if [ ! -d ${run_dir} ]
  187. then
  188. mkdir -p ${run_dir}
  189. if $special_restart
  190. then
  191. force_run_from_scratch=false
  192. rsync -av --delete ${run_dir}/../${special_restart_from}/ --exclude log --exclude output --exclude restart --exclude="${special_restart_from}_*" --exclude="srf*" --exclude="restart_*" --exclude="debug.*" --exclude="output.*" ${run_dir}
  193. cp -f ${nem_exe_file} ${run_dir}
  194. cp -f ${ifs_exe_file} ${run_dir}
  195. cp -f ${rnf_exe_file} ${run_dir}
  196. cp -f ${xio_exe_file} ${run_dir}
  197. special_year=${special_restart_date:0:4}
  198. sed -i "/$special_year/q" ${run_dir}/ece.info
  199. . ${run_dir}/ece.info
  200. special_restart_leg=$(printf %03d $((leg_number+1)))
  201. # PUT HERE THE INSTRUCTIONS TO COPY THE restart files
  202. rsync -av ${run_dir}/../${special_restart_from}/restart/ifs/${special_restart_leg}/ ${run_dir}
  203. rsync -av ${run_dir}/../${special_restart_from}/restart/oasis/${special_restart_leg}/ ${run_dir}
  204. cd ${run_dir}/../${special_restart_from}/restart/nemo/${special_restart_leg}
  205. for f in *.nc; do
  206. nf=${exp_name}${f:4}
  207. cp $f ${run_dir}/$nf
  208. done
  209. cd -
  210. cd ${run_dir}
  211. for f in ${exp_name}_????????_restart_???_????.nc; do
  212. nf=${f:14}
  213. ln -s $f $nf
  214. done
  215. cd -
  216. rm -f ${run_dir}/ICMCL${special_restart_from}INIT
  217. mv ${run_dir}/ICMGG${special_restart_from}INIUA ${run_dir}/ICMGG${exp_name}INIUA
  218. mv ${run_dir}/ICMGG${special_restart_from}INIT ${run_dir}/ICMGG${exp_name}INIT
  219. mv ${run_dir}/ICMSH${special_restart_from}INIT ${run_dir}/ICMSH${exp_name}INIT
  220. fi
  221. else
  222. force_run_from_scratch=false
  223. special_restart=false
  224. fi
  225. cd ${run_dir}
  226. # -----------------------------------------------------------------------------
  227. # *** Determine the time span of this run and whether it's a restart leg
  228. # -----------------------------------------------------------------------------
  229. # Regularise the format of the start and end date of the simulation
  230. run_start_date=$(date -uR -d "${run_start_date}")
  231. run_end_date=$(date -uR -d "${run_end_date}")
  232. # Loop over the number of legs
  233. for (( ; run_num_legs>0 ; run_num_legs-- ))
  234. do
  235. # Check for restart information file and set the current leg start date
  236. # Ignore restart information file if force_run_from_scratch is true
  237. if ${force_run_from_scratch} || ! [ -r ${ece_info_file} ]
  238. then
  239. leg_is_restart=false
  240. leg_start_date=${run_start_date}
  241. leg_number=1
  242. else
  243. leg_is_restart=true
  244. . ./${ece_info_file}
  245. leg_start_date=${leg_end_date}
  246. leg_number=$((leg_number+1))
  247. fi
  248. # Compute the end date of the current leg
  249. if [ -n "${rst_freq}" ]
  250. then
  251. leg_end_date=$(date -uR -d "${leg_start_date} + ${rst_freq}")
  252. else
  253. leg_end_date=${run_end_date}
  254. fi
  255. if [ $(date -d "${leg_end_date}" +%s) -gt $(date -d "${run_end_date}" +%s) ]
  256. then
  257. leg_end_date=${run_end_date}
  258. fi
  259. # Some time variables needed later
  260. leg_length_sec=$(( $(date -d "${leg_end_date}" +%s) - $(date -d "${leg_start_date}" +%s) ))
  261. leg_start_sec=$(( $(date -d "${leg_start_date}" +%s) - $(date -d "${run_start_date}" +%s) ))
  262. leg_end_sec=$(( $(date -d "${leg_end_date}" +%s) - $(date -d "${run_start_date}" +%s) ))
  263. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d)
  264. leg_start_date_yyyy=$(date -u -d "${leg_start_date}" +%Y)
  265. leg_end_date_yyyy=$(date -u -d "${leg_end_date}" +%Y)
  266. # Check whether there's actually time left to simulate - exit otherwise
  267. if [ ${leg_length_sec} -le 0 ]
  268. then
  269. info "Leg start date equal to or after end of simulation."
  270. info "Nothing left to do. Exiting."
  271. exit 0
  272. fi
  273. # -------------------------------------------------------------------------
  274. # *** Prepare the run directory for a run from scratch
  275. # -------------------------------------------------------------------------
  276. if ! $leg_is_restart
  277. then
  278. # ---------------------------------------------------------------------
  279. # *** Check if run dir is empty. If not, and if we are allowed to do so
  280. # by ${force_run_from_scratch}, remove everything
  281. # ---------------------------------------------------------------------
  282. if $(ls * >& /dev/null)
  283. then
  284. if ${force_run_from_scratch}
  285. then
  286. rm -fr ${run_dir}/*
  287. else
  288. error "Run directory not empty and \$force_run_from_scratch not set."
  289. fi
  290. fi
  291. # ---------------------------------------------------------------------
  292. # *** Copy executables of model components
  293. # *** Additionally, create symlinks to the original place for reference
  294. # ---------------------------------------------------------------------
  295. cp ${ifs_exe_file} .
  296. ln -s ${ifs_exe_file} $(basename ${ifs_exe_file}).lnk
  297. cp ${nem_exe_file} .
  298. ln -s ${nem_exe_file} $(basename ${nem_exe_file}).lnk
  299. cp ${rnf_exe_file} .
  300. ln -s ${rnf_exe_file} $(basename ${rnf_exe_file}).lnk
  301. cp ${xio_exe_file} .
  302. ln -s ${xio_exe_file} $(basename ${xio_exe_file}).lnk
  303. # ---------------------------------------------------------------------
  304. # *** Files needed for IFS (linked)
  305. # ---------------------------------------------------------------------
  306. # Initial data
  307. ln -s \
  308. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIUA \
  309. ICMGG${exp_name}INIUA
  310. ln -s \
  311. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIT \
  312. ICMGG${exp_name}INIT
  313. ln -s \
  314. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMSHECE3INIT \
  315. ICMSH${exp_name}INIT
  316. # Other stuff
  317. ln -s ${ini_data_dir}/ifs/rtables/* .
  318. # Output control (ppt files)
  319. mkdir postins
  320. rm -f postins/*
  321. cp ${ctrl_file_dir}/ppt0000000000 postins/
  322. # create ppt files/links for each ifs_output_freq_h
  323. for freq in $ifs_output_freq_h ; do
  324. hhmm_freq=$(printf %02d00 $freq)
  325. if [ ! -f ${ctrl_file_dir}/pptdddddd${hhmm_freq} ] ; then
  326. echo "warning: output requested at $freq h. but ppt file postins/pptdddddd${hhmm_freq} does not exist."
  327. continue
  328. else
  329. cp ${ctrl_file_dir}/pptdddddd${hhmm_freq} postins/
  330. fi
  331. for t in `seq 0 $freq 23`
  332. do
  333. hhmm_t=$(printf %02d00 $t)
  334. if [ ! -f postins/pptdddddd${hhmm_t} ]
  335. then
  336. ln -s pptdddddd${hhmm_freq} postins/pptdddddd${hhmm_t}
  337. fi
  338. done
  339. done
  340. # create dirlist
  341. /bin/ls -1 postins/* > dirlist
  342. # ---------------------------------------------------------------------
  343. # *** Files needed for NEMO (linked)
  344. # ---------------------------------------------------------------------
  345. # Link initialisation files for matching ORCA grid
  346. # It would be simpler to link all files in ${ini_data_dir}/nemo/initial/${nem_grid}
  347. for f in \
  348. bathy_meter.nc coordinates.nc \
  349. ahmcoef.nc \
  350. K1rowdrg.nc M2rowdrg.nc mask_itf.nc \
  351. decay_scale_bot.nc decay_scale_cri.nc \
  352. mixing_power_bot.nc mixing_power_cri.nc mixing_power_pyc.nc \
  353. runoff_depth.nc subbasins.nc
  354. do
  355. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && ln -s ${ini_data_dir}/nemo/initial/${nem_grid}/$f
  356. done
  357. # Link geothermal heating file (independent of grid) and matching weight file
  358. ln -s ${ini_data_dir}/nemo/initial/Goutorbe_ghflux.nc
  359. ln -s ${ini_data_dir}/nemo/initial/weights_Goutorbe1_2_orca${nem_res_hor}_bilinear.nc
  360. # Link either restart files or climatology files for the initial state
  361. if $(has_config nemo:start_from_restart)
  362. then
  363. # When linking restart files, we accept three options:
  364. # (1) Merged files for ocean and ice, i.e.
  365. # restart_oce.nc and restart_ice.nc
  366. # (2) One-file-per-MPI-rank, i.e.
  367. # restart_oce_????.nc and restart_ice_????.nc
  368. # No check is done whether the number of restart files agrees
  369. # with the number of MPI ranks for NEMO!
  370. # (3) One-file-per-MPI-rank with a prefix, i.e.
  371. # <exp_name>_<time_step>_restart_oce_????.nc (similar for the ice)
  372. # The prefix is ignored.
  373. # The code assumes that one of the options can be applied! If more
  374. # options are applicable, the first is chosen. If none of the
  375. # options apply, NEMO will crash with missing restart file.
  376. if ls -U ${nem_restart_file_path}/restart_[oi]ce.nc > /dev/null 2>&1
  377. then
  378. ln -s ${nem_restart_file_path}/restart_[oi]ce.nc ./
  379. elif ls -U ${nem_restart_file_path}/restart_[oi]ce_????.nc > /dev/null 2>&1
  380. then
  381. ln -s ${nem_restart_file_path}/restart_[oi]ce_????.nc ./
  382. else
  383. for f in ${nem_restart_file_path}/????_????????_restart_[oi]ce_????.nc
  384. do
  385. ln -s $f $(echo $f | sed 's/.*_\(restart_[oi]ce_....\.nc\)/\1/')
  386. done
  387. fi
  388. else
  389. # Temperature and salinity files for initialisation
  390. ln -s ${ini_data_dir}/nemo/climatology/absolute_salinity_WOA13_decav_Reg1L75_clim.nc
  391. ln -s ${ini_data_dir}/nemo/climatology/conservative_temperature_WOA13_decav_Reg1L75_clim.nc
  392. ln -s ${ini_data_dir}/nemo/climatology/weights_WOA13d1_2_orca${nem_res_hor}_bilinear.nc
  393. # Grid dependent runoff files
  394. case ${nem_grid} in
  395. ORCA1*) ln -s ${ini_data_dir}/nemo/climatology/runoff-icb_DaiTrenberth_Depoorter_ORCA1_JD.nc ;;
  396. ORCA025*) ln -s ${ini_data_dir}/nemo/climatology/ORCA_R025_runoff_v1.1.nc ;;
  397. esac
  398. fi
  399. # XIOS files
  400. . ${ctrl_file_dir}/iodef.xml.sh > iodef.xml
  401. ln -s ${ctrl_file_dir}/context_nemo.xml
  402. ln -s ${ctrl_file_dir}/domain_def_nemo.xml
  403. ln -s ${ctrl_file_dir}/field_def_nemo-lim.xml
  404. ln -s ${ctrl_file_dir}/field_def_nemo-opa.xml
  405. ln -s ${ctrl_file_dir}/field_def_nemo-pisces.xml
  406. ln -s ${ctrl_file_dir}/file_def_nemo-lim3.xml file_def_nemo-lim.xml
  407. ln -s ${ctrl_file_dir}/file_def_nemo-opa.xml
  408. ln -s ${ctrl_file_dir}/file_def_nemo-pisces.xml
  409. # ---------------------------------------------------------------------
  410. # *** Files needed for the Runoff mapper (linked)
  411. # ---------------------------------------------------------------------
  412. ln -s ${ini_data_dir}/runoff-mapper/runoff_maps.nc
  413. # ---------------------------------------------------------------------
  414. # *** Files needed for OASIS (linked)
  415. # ---------------------------------------------------------------------
  416. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-ORCA${nem_res_hor}
  417. # Name table file
  418. ln -s ${ini_data_dir}/oasis/cf_name_table.txt
  419. # Grid definition files
  420. ln -s ${oas_grid_dir}/areas.nc
  421. ln -s ${oas_grid_dir}/grids.nc
  422. ln -s ${oas_grid_dir}/masks.nc
  423. # Weight files
  424. case ${ifs_res_hor} in
  425. 159) oas_agrd=080
  426. ;;
  427. 255) oas_agrd=128
  428. ;;
  429. 511) oas_agrd=256
  430. ;;
  431. 799) oas_agrd=400
  432. ;;
  433. *) error "Unsupported horizontal resolution (IFS): ${ifs_res_hor}"
  434. ;;
  435. esac
  436. case ${nem_res_hor} in
  437. 1) oas_ogrd=O1t0
  438. ;;
  439. 025) oas_ogrd=Ot25
  440. ;;
  441. *) error "Unsupported horizontal resolution (NEMO): ${nem_res_hor}"
  442. ;;
  443. esac
  444. if ${oas_link_weights}
  445. then
  446. for f in ${oas_grid_dir}/rmp_????_to_????_GAUSWGT.nc
  447. do
  448. ln -s $f
  449. done
  450. fi
  451. for f in ${oas_rst_files}
  452. do
  453. cp ${oas_grid_dir}/rst/$f .
  454. done
  455. else # i.e. $leg_is_restart == true
  456. # ---------------------------------------------------------------------
  457. # *** Remove all leftover output files from previous legs
  458. # ---------------------------------------------------------------------
  459. # IFS files
  460. rm -f ICM{SH,GG}${exp_name}+??????
  461. # NEMO files
  462. rm -f ${exp_name}_??_????????_????????_{grid_U,grid_V,grid_W,grid_T,icemod,SBC,scalar,SBC_scalar}.nc
  463. fi # ! $leg_is_restart
  464. # -------------------------------------------------------------------------
  465. # *** Create some control files
  466. # -------------------------------------------------------------------------
  467. # IFS, NEMO, LIM namelist and OASIS namcouple files
  468. . ${ctrl_file_dir}/namelist.ifs.sh > fort.4
  469. . ${ctrl_file_dir}/namelist.nemo.ref.sh > namelist_ref
  470. . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-coupled.cfg.sh > namelist_cfg
  471. . ${ctrl_file_dir}/namelist.lim3.ref.sh > namelist_ice_ref
  472. . ${ctrl_file_dir}/namelist.lim3-${nem_grid}.cfg.sh > namelist_ice_cfg
  473. . ${ctrl_file_dir}/namelist.runoffmapper.sh > namelist.runoffmapper
  474. . ${ctrl_file_dir}/namcouple.sh > namcouple
  475. # -------------------------------------------------------------------------
  476. # *** IFS climatology data
  477. # -------------------------------------------------------------------------
  478. icmclfile=${ini_data_dir}/ifs/${ifs_grid}/climate/ICMCL
  479. tempfile=tmp.$$
  480. grib_set=${GRIB_BIN_PATH}${GRIB_BIN_PATH:+/}grib_set
  481. # Create data for december, the year before the leg starts
  482. ${grib_set} \
  483. -s dataDate=$(printf "%04d" $((leg_start_date_yyyy-1)))1215 ${icmclfile}-12 \
  484. ICMCL${exp_name}INIT
  485. # Create data for all month in the years of the leg
  486. for (( y=${leg_start_date_yyyy} ; y<=${leg_end_date_yyyy} ; y++ ))
  487. do
  488. yy=$(printf "%04d" $y)
  489. for m in {1..12}
  490. do
  491. mm=$(printf "%02d" $m)
  492. ${grib_set} -s dataDate=${yy}${mm}15 ${icmclfile}-${mm} ${tempfile}
  493. cat ${tempfile} >> ICMCL${exp_name}INIT
  494. done
  495. done
  496. # Create data for january, the year after the leg ends
  497. ${grib_set} -s dataDate=$(printf "%04d" $((leg_end_date_yyyy+1)))0115 ${icmclfile}-01 \
  498. ${tempfile}
  499. cat ${tempfile} >> ICMCL${exp_name}INIT
  500. # Clean up
  501. rm -f ${tempfile}
  502. # -------------------------------------------------------------------------
  503. # *** Link the appropriate NEMO restart files of the previous leg
  504. # -------------------------------------------------------------------------
  505. if $leg_is_restart
  506. then
  507. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  508. for (( n=0 ; n<nem_numproc ; n++ ))
  509. do
  510. np=$(printf %04d ${n})
  511. ln -fs ${exp_name}_${ns}_restart_oce_${np}.nc restart_oce_${np}.nc
  512. ln -fs ${exp_name}_${ns}_restart_ice_${np}.nc restart_ice_${np}.nc
  513. done
  514. # Make sure there are no global restart files
  515. # If links are found, they will be removed. We are cautious and do
  516. # _not_ remove real files! However, if real global restart files are
  517. # present, NEMO/LIM will stop because time stamps will not match.
  518. [ -h restart_oce.nc ] && rm restart_oce.nc
  519. [ -h restart_ice.nc ] && rm restart_ice.nc
  520. fi
  521. # -------------------------------------------------------------------------
  522. # *** Remove some OASIS files of the previous leg
  523. # -------------------------------------------------------------------------
  524. if $leg_is_restart
  525. then
  526. rm -f anaisout_*
  527. fi
  528. # -------------------------------------------------------------------------
  529. # *** Start the run
  530. # -------------------------------------------------------------------------
  531. export DR_HOOK_IGNORE_SIGNALS='-1'
  532. export CPLNG='active'
  533. # Use the launch function from the platform configuration file
  534. t1=$(date +%s)
  535. launch \
  536. ${xio_numproc} ${xio_exe_file} -- \
  537. ${nem_numproc} ${nem_exe_file} -- \
  538. ${rnf_numproc} ${rnf_exe_file} -- \
  539. ${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name}
  540. t2=$(date +%s)
  541. tr=$(date -d "0 -$t1 sec + $t2 sec" +%T)
  542. # -------------------------------------------------------------------------
  543. # *** Check for signs of success
  544. # Note the tests provide no guarantee that things went fine! They are
  545. # just based on the IFS and NEMO log files. More tests (e.g. checking
  546. # restart files) could be implemented.
  547. # -------------------------------------------------------------------------
  548. # Checking for IFS success
  549. if [ -f ifs.stat ]
  550. then
  551. if [ "$(awk 'END{print $3}' ifs.stat)" == "CNT0" ]
  552. then
  553. info "Leg successfully completed according to IFS log file 'ifs.stat'."
  554. else
  555. error "Leg not completed according to IFS log file 'ifs.stat'."
  556. fi
  557. else
  558. error "IFS log file 'ifs.stat' not found after run."
  559. fi
  560. # Check for NEMO success
  561. if [ -f ocean.output ]
  562. then
  563. if [ "$(awk '/New day/{d=$10}END{print d}' ocean.output)" == "$(date -d "${leg_end_date} - 1 day" +%Y/%m/%d)" ]
  564. then
  565. info "Leg successfully completed according to NEMO log file 'ocean.output'."
  566. else
  567. error "Leg not completed according to NEMO log file 'ocean.output'."
  568. fi
  569. else
  570. error "NEMO log file 'ocean.output' not found after run."
  571. fi
  572. # -------------------------------------------------------------------------
  573. # *** Move IFS output files to archive directory
  574. # -------------------------------------------------------------------------
  575. outdir="output/ifs/$(printf %03d $((leg_number)))"
  576. mkdir -p ${outdir}
  577. prv_leg=$(printf %03d $((leg_number-1)))
  578. # This takes care of a special IFS feature: The output for the last time
  579. # step of each leg is written at the first time step of the new leg. The
  580. # following code makes sure that the output is appended to the appropriate
  581. # file. Since GRIB files are just streams, its done with a simple cat
  582. # command.
  583. for f in ICMSH${exp_name}+?????? ICMGG${exp_name}+??????
  584. do
  585. if [ -f output/ifs/${prv_leg}/${f} ]
  586. then
  587. cat ${f} >> output/ifs/${prv_leg}/${f}
  588. rm -f ${f}
  589. else
  590. mv ${f} ${outdir}
  591. fi
  592. done
  593. # -------------------------------------------------------------------------
  594. # *** Move NEMO output files to archive directory
  595. # -------------------------------------------------------------------------
  596. outdir="output/nemo/$(printf %03d $((leg_number)))"
  597. mkdir -p ${outdir}
  598. for f in ${exp_name}_??_????????_????????_*.nc ; do mv $f $outdir/ ; done
  599. #for v in grid_U grid_V grid_W grid_T icemod SBC scalar SBC_scalar
  600. #do
  601. # for f in ${exp_name}_??_????????_????????_${v}.nc
  602. # do
  603. # test -f $f && mv $f $outdir/
  604. # done
  605. #done
  606. # -------------------------------------------------------------------------
  607. # *** Move IFS restart files to archive directory
  608. # -------------------------------------------------------------------------
  609. if $leg_is_restart
  610. then
  611. outdir="restart/ifs/$(printf %03d $((leg_number)))"
  612. mkdir -p ${outdir}
  613. # Figure out the time part of the restart files (cf. CTIME on rcf files)
  614. # NOTE: Assuming that restarts are at full days (time=0000) only!
  615. nd="$(printf %06d $((leg_start_sec/(24*3600))))0000"
  616. mv srf${nd}.???? ${outdir}
  617. fi
  618. # -------------------------------------------------------------------------
  619. # *** Move NEMO restart files to archive directory
  620. # -------------------------------------------------------------------------
  621. if $leg_is_restart
  622. then
  623. outdir="restart/nemo/$(printf %03d $((leg_number)))"
  624. mkdir -p ${outdir}
  625. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  626. for f in oce ice
  627. do
  628. mv ${exp_name}_${ns}_restart_${f}_????.nc ${outdir}
  629. done
  630. fi
  631. # -------------------------------------------------------------------------
  632. # *** Copy OASIS restart files to archive directory
  633. # NOTE: These files are copied and not moved as they are used in the
  634. # next leg!
  635. # Note also that the OASIS restart files present at the end of
  636. # the leg correspond to the start of the next leg!
  637. # -------------------------------------------------------------------------
  638. outdir="restart/oasis/$(printf %03d $((leg_number+1)))"
  639. mkdir -p ${outdir}
  640. for f in ${oas_rst_files}
  641. do
  642. test -f ${f} && cp ${f} ${outdir}
  643. done
  644. # -------------------------------------------------------------------------
  645. # *** Copy rcf files to the archive directory (of the next leg!)
  646. # -------------------------------------------------------------------------
  647. outdir="restart/ifs/$(printf %03d $((leg_number+1)))"
  648. mkdir -p ${outdir}
  649. for f in rcf
  650. do
  651. test -f ${f} && cp ${f} ${outdir}
  652. done
  653. # -------------------------------------------------------------------------
  654. # *** Move log files to archive directory
  655. # -------------------------------------------------------------------------
  656. outdir="log/$(printf %03d $((leg_number)))"
  657. mkdir -p ${outdir}
  658. for f in \
  659. ifs.log ifs.stat fort.4 ocean.output \
  660. time.step solver.stat \
  661. nout.000000 debug.??.?????? A*_??.nc O*_??.nc
  662. do
  663. test -f ${f} && mv ${f} ${outdir}
  664. done
  665. # -------------------------------------------------------------------------
  666. # *** Write the restart control file
  667. # -------------------------------------------------------------------------
  668. # Compute CPMIP performance
  669. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  670. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1)) $(($ifs_numproc + $nem_numproc + $rnf_numproc + $xio_numproc)))"
  671. echo "#" | tee -a ${ece_info_file}
  672. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  673. | tee -a ${ece_info_file}
  674. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  675. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  676. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  677. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  678. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  679. force_run_from_scratch=false
  680. special_restart=false
  681. done # loop over legs
  682. # -----------------------------------------------------------------------------
  683. # *** Platform dependent finalising of the run
  684. # -----------------------------------------------------------------------------
  685. finalise
  686. exit 0