ece-ifs+nemo.sh.tmpl 31 KB

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