ece-ifs+nemo.sh.tmpl 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. #!/usr/bin/env bash
  2. set -ue
  3. # librunscript defines some helper functions
  4. source ./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 lim3 rnfmapper xios:detached oasis"
  14. # Experiment name (exactly 4 letters!)
  15. exp_name=[[[MOD:GENERAL:EXP_NAME]]]
  16. # Simulation start and end date. Use any (reasonable) syntax you want.
  17. run_start_date="[[[MOD:GENERAL:RUN_START_DATE]]]"
  18. run_end_date="[[[MOD:GENERAL:RUN_END_DATE]]]"
  19. # Set $force_run_from_scratch to 'true' if you want to force this run to start
  20. # from scratch, possibly ignoring any restart files present in the run
  21. # directory. Leave set to 'false' otherwise.
  22. # NOTE: If set to 'true' the run directory $run_dir is cleaned!
  23. force_run_from_scratch=[[[MOD:GENERAL:FORCE_RUN_FROM_SCRATCH]]]
  24. # Resolution
  25. ifs_grid=[[[MOD:IFS:GRID]]]
  26. nem_grid=[[[MOD:NEM:GRID]]]
  27. # Restart frequency. Use any (reasonable) number and time unit you want.
  28. # For runs without restart, leave this variable empty
  29. rst_freq="[[[MOD:GENERAL:RST_FREQ]]]"
  30. # Number of restart legs to be run in one go
  31. run_num_legs=[[[MOD:GENERAL:RUN_NUM_LEGS]]]
  32. # Directories
  33. start_dir=${PWD}
  34. ctrl_file_dir=${start_dir}/ctrl
  35. output_control_files_dir=${start_dir}/[[[MOD:GENERAL:OUTPUT_CONTROL_FILES_DIR]]]
  36. # Architecture
  37. build_arch=[[[PLT:ACTIVE:BUILD_ARCH]]]
  38. # This file is used to store information about restarts
  39. ece_info_file="ece.info"
  40. # -----------------------------------------------------------------------------
  41. # *** Read platform dependent configuration
  42. # -----------------------------------------------------------------------------
  43. source ./ecconf.cfg
  44. configure
  45. # -----------------------------------------------------------------------------
  46. # *** Time step settings
  47. # -----------------------------------------------------------------------------
  48. case "${ifs_grid}--${nem_grid}" in
  49. T159L*--ORCA1L*)
  50. ifs_time_step_sec=3600; nem_time_step_sec=2700; lim_time_step_sec=2700; cpl_freq_atm_oce_sec=10800
  51. ;;
  52. T255L*--ORCA1L*)
  53. ifs_time_step_sec=2700; nem_time_step_sec=2700; lim_time_step_sec=2700; cpl_freq_atm_oce_sec=2700
  54. ;;
  55. T511L*--ORCA025L*)
  56. ifs_time_step_sec=900 ; nem_time_step_sec=900 ; lim_time_step_sec=900 ; cpl_freq_atm_oce_sec=2700
  57. ;;
  58. *) error "Can't set time steps for unknown combination of horizontal grids: ${ifs_grid}-${nem_grid}"
  59. ;;
  60. esac
  61. # -----------------------------------------------------------------------------
  62. # *** IFS configuration
  63. # -----------------------------------------------------------------------------
  64. ifs_version=36r4
  65. ifs_di_freq=$(( 24 * 3600 / ifs_time_step_sec ))
  66. ifs_ddh_freq=$(( 120 * 3600 / ifs_time_step_sec ))
  67. ifs_res_hor=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\1:')
  68. ifs_res_ver=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\2:')
  69. ifs_numproc=[[[MOD:IFS:NUMPROC]]]
  70. ifs_exe_file=${ecearth_src_dir}/ifs-${ifs_version}/bin/ifsmaster-${build_arch}
  71. ifs_lastout=false
  72. ifs_cmip5=[[[MOD:IFS:CMIP5]]]
  73. ifs_cmip5_rcp=[[[MOD:IFS:CMIP5_RCP]]]
  74. ifs_cmip_fixyear=[[[MOD:IFS:CMIP_FIXYEAR]]]
  75. ifs_cmip6=[[[MOD:IFS:CMIP6]]]
  76. ifs_mac2sp=[[[MOD:IFS:CMIP6]]]
  77. ifs_cmip6piaer=[[[MOD:IFS:CMIP6]]]
  78. ifs_cmip6_scenario=[[[MOD:IFS:CMIP6_SCENARIO]]]
  79. lcmip6_strataer_simp=FALSE
  80. lcmip6_strataer_full=[[[MOD:IFS:CMIP6]]]
  81. lcmip6_strataer_bckgd=FALSE
  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. # IFS tuning parameters
  97. ifs_tuning_parameter_file=${ctrl_file_dir}/ifs-tuning-parameters-${ifs_grid}.sh
  98. if [ -f ${ifs_tuning_parameter_file} ]
  99. then
  100. source ${ifs_tuning_parameter_file}
  101. else
  102. error "Sorry, ${ifs_tuning_parameter_file} not found, exiting."
  103. fi
  104. # Select source of vegetation data:
  105. # ifs climatology from IFS
  106. # era20c vegetation from an off-line LPJ-Guess run forced with ERA20C
  107. # (currently available only for T255 and T159)
  108. #
  109. ifs_veg_source="era20c"
  110. case ${ifs_veg_source} in
  111. "ifs" )
  112. # Use Lambert-Beer to compute effective vegetation cover
  113. n_compute_eff_veg_fraction=2
  114. ;;
  115. "era20c" )
  116. # LPJG vegetation is provided as effective cover
  117. # Don't use Lambert-Beer
  118. n_compute_eff_veg_fraction=0
  119. ;;
  120. * )
  121. error "Vegetation from ${ifs_veg_source} not implemented"
  122. ;;
  123. esac
  124. # use DMI land ice physics and varying snow albedo
  125. ifs_landice=false
  126. # -----------------------------------------------------------------------------
  127. # *** NEMO/LIM configuration
  128. # -----------------------------------------------------------------------------
  129. # This is only needed if the experiment is started from an existing set of NEMO
  130. # restart files
  131. nem_restart_file_path=${start_dir}/nemo-rst
  132. nem_restart_offset=0
  133. nem_res_hor=$(echo ${nem_grid} | sed 's:ORCA\([0-9]\+\)L[0-9]\+:\1:')
  134. nem_exe_file=${ecearth_src_dir}/nemo-3.6/CONFIG/${nem_grid}_LIM3/BLD/bin/nemo.exe
  135. nem_numproc=[[[MOD:NEM:NUMPROC]]]
  136. # -----------------------------------------------------------------------------
  137. # *** Runoff mapper configuration
  138. # -----------------------------------------------------------------------------
  139. rnf_exe_file=${ecearth_src_dir}/runoff-mapper/bin/runoff-mapper.exe
  140. rnf_numproc=1
  141. # -----------------------------------------------------------------------------
  142. # *** OASIS configuration
  143. # -----------------------------------------------------------------------------
  144. # Restart files for the coupling fields (note 8 character limit in OASIS)
  145. # rstas.nc : atmosphere single-category fields
  146. # rstam.nc : atmosphere multi-category fields
  147. # rstos.nc : ocean single-category fields
  148. # rstom.nc : ocean multi-category fields
  149. oas_rst_files="rstas.nc rstos.nc"
  150. # Decide whether the OASIS weight files for interpolation should be linked from
  151. # the setup directory (true) or not (false). In the latter case, the weights
  152. # are re-computed at the start of the run.
  153. oas_link_weights=true
  154. # Flux correction for runoff (not calving) sent from Oasis to ocean.
  155. # 1.07945 is computed to compensate for a P-E=-0.016 mm/day
  156. oas_mb_fluxcorr=1.07945
  157. # -----------------------------------------------------------------------------
  158. # *** XIOS configuration
  159. # -----------------------------------------------------------------------------
  160. xio_exe_file=${ecearth_src_dir}/xios-2.5/bin/xios_server.exe
  161. xio_numproc=[[[MOD:XIO:NUMPROC]]]
  162. # -----------------------------------------------------------------------------
  163. # *** Extra initial conditions saved during the run
  164. # -----------------------------------------------------------------------------
  165. if has_config save_ic
  166. then
  167. source ./libsave_ic.sh
  168. declare -a save_ic_date save_ic_date1 save_ic_sec save_ic_day save_ic_ppt_file save_ic_nemo_ts
  169. fi
  170. # =============================================================================
  171. # *** END of User configuration
  172. # =============================================================================
  173. # =============================================================================
  174. # *** This is where the code begins ...
  175. # =============================================================================
  176. # -----------------------------------------------------------------------------
  177. # *** Create the run dir if necessary and go there
  178. # Everything is done from here.
  179. # -----------------------------------------------------------------------------
  180. if [ ! -d ${run_dir} ]
  181. then
  182. mkdir -p ${run_dir}
  183. fi
  184. cd ${run_dir}
  185. # -----------------------------------------------------------------------------
  186. # *** Determine the time span of this run and whether it's a restart leg
  187. # -----------------------------------------------------------------------------
  188. # Regularise the format of the start and end date of the simulation
  189. run_start_date=$(date -uR -d "${run_start_date}")
  190. run_end_date=$(date -uR -d "${run_end_date}")
  191. # -----------------------------------------------------------------------------
  192. # *** Set path to grib_set
  193. # -----------------------------------------------------------------------------
  194. grib_set=${GRIB_BIN_PATH}${GRIB_BIN_PATH:+/}grib_set
  195. # Loop over the number of legs
  196. for (( ; run_num_legs>0 ; run_num_legs-- ))
  197. do
  198. # Check for restart information file and set the current leg start date
  199. # Ignore restart information file if force_run_from_scratch is true
  200. if ${force_run_from_scratch} || ! [ -r ${ece_info_file} ]
  201. then
  202. leg_is_restart=false
  203. leg_start_date=${run_start_date}
  204. leg_number=1
  205. else
  206. leg_is_restart=true
  207. . ./${ece_info_file}
  208. leg_start_date=${leg_end_date}
  209. leg_number=$((leg_number+1))
  210. fi
  211. # Compute the end date of the current leg
  212. if [ -n "${rst_freq}" ]
  213. then
  214. leg_end_date=$(date -uR -d "${leg_start_date} + ${rst_freq}")
  215. else
  216. leg_end_date=${run_end_date}
  217. fi
  218. if [ $(date -u -d "${leg_end_date}" +%s) -ge $(date -u -d "${run_end_date}" +%s) ]
  219. then
  220. leg_end_date=${run_end_date}
  221. ifs_lastout=true
  222. fi
  223. # Some time variables needed later
  224. leg_length_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${leg_start_date}" +%s) ))
  225. leg_start_sec=$(( $(date -u -d "${leg_start_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  226. leg_end_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  227. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d)
  228. leg_start_date_yyyy=$(date -u -d "${leg_start_date}" +%Y)
  229. leg_end_date_yyyy=$(date -u -d "${leg_end_date}" +%Y)
  230. # Check whether there's actually time left to simulate - exit otherwise
  231. if [ ${leg_length_sec} -le 0 ]
  232. then
  233. info "Leg start date equal to or after end of simulation."
  234. info "Nothing left to do. Exiting."
  235. exit 0
  236. fi
  237. # Initial conditions saved during the run
  238. do_save_ic=false
  239. has_config save_ic && save_ic_get_config
  240. # if you do not use an option with save_ic, you must define 'do_save_ic' and
  241. # 'save_ic_date_offset' here or in ../libsave_ic.sh/save_ic_get_config()
  242. ${do_save_ic} && save_ic_define_vars
  243. # -------------------------------------------------------------------------
  244. # *** Prepare the run directory for a run from scratch
  245. # -------------------------------------------------------------------------
  246. if ! $leg_is_restart
  247. then
  248. # ---------------------------------------------------------------------
  249. # *** Check if run dir is empty. If not, and if we are allowed to do so
  250. # by ${force_run_from_scratch}, remove everything
  251. # ---------------------------------------------------------------------
  252. if $(ls * >& /dev/null)
  253. then
  254. if ${force_run_from_scratch}
  255. then
  256. rm -fr ${run_dir}/*
  257. else
  258. error "Run directory not empty and \$force_run_from_scratch not set."
  259. fi
  260. fi
  261. # ---------------------------------------------------------------------
  262. # *** Copy executables of model components
  263. # *** Additionally, create symlinks to the original place for reference
  264. # ---------------------------------------------------------------------
  265. cp ${ifs_exe_file} .
  266. ln -s ${ifs_exe_file} $(basename ${ifs_exe_file}).lnk
  267. cp ${nem_exe_file} .
  268. ln -s ${nem_exe_file} $(basename ${nem_exe_file}).lnk
  269. cp ${rnf_exe_file} .
  270. ln -s ${rnf_exe_file} $(basename ${rnf_exe_file}).lnk
  271. cp ${xio_exe_file} .
  272. ln -s ${xio_exe_file} $(basename ${xio_exe_file}).lnk
  273. # ---------------------------------------------------------------------
  274. # *** Files needed for IFS (linked)
  275. # ---------------------------------------------------------------------
  276. # Initial data
  277. ln -s \
  278. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIUA \
  279. ICMGG${exp_name}INIUA
  280. ln -s \
  281. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMSHECE3INIT \
  282. ICMSH${exp_name}INIT
  283. rm -f ICMGG${exp_name}INIT
  284. cp ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIT \
  285. ICMGG${exp_name}INIT
  286. # add bare_soil_albedo to ICMGG*INIT
  287. tempfile=tmp.$$
  288. ${grib_set} -s dataDate=$(date -u -d "$run_start_date" +%Y%m%d) \
  289. ${ini_data_dir}/ifs/${ifs_grid}/climate/bare_soil_albedos.grb \
  290. ${tempfile}
  291. cat ${tempfile} >> ICMGG${exp_name}INIT
  292. rm -f ${tempfile}
  293. # add land ice mask if needed
  294. if ${ifs_landice}
  295. then
  296. tempfile=tmp.$$
  297. cdo divc,10 -setcode,82 -selcode,141 ICMGG${exp_name}INIT ${tempfile}
  298. ${grib_set} -s gridType=reduced_gg ${tempfile} ${tempfile}
  299. cat ${tempfile} >> ICMGG${exp_name}INIT
  300. rm -f ${tempfile}
  301. fi
  302. # Other stuff
  303. ln -s ${ini_data_dir}/ifs/rtables/* .
  304. # Output control (ppt files)
  305. if [ ! -f ${output_control_files_dir}/pptdddddd0600 ] && [ ! -f ${output_control_files_dir}/pptdddddd0300 ];then
  306. echo "Error from ece-esm.sh: Neither the file pptdddddd0600 or pptdddddd0300 exists in the directory:"
  307. echo " " ${output_control_files_dir}
  308. exit -1
  309. fi
  310. mkdir postins
  311. cp ${output_control_files_dir}/ppt* postins/
  312. if [ -f postins/pptdddddd0600 ];then
  313. ln -s pptdddddd0600 postins/pptdddddd0000
  314. ln -s pptdddddd0600 postins/pptdddddd1200
  315. ln -s pptdddddd0600 postins/pptdddddd1800
  316. fi
  317. if [ -f postins/pptdddddd0300 ];then
  318. ln -s pptdddddd0300 postins/pptdddddd0900
  319. ln -s pptdddddd0300 postins/pptdddddd1500
  320. ln -s pptdddddd0300 postins/pptdddddd2100
  321. if [ ! -f postins/pptdddddd0600 ];then
  322. ln -s pptdddddd0300 postins/pptdddddd0000
  323. ln -s pptdddddd0300 postins/pptdddddd0600
  324. ln -s pptdddddd0300 postins/pptdddddd1200
  325. ln -s pptdddddd0300 postins/pptdddddd1800
  326. fi
  327. fi
  328. /bin/ls -1 postins/* > dirlist
  329. # ---------------------------------------------------------------------
  330. # *** Files needed for NEMO (linked)
  331. # ---------------------------------------------------------------------
  332. # Link initialisation files for matching ORCA grid
  333. for f in \
  334. bathy_meter.nc coordinates.nc \
  335. ahmcoef.nc \
  336. K1rowdrg.nc M2rowdrg.nc mask_itf.nc \
  337. decay_scale_bot.nc decay_scale_cri.nc \
  338. mixing_power_bot.nc mixing_power_cri.nc mixing_power_pyc.nc \
  339. runoff_depth.nc subbasins.nc
  340. do
  341. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && ln -s ${ini_data_dir}/nemo/initial/${nem_grid}/$f
  342. done
  343. # Link geothermal heating file (independent of grid) and matching weight file
  344. ln -s ${ini_data_dir}/nemo/initial/Goutorbe_ghflux.nc
  345. ln -s ${ini_data_dir}/nemo/initial/weights_Goutorbe1_2_orca${nem_res_hor}_bilinear.nc
  346. # Link the salinity climatology file (needed for diagnostics)
  347. ln -s ${ini_data_dir}/nemo/climatology/${nem_grid}/sali_ref_clim_monthly.nc
  348. # Link either restart files or climatology files for the initial state
  349. if $(has_config nemo:start_from_restart)
  350. then
  351. # When linking restart files, we accept three options:
  352. # (1) Merged files for ocean and ice, i.e.
  353. # restart_oce.nc and restart_ice.nc
  354. # (2) One-file-per-MPI-rank, i.e.
  355. # restart_oce_????.nc and restart_ice_????.nc
  356. # No check is done whether the number of restart files agrees
  357. # with the number of MPI ranks for NEMO!
  358. # (3) One-file-per-MPI-rank with a prefix, i.e.
  359. # <exp_name>_<time_step>_restart_oce_????.nc (similar for the ice)
  360. # The prefix is ignored.
  361. # The code assumes that one of the options can be applied! If more
  362. # options are applicable, the first is chosen. If none of the
  363. # options apply, NEMO will crash with missing restart file.
  364. if ls -U ${nem_restart_file_path}/restart_[oi]ce.nc > /dev/null 2>&1
  365. then
  366. ln -s ${nem_restart_file_path}/restart_[oi]ce.nc ./
  367. elif ls -U ${nem_restart_file_path}/restart_[oi]ce_????.nc > /dev/null 2>&1
  368. then
  369. ln -s ${nem_restart_file_path}/restart_[oi]ce_????.nc ./
  370. else
  371. for f in ${nem_restart_file_path}/????_????????_restart_[oi]ce_????.nc
  372. do
  373. ln -s $f $(echo $f | sed 's/.*_\(restart_[oi]ce_....\.nc\)/\1/')
  374. done
  375. fi
  376. else
  377. # Temperature and salinity files for initialisation
  378. ln -s ${ini_data_dir}/nemo/climatology/absolute_salinity_WOA13_decav_Reg1L75_clim.nc
  379. ln -s ${ini_data_dir}/nemo/climatology/conservative_temperature_WOA13_decav_Reg1L75_clim.nc
  380. ln -s ${ini_data_dir}/nemo/climatology/weights_WOA13d1_2_orca${nem_res_hor}_bilinear.nc
  381. # Grid dependent runoff files
  382. case ${nem_grid} in
  383. ORCA1*) ln -s ${ini_data_dir}/nemo/climatology/runoff-icb_DaiTrenberth_Depoorter_ORCA1_JD.nc ;;
  384. ORCA025*) ln -s ${ini_data_dir}/nemo/climatology/ORCA_R025_runoff_v1.1.nc ;;
  385. esac
  386. fi
  387. # for ocean_nudging
  388. if $(has_config nemo:ocenudg) ; then
  389. ln -fs ${ini_data_dir}/nemo/oce_nudg/resto.nc ./
  390. fi
  391. # XIOS files
  392. . ${ctrl_file_dir}/iodef.xml.sh > iodef.xml
  393. ln -s ${ctrl_file_dir}/context_nemo.xml
  394. ln -s ${ctrl_file_dir}/domain_def_nemo.xml
  395. ln -s ${ctrl_file_dir}/axis_def_nemo.xml
  396. ln -s ${ctrl_file_dir}/grids_def_nemo.xml
  397. ln -s ${ctrl_file_dir}/field_def_nemo-lim.xml
  398. ln -s ${ctrl_file_dir}/field_def_nemo-opa.xml
  399. ln -s ${ctrl_file_dir}/field_def_nemo-pisces.xml
  400. ln -s ${ctrl_file_dir}/field_def_nemo-inerttrc.xml
  401. ln -s ${output_control_files_dir}/file_def_nemo-lim3.xml file_def_nemo-lim.xml
  402. ln -s ${output_control_files_dir}/file_def_nemo-opa.xml
  403. ln -s ${output_control_files_dir}/file_def_nemo-pisces.xml
  404. if [ -f ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ]
  405. then
  406. cp ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ./
  407. else
  408. info "File 'coordinates_xios.nc' not found. NEMO can not be run with land domain removal!"
  409. fi
  410. # ---------------------------------------------------------------------
  411. # *** Files needed for the Runoff mapper (linked)
  412. # ---------------------------------------------------------------------
  413. ln -s ${ini_data_dir}/runoff-mapper/runoff_maps.nc
  414. # ---------------------------------------------------------------------
  415. # *** Files needed for OASIS (linked)
  416. # ---------------------------------------------------------------------
  417. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-ORCA${nem_res_hor}
  418. # Name table file
  419. ln -s ${ini_data_dir}/oasis/cf_name_table.txt
  420. # Grid definition files
  421. ln -s ${oas_grid_dir}/areas.nc
  422. ln -s ${oas_grid_dir}/grids.nc
  423. ln -s ${oas_grid_dir}/masks.nc
  424. # Weight files
  425. case ${ifs_res_hor} in
  426. 159) oas_agrd=080
  427. ;;
  428. 255) oas_agrd=128
  429. ;;
  430. 511) oas_agrd=256
  431. ;;
  432. 799) oas_agrd=400
  433. ;;
  434. *) error "Unsupported horizontal resolution (IFS): ${ifs_res_hor}"
  435. ;;
  436. esac
  437. case ${nem_res_hor} in
  438. 1) oas_ogrd=O1t0
  439. ;;
  440. 025) oas_ogrd=Ot25
  441. ;;
  442. *) error "Unsupported horizontal resolution (NEMO): ${nem_res_hor}"
  443. ;;
  444. esac
  445. if ${oas_link_weights}
  446. then
  447. for f in ${oas_grid_dir}/rmp_????_to_????_GAUSWGT.nc
  448. do
  449. ln -s $f
  450. done
  451. fi
  452. for f in ${oas_rst_files}
  453. do
  454. cp ${oas_grid_dir}/rst/$f .
  455. done
  456. else # i.e. $leg_is_restart == true
  457. # ---------------------------------------------------------------------
  458. # *** Remove all leftover output files from previous legs
  459. # ---------------------------------------------------------------------
  460. # IFS files
  461. rm -f ICM{SH,GG}${exp_name}+??????
  462. # NEMO files
  463. rm -f ${exp_name}_??_????????_????????_{grid_U,grid_V,grid_W,grid_T,icemod,SBC,scalar,SBC_scalar}.nc
  464. fi # ! $leg_is_restart
  465. #--------------------------------------------------------------------------
  466. # *** Surface restoring and ocean nudging options
  467. #--------------------------------------------------------------------------
  468. #for ocean_nudging
  469. if $(has_config nemo:ocenudg) ; then
  470. ln -fs ${ini_data_dir}/nemo/oce_nudg/temp_sal_*.nc ./
  471. fi
  472. #for surface restoring
  473. if $(has_config nemo:surfresto) ; then
  474. ln -fs ${ini_data_dir}/nemo/surface_restoring/sss_restore_data*.nc ./
  475. ln -fs ${ini_data_dir}/nemo/surface_restoring/sst_restore_data*.nc ./
  476. ln -fs ${ini_data_dir}/nemo/surface_restoring/mask_restore*.nc ./
  477. fi
  478. # -------------------------------------------------------------------------
  479. # *** Remove land grid-points
  480. # -------------------------------------------------------------------------
  481. if $(has_config nemo:elpin)
  482. then
  483. if [ ! -f coordinates_xios.nc ]
  484. then
  485. error "ELpIN requested, but file 'coordinates_xios.nc' was not found"
  486. fi
  487. jpns=($(${ecearth_src_dir}/util/ELPiN/ELPiNv2.cmd ${nem_numproc}))
  488. info "nemo domain decompostion from ELpIN: ${jpns[@]}"
  489. nem_numproc=${jpns[0]}
  490. nem_jpni=${jpns[1]}
  491. nem_jpnj=${jpns[2]}
  492. else
  493. info "nemo original domain decomposition (not using ELPiN)"
  494. fi
  495. # -------------------------------------------------------------------------
  496. # *** Initial conditions saved during the run
  497. # -------------------------------------------------------------------------
  498. ${do_save_ic} && save_ic_prepare_output
  499. # -------------------------------------------------------------------------
  500. # *** Create some control files
  501. # -------------------------------------------------------------------------
  502. # IFS frequency output for namelist
  503. if [ -f postins/pptdddddd0300 ]
  504. then
  505. ifs_output_freq=$(( 3 * 3600 / ifs_time_step_sec ))
  506. elif [ -f postins/pptdddddd0600 ]
  507. then
  508. ifs_output_freq=$(( 6 * 3600 / ifs_time_step_sec ))
  509. else
  510. error "IFS output frequency undefined."
  511. fi
  512. # IFS, NEMO, LIM namelist and OASIS namcouple files
  513. . ${ctrl_file_dir}/namelist.ifs.sh > fort.4
  514. . ${ctrl_file_dir}/namelist.nemo.ref.sh > namelist_ref
  515. . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-coupled.cfg.sh > namelist_cfg
  516. . ${ctrl_file_dir}/namelist.lim3.ref.sh > namelist_ice_ref
  517. . ${ctrl_file_dir}/namelist.lim3-${nem_grid}.cfg.sh > namelist_ice_cfg
  518. . ${ctrl_file_dir}/namelist.runoffmapper.sh > namelist.runoffmapper
  519. . ${ctrl_file_dir}/namcouple.sh > namcouple
  520. # -------------------------------------------------------------------------
  521. # *** Create ICMCL file with vegetation fields
  522. # -------------------------------------------------------------------------
  523. tempfile=tmp.$$
  524. case ${ifs_veg_source} in
  525. "ifs" )
  526. # Vegetation from IFS (climatology)
  527. icmclfile=${ini_data_dir}/ifs/${ifs_grid}/climate/ICMCL_ONLY_VEG_PD
  528. # Create data for december, the year before the leg starts
  529. ${grib_set} \
  530. -s dataDate=$(printf "%04d" $((leg_start_date_yyyy-1)))1215 \
  531. ${icmclfile}-12 ICMCL${exp_name}INIT
  532. # Create data for all month in the years of the leg
  533. for (( y=${leg_start_date_yyyy} ; y<=${leg_end_date_yyyy} ; y++ ))
  534. do
  535. yy=$(printf "%04d" $y)
  536. for m in {1..12}
  537. do
  538. mm=$(printf "%02d" $m)
  539. ${grib_set} -s dataDate=${yy}${mm}15 ${icmclfile}-${mm} ${tempfile}
  540. cat ${tempfile} >> ICMCL${exp_name}INIT
  541. done
  542. done
  543. # Create data for january, the year after the leg ends
  544. ${grib_set} \
  545. -s dataDate=$(printf "%04d" $((leg_end_date_yyyy+1)))0115 \
  546. ${icmclfile}-01 ${tempfile}
  547. cat ${tempfile} >> ICMCL${exp_name}INIT
  548. ;;
  549. "era20c" )
  550. # Vegetation from an off-line LPJG run forced with ERA20C (v16)
  551. rm -f ICMCL${exp_name}INIT
  552. # Create data for all years of the leg, including one year
  553. # before and one year after
  554. for (( yr=leg_start_date_yyyy-1 ; yr<=leg_end_date_yyyy+1 ; yr+=1 ))
  555. do
  556. if [ $ifs_cmip_fixyear -le 0 ]
  557. then
  558. cat ${ini_data_dir}/ifs/${ifs_grid}/icmcl_v16/icmcl_$yr.grb >> ICMCL${exp_name}INIT
  559. else
  560. # Fixed year forcing, requires cdo!
  561. # If cdo is not available at runtime you need to fix proper
  562. # icmcl files beforehand and use them here
  563. cdo setyear,$yr ${ini_data_dir}/ifs/${ifs_grid}/icmcl_v16/icmcl_${ifs_cmip_fixyear}.grb ${tempfile}
  564. cat ${tempfile} >> ICMCL${exp_name}INIT
  565. fi
  566. done
  567. ;;
  568. * )
  569. error "Vegetation from ${ifs_veg_source} not implemented"
  570. ;;
  571. esac
  572. # Clean up
  573. rm -f ${tempfile}
  574. # -------------------------------------------------------------------------
  575. # *** Link the appropriate NEMO restart files of the previous leg
  576. # -------------------------------------------------------------------------
  577. if $leg_is_restart
  578. then
  579. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  580. for (( n=0 ; n<nem_numproc ; n++ ))
  581. do
  582. np=$(printf %04d ${n})
  583. ln -fs ${exp_name}_${ns}_restart_oce_${np}.nc restart_oce_${np}.nc
  584. ln -fs ${exp_name}_${ns}_restart_ice_${np}.nc restart_ice_${np}.nc
  585. done
  586. # Make sure there are no global restart files
  587. # If links are found, they will be removed. We are cautious and do
  588. # _not_ remove real files! However, if real global restart files are
  589. # present, NEMO/LIM will stop because time stamps will not match.
  590. [ -h restart_oce.nc ] && rm restart_oce.nc
  591. [ -h restart_ice.nc ] && rm restart_ice.nc
  592. fi
  593. # -------------------------------------------------------------------------
  594. # *** Remove some OASIS files of the previous leg
  595. # -------------------------------------------------------------------------
  596. if $leg_is_restart
  597. then
  598. rm -f anaisout_*
  599. fi
  600. # -------------------------------------------------------------------------
  601. # *** Start the run
  602. # -------------------------------------------------------------------------
  603. export DR_HOOK_IGNORE_SIGNALS='-1'
  604. export CPLNG='active'
  605. # Use the launch function from the platform configuration file
  606. t1=$(date +%s)
  607. launch \
  608. ${xio_numproc} ${xio_exe_file} -- \
  609. ${nem_numproc} ${nem_exe_file} -- \
  610. ${rnf_numproc} ${rnf_exe_file} -- \
  611. ${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name}
  612. t2=$(date +%s)
  613. tr=$(date -u -d "0 -$t1 sec + $t2 sec" +%T)
  614. # -------------------------------------------------------------------------
  615. # *** Check for signs of success
  616. # Note the tests provide no guarantee that things went fine! They are
  617. # just based on the IFS and NEMO log files. More tests (e.g. checking
  618. # restart files) could be implemented.
  619. # -------------------------------------------------------------------------
  620. # Checking for IFS success
  621. if [ -f ifs.stat ]
  622. then
  623. if [ "$(awk 'END{print $3}' ifs.stat)" == "CNT0" ]
  624. then
  625. info "Leg successfully completed according to IFS log file 'ifs.stat'."
  626. else
  627. error "Leg not completed according to IFS log file 'ifs.stat'."
  628. fi
  629. else
  630. error "IFS log file 'ifs.stat' not found after run."
  631. fi
  632. # Check for NEMO success
  633. if [ -f ocean.output ]
  634. then
  635. if [ "$(sed -n '/New day/h; ${g;s:.*\([0-9/]\{10\}\).*:\1:;p;}' ocean.output)" == "$(date -u -d "${leg_end_date} - 1 day" +%Y/%m/%d)" ]
  636. then
  637. info "Leg successfully completed according to NEMO log file 'ocean.output'."
  638. else
  639. error "Leg not completed according to NEMO log file 'ocean.output'."
  640. fi
  641. else
  642. error "NEMO log file 'ocean.output' not found after run."
  643. fi
  644. # -------------------------------------------------------------------------
  645. # *** Post-process initial conditions saved during the run if requested
  646. # -------------------------------------------------------------------------
  647. ${do_save_ic} && save_ic_postproc
  648. # -------------------------------------------------------------------------
  649. # *** Move IFS output files to archive directory
  650. # -------------------------------------------------------------------------
  651. outdir="output/ifs/$(printf %03d $((leg_number)))"
  652. mkdir -p ${outdir}
  653. prv_leg=$(printf %03d $((leg_number-1)))
  654. # This takes care of a special IFS feature: The output for the last time
  655. # step of each leg is written at the first time step of the new leg. The
  656. # following code makes sure that the output is appended to the appropriate
  657. # file. Since GRIB files are just streams, its done with a simple cat
  658. # command.
  659. for f in ICMSH${exp_name}+?????? ICMGG${exp_name}+??????
  660. do
  661. if [ -f output/ifs/${prv_leg}/${f} ]
  662. then
  663. cat ${f} >> output/ifs/${prv_leg}/${f}
  664. rm -f ${f}
  665. else
  666. mv ${f} ${outdir}
  667. fi
  668. done
  669. # -------------------------------------------------------------------------
  670. # *** Move NEMO output files to archive directory
  671. # -------------------------------------------------------------------------
  672. outdir="output/nemo/$(printf %03d $((leg_number)))"
  673. mkdir -p ${outdir}
  674. for v in grid_U grid_V grid_W grid_T icemod SBC scalar SBC_scalar diad_T \
  675. grid_T_2D grid_U_2D grid_V_2D grid_W_2D grid_T_3D grid_U_3D grid_V_3D grid_W_3D \
  676. grid_1point grid_T_3D_ncatice vert_sum \
  677. grid_ptr_W_3basin_3D grid_ptr_T_3basin_2D grid_ptr_T_2D \
  678. zoom_700_sum zoom_300_sum zoom_2000_sum
  679. do
  680. for f in ${exp_name}_*_????????_????????_*${v}.nc
  681. do
  682. test -f $f && mv $f $outdir/
  683. done
  684. done
  685. # -------------------------------------------------------------------------
  686. # *** Move IFS restart files to archive directory
  687. # -------------------------------------------------------------------------
  688. if $leg_is_restart
  689. then
  690. outdir="restart/ifs/$(printf %03d $((leg_number)))"
  691. mkdir -p ${outdir}
  692. # Figure out the time part of the restart files (cf. CTIME on rcf files)
  693. # NOTE: Assuming that restarts are at full days (time=0000) only!
  694. nd="$(printf %06d $((leg_start_sec/(24*3600))))0000"
  695. mv srf${nd}.???? ${outdir}
  696. fi
  697. # -------------------------------------------------------------------------
  698. # *** Move NEMO restart files to archive directory
  699. # -------------------------------------------------------------------------
  700. if $leg_is_restart
  701. then
  702. outdir="restart/nemo/$(printf %03d $((leg_number)))"
  703. mkdir -p ${outdir}
  704. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  705. for f in oce ice
  706. do
  707. mv ${exp_name}_${ns}_restart_${f}_????.nc ${outdir}
  708. done
  709. fi
  710. # -------------------------------------------------------------------------
  711. # *** Copy OASIS restart files to archive directory
  712. # NOTE: These files are copied and not moved as they are used in the
  713. # next leg!
  714. # Note also that the OASIS restart files present at the end of
  715. # the leg correspond to the start of the next leg!
  716. # -------------------------------------------------------------------------
  717. outdir="restart/oasis/$(printf %03d $((leg_number+1)))"
  718. mkdir -p ${outdir}
  719. for f in ${oas_rst_files}
  720. do
  721. test -f ${f} && cp ${f} ${outdir}
  722. done
  723. # -------------------------------------------------------------------------
  724. # *** Copy rcf files to the archive directory (of the next leg!)
  725. # -------------------------------------------------------------------------
  726. outdir="restart/ifs/$(printf %03d $((leg_number+1)))"
  727. mkdir -p ${outdir}
  728. for f in rcf
  729. do
  730. test -f ${f} && cp ${f} ${outdir}
  731. done
  732. # -------------------------------------------------------------------------
  733. # *** Move log files to archive directory
  734. # -------------------------------------------------------------------------
  735. outdir="log/$(printf %03d $((leg_number)))"
  736. mkdir -p ${outdir}
  737. for f in \
  738. ifs.log ifs.stat fort.4 ocean.output \
  739. time.step solver.stat \
  740. nout.000000 debug.??.?????? A*_??.nc O*_??.nc
  741. do
  742. test -f ${f} && mv ${f} ${outdir}
  743. done
  744. # -------------------------------------------------------------------------
  745. # *** Write the restart control file
  746. # -------------------------------------------------------------------------
  747. # Compute CPMIP performance
  748. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  749. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1)) $(($ifs_numproc + $nem_numproc + $rnf_numproc + $xio_numproc)))"
  750. echo "#" | tee -a ${ece_info_file}
  751. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  752. | tee -a ${ece_info_file}
  753. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  754. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  755. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  756. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  757. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  758. force_run_from_scratch=false
  759. done # loop over legs
  760. # -----------------------------------------------------------------------------
  761. # *** Platform dependent finalising of the run
  762. # -----------------------------------------------------------------------------
  763. finalise
  764. exit 0