ece-ifs+nemo.sh.tmpl 37 KB

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