ece-ifs+nemo.sh.tmpl 37 KB

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