ece-ifs+nemo.sh.tmpl 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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=true
  23. special_restart_from=IC90
  24. special_restart_date="1991-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. # PUT HERE THE INSTRUCTIONS TO COPY THE restart files
  200. rsync -av ${run_dir}/../../archive/${special_restart_from}/restart/ifs/${special_restart_leg}/ ${run_dir}
  201. rsync -av ${run_dir}/../../archive/${special_restart_from}/restart/oasis/${special_restart_leg}/ ${run_dir}
  202. cd ${run_dir}/../../archive/${special_restart_from}/restart/nemo/${special_restart_leg}
  203. for f in *.nc; do
  204. nf=${exp_name}${f:4}
  205. cp $f ${run_dir}/$nf
  206. done
  207. cd -
  208. cd ${run_dir}
  209. for f in ${exp_name}_????????_restart_???_????.nc; do
  210. nf=${f:14}
  211. ln -s $f $nf
  212. done
  213. cd -
  214. rm -f ${run_dir}/ICMCL${special_restart_from}INIT
  215. mv ${run_dir}/ICMGG${special_restart_from}INIUA ${run_dir}/ICMGG${exp_name}INIUA
  216. mv ${run_dir}/ICMGG${special_restart_from}INIT ${run_dir}/ICMGG${exp_name}INIT
  217. mv ${run_dir}/ICMSH${special_restart_from}INIT ${run_dir}/ICMSH${exp_name}INIT
  218. fi
  219. else
  220. force_run_from_scratch=false
  221. special_restart=false
  222. fi
  223. cd ${run_dir}
  224. # -----------------------------------------------------------------------------
  225. # *** Determine the time span of this run and whether it's a restart leg
  226. # -----------------------------------------------------------------------------
  227. # Regularise the format of the start and end date of the simulation
  228. run_start_date=$(date -uR -d "${run_start_date}")
  229. run_end_date=$(date -uR -d "${run_end_date}")
  230. # -----------------------------------------------------------------------------
  231. # *** Set path to grib_set
  232. # -----------------------------------------------------------------------------
  233. grib_set=${GRIB_BIN_PATH}${GRIB_BIN_PATH:+/}grib_set
  234. # Loop over the number of legs
  235. for (( ; run_num_legs>0 ; run_num_legs-- ))
  236. do
  237. # Check for restart information file and set the current leg start date
  238. # Ignore restart information file if force_run_from_scratch is true
  239. if ${force_run_from_scratch} || ! [ -r ${ece_info_file} ]
  240. then
  241. leg_is_restart=false
  242. leg_start_date=${run_start_date}
  243. leg_number=1
  244. else
  245. leg_is_restart=true
  246. . ./${ece_info_file}
  247. leg_start_date=${leg_end_date}
  248. leg_number=$((leg_number+1))
  249. fi
  250. # Compute the end date of the current leg
  251. if [ -n "${rst_freq}" ]
  252. then
  253. leg_end_date=$(date -uR -d "${leg_start_date} + ${rst_freq}")
  254. else
  255. leg_end_date=${run_end_date}
  256. fi
  257. if [ $(date -u -d "${leg_end_date}" +%s) -gt $(date -u -d "${run_end_date}" +%s) ]
  258. then
  259. leg_end_date=${run_end_date}
  260. fi
  261. # Some time variables needed later
  262. leg_length_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${leg_start_date}" +%s) ))
  263. leg_start_sec=$(( $(date -u -d "${leg_start_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  264. leg_end_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  265. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d)
  266. leg_start_date_yyyy=$(date -u -d "${leg_start_date}" +%Y)
  267. leg_end_date_yyyy=$(date -u -d "${leg_end_date}" +%Y)
  268. # Check whether there's actually time left to simulate - exit otherwise
  269. if [ ${leg_length_sec} -le 0 ]
  270. then
  271. info "Leg start date equal to or after end of simulation."
  272. info "Nothing left to do. Exiting."
  273. exit 0
  274. fi
  275. # Initial conditions saved during the run
  276. do_save_ic=false
  277. has_config save_ic && save_ic_get_config
  278. # if you do not use an option with save_ic, you must define 'do_save_ic' and
  279. # 'save_ic_date_offset' here or in ../libsave_ic.sh/save_ic_get_config()
  280. ${do_save_ic} && save_ic_define_vars
  281. # -------------------------------------------------------------------------
  282. # *** Prepare the run directory for a run from scratch
  283. # -------------------------------------------------------------------------
  284. if ! $leg_is_restart
  285. then
  286. # ---------------------------------------------------------------------
  287. # *** Check if run dir is empty. If not, and if we are allowed to do so
  288. # by ${force_run_from_scratch}, remove everything
  289. # ---------------------------------------------------------------------
  290. if $(ls * >& /dev/null)
  291. then
  292. if ${force_run_from_scratch}
  293. then
  294. rm -fr ${run_dir}/*
  295. else
  296. error "Run directory not empty and \$force_run_from_scratch not set."
  297. fi
  298. fi
  299. # ---------------------------------------------------------------------
  300. # *** Copy executables of model components
  301. # *** Additionally, create symlinks to the original place for reference
  302. # ---------------------------------------------------------------------
  303. cp ${ifs_exe_file} .
  304. ln -s ${ifs_exe_file} $(basename ${ifs_exe_file}).lnk
  305. cp ${nem_exe_file} .
  306. ln -s ${nem_exe_file} $(basename ${nem_exe_file}).lnk
  307. cp ${rnf_exe_file} .
  308. ln -s ${rnf_exe_file} $(basename ${rnf_exe_file}).lnk
  309. cp ${xio_exe_file} .
  310. ln -s ${xio_exe_file} $(basename ${xio_exe_file}).lnk
  311. # ---------------------------------------------------------------------
  312. # *** Files needed for IFS (linked)
  313. # ---------------------------------------------------------------------
  314. # Initial data
  315. ln -s \
  316. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIUA \
  317. ICMGG${exp_name}INIUA
  318. ln -s \
  319. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMSHECE3INIT \
  320. ICMSH${exp_name}INIT
  321. rm -f ICMGG${exp_name}INIT
  322. cp ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIT \
  323. ICMGG${exp_name}INIT
  324. # add bare_soil_albedo to ICMGG*INIT
  325. tempfile=tmp.$$
  326. ${grib_set} -s dataDate=$(date -u -d "$run_start_date" +%Y%m%d) \
  327. ${ini_data_dir}/ifs/${ifs_grid}/climate/bare_soil_albedos.grb \
  328. ${tempfile}
  329. cat ${tempfile} >> ICMGG${exp_name}INIT
  330. rm -f ${tempfile}
  331. # Other stuff
  332. ln -s ${ini_data_dir}/ifs/rtables/* .
  333. # Output control (ppt files)
  334. if [ ! -f ${output_control_files_dir}/pptdddddd0600 ] && [ ! -f ${output_control_files_dir}/pptdddddd0300 ];then
  335. echo "Error from ece-esm.sh: Neither the file pptdddddd0600 or pptdddddd0300 exists in the directory:"
  336. echo " " ${output_control_files_dir}
  337. exit -1
  338. fi
  339. mkdir postins
  340. cp ${output_control_files_dir}/ppt* postins/
  341. if [ -f postins/pptdddddd0600 ];then
  342. ln -s pptdddddd0600 postins/pptdddddd0000
  343. ln -s pptdddddd0600 postins/pptdddddd1200
  344. ln -s pptdddddd0600 postins/pptdddddd1800
  345. fi
  346. if [ -f postins/pptdddddd0300 ];then
  347. ln -s pptdddddd0300 postins/pptdddddd0900
  348. ln -s pptdddddd0300 postins/pptdddddd1500
  349. ln -s pptdddddd0300 postins/pptdddddd2100
  350. if [ ! -f postins/pptdddddd0600 ];then
  351. ln -s pptdddddd0300 postins/pptdddddd0000
  352. ln -s pptdddddd0300 postins/pptdddddd0600
  353. ln -s pptdddddd0300 postins/pptdddddd1200
  354. ln -s pptdddddd0300 postins/pptdddddd1800
  355. fi
  356. fi
  357. /bin/ls -1 postins/* > dirlist
  358. # ---------------------------------------------------------------------
  359. # *** Files needed for NEMO (linked)
  360. # ---------------------------------------------------------------------
  361. # Link initialisation files for matching ORCA grid
  362. for f in \
  363. bathy_meter.nc coordinates.nc \
  364. ahmcoef.nc \
  365. K1rowdrg.nc M2rowdrg.nc mask_itf.nc \
  366. decay_scale_bot.nc decay_scale_cri.nc \
  367. mixing_power_bot.nc mixing_power_cri.nc mixing_power_pyc.nc \
  368. runoff_depth.nc subbasins.nc
  369. do
  370. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && ln -s ${ini_data_dir}/nemo/initial/${nem_grid}/$f
  371. done
  372. # Link geothermal heating file (independent of grid) and matching weight file
  373. ln -s ${ini_data_dir}/nemo/initial/Goutorbe_ghflux.nc
  374. ln -s ${ini_data_dir}/nemo/initial/weights_Goutorbe1_2_orca${nem_res_hor}_bilinear.nc
  375. # Link the salinity climatology file (needed for diagnostics)
  376. ln -s ${ini_data_dir}/nemo/climatology/${nem_grid}/sali_ref_clim_monthly.nc
  377. # Link either restart files or climatology files for the initial state
  378. if $(has_config nemo:start_from_restart)
  379. then
  380. # When linking restart files, we accept three options:
  381. # (1) Merged files for ocean and ice, i.e.
  382. # restart_oce.nc and restart_ice.nc
  383. # (2) One-file-per-MPI-rank, i.e.
  384. # restart_oce_????.nc and restart_ice_????.nc
  385. # No check is done whether the number of restart files agrees
  386. # with the number of MPI ranks for NEMO!
  387. # (3) One-file-per-MPI-rank with a prefix, i.e.
  388. # <exp_name>_<time_step>_restart_oce_????.nc (similar for the ice)
  389. # The prefix is ignored.
  390. # The code assumes that one of the options can be applied! If more
  391. # options are applicable, the first is chosen. If none of the
  392. # options apply, NEMO will crash with missing restart file.
  393. if ls -U ${nem_restart_file_path}/restart_[oi]ce.nc > /dev/null 2>&1
  394. then
  395. ln -s ${nem_restart_file_path}/restart_[oi]ce.nc ./
  396. elif ls -U ${nem_restart_file_path}/restart_[oi]ce_????.nc > /dev/null 2>&1
  397. then
  398. ln -s ${nem_restart_file_path}/restart_[oi]ce_????.nc ./
  399. else
  400. for f in ${nem_restart_file_path}/????_????????_restart_[oi]ce_????.nc
  401. do
  402. ln -s $f $(echo $f | sed 's/.*_\(restart_[oi]ce_....\.nc\)/\1/')
  403. done
  404. fi
  405. else
  406. # Temperature and salinity files for initialisation
  407. ln -s ${ini_data_dir}/nemo/climatology/absolute_salinity_WOA13_decav_Reg1L75_clim.nc
  408. ln -s ${ini_data_dir}/nemo/climatology/conservative_temperature_WOA13_decav_Reg1L75_clim.nc
  409. ln -s ${ini_data_dir}/nemo/climatology/weights_WOA13d1_2_orca${nem_res_hor}_bilinear.nc
  410. # Grid dependent runoff files
  411. case ${nem_grid} in
  412. ORCA1*) ln -s ${ini_data_dir}/nemo/climatology/runoff-icb_DaiTrenberth_Depoorter_ORCA1_JD.nc ;;
  413. ORCA025*) ln -s ${ini_data_dir}/nemo/climatology/ORCA_R025_runoff_v1.1.nc ;;
  414. esac
  415. fi
  416. # for ocean_nudging
  417. if $(has_config nemo:ocenudg) ; then
  418. ln -fs ${ini_data_dir}/nemo/oce_nudg/resto.nc ./
  419. fi
  420. # XIOS files
  421. . ${ctrl_file_dir}/iodef.xml.sh > iodef.xml
  422. cp ${ctrl_file_dir}/context_nemo.xml ./
  423. cp ${ctrl_file_dir}/domain_def_nemo.xml ./
  424. cp ${ctrl_file_dir}/axis_def_nemo.xml ./
  425. cp ${ctrl_file_dir}/grids_def_nemo.xml ./
  426. cp ${ctrl_file_dir}/field_def_nemo-lim.xml ./
  427. cp ${ctrl_file_dir}/field_def_nemo-opa.xml ./
  428. cp ${ctrl_file_dir}/field_def_nemo-pisces.xml ./
  429. cp ${ctrl_file_dir}/field_def_nemo-inerttrc.xml ./
  430. cp ${output_control_files_dir}/file_def_nemo-lim3.xml file_def_nemo-lim.xml
  431. cp ${output_control_files_dir}/file_def_nemo-opa.xml ./
  432. cp ${output_control_files_dir}/file_def_nemo-pisces.xml ./
  433. if [ -f ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ]
  434. then
  435. cp ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ./
  436. else
  437. info "File 'coordinates_xios.nc' not found. NEMO can not be run with land domain removal!"
  438. fi
  439. # ---------------------------------------------------------------------
  440. # *** Files needed for the Runoff mapper (linked)
  441. # ---------------------------------------------------------------------
  442. ln -s ${ini_data_dir}/runoff-mapper/runoff_maps.nc
  443. # ---------------------------------------------------------------------
  444. # *** Files needed for OASIS (linked)
  445. # ---------------------------------------------------------------------
  446. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-ORCA${nem_res_hor}
  447. # Name table file
  448. ln -s ${ini_data_dir}/oasis/cf_name_table.txt
  449. # Grid definition files
  450. ln -s ${oas_grid_dir}/areas.nc
  451. ln -s ${oas_grid_dir}/grids.nc
  452. ln -s ${oas_grid_dir}/masks.nc
  453. # Weight files
  454. case ${ifs_res_hor} in
  455. 159) oas_agrd=080
  456. ;;
  457. 255) oas_agrd=128
  458. ;;
  459. 511) oas_agrd=256
  460. ;;
  461. 799) oas_agrd=400
  462. ;;
  463. *) error "Unsupported horizontal resolution (IFS): ${ifs_res_hor}"
  464. ;;
  465. esac
  466. case ${nem_res_hor} in
  467. 1) oas_ogrd=O1t0
  468. ;;
  469. 025) oas_ogrd=Ot25
  470. ;;
  471. *) error "Unsupported horizontal resolution (NEMO): ${nem_res_hor}"
  472. ;;
  473. esac
  474. if ${oas_link_weights}
  475. then
  476. for f in ${oas_grid_dir}/rmp_????_to_????_GAUSWGT.nc
  477. do
  478. ln -s $f
  479. done
  480. fi
  481. for f in ${oas_rst_files}
  482. do
  483. cp ${oas_grid_dir}/rst/$f .
  484. done
  485. else # i.e. $leg_is_restart == true
  486. # ---------------------------------------------------------------------
  487. # *** Remove all leftover output files from previous legs
  488. # ---------------------------------------------------------------------
  489. # IFS files
  490. rm -f ICM{SH,GG}${exp_name}+??????
  491. # NEMO files
  492. rm -f ${exp_name}_??_????????_????????_{grid_U,grid_V,grid_W,grid_T,icemod,SBC,scalar,SBC_scalar}.nc
  493. fi # ! $leg_is_restart
  494. #--------------------------------------------------------------------------
  495. # *** Surface restoring and ocean nudging options
  496. #--------------------------------------------------------------------------
  497. #for ocean_nudging
  498. if $(has_config nemo:ocenudg) ; then
  499. ln -fs ${ini_data_dir}/nemo/oce_nudg/temp_sal_*.nc ./
  500. fi
  501. #for surface restoring
  502. if $(has_config nemo:surfresto) ; then
  503. ln -fs ${ini_data_dir}/nemo/surface_restoring/sss_restore_data*.nc ./
  504. ln -fs ${ini_data_dir}/nemo/surface_restoring/sst_restore_data*.nc ./
  505. ln -fs ${ini_data_dir}/nemo/surface_restoring/mask_restore*.nc ./
  506. fi
  507. # -------------------------------------------------------------------------
  508. # *** Remove land grid-points
  509. # -------------------------------------------------------------------------
  510. if $(has_config nemo:elpin)
  511. then
  512. if [ ! -f coordinates_xios.nc ]
  513. then
  514. error "ELpIN requested, but file 'coordinates_xios.nc' was not found"
  515. fi
  516. jpns=($(${ecearth_src_dir}/util/ELPiN/ELPiNv2.cmd ${nem_numproc}))
  517. info "nemo domain decompostion from ELpIN: ${jpns[@]}"
  518. nem_numproc=${jpns[0]}
  519. nem_jpni=${jpns[1]}
  520. nem_jpnj=${jpns[2]}
  521. else
  522. info "nemo original domain decomposition (not using ELPiN)"
  523. fi
  524. # -------------------------------------------------------------------------
  525. # *** Initial conditions saved during the run
  526. # -------------------------------------------------------------------------
  527. ${do_save_ic} && save_ic_prepare_output
  528. # -------------------------------------------------------------------------
  529. # *** Create some control files
  530. # -------------------------------------------------------------------------
  531. # IFS frequency output for namelist
  532. if [ -f postins/pptdddddd0300 ]
  533. then
  534. ifs_output_freq=$(( 3 * 3600 / ifs_time_step_sec ))
  535. elif [ -f postins/pptdddddd0600 ]
  536. then
  537. ifs_output_freq=$(( 6 * 3600 / ifs_time_step_sec ))
  538. else
  539. error "IFS output frequency undefined."
  540. fi
  541. # IFS, NEMO, LIM namelist and OASIS namcouple files
  542. . ${ctrl_file_dir}/namelist.ifs.sh > fort.4
  543. . ${ctrl_file_dir}/namelist.nemo.ref.sh > namelist_ref
  544. . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-coupled.cfg.sh > namelist_cfg
  545. . ${ctrl_file_dir}/namelist.lim3.ref.sh > namelist_ice_ref
  546. . ${ctrl_file_dir}/namelist.lim3-${nem_grid}.cfg.sh > namelist_ice_cfg
  547. . ${ctrl_file_dir}/namelist.runoffmapper.sh > namelist.runoffmapper
  548. . ${ctrl_file_dir}/namcouple.sh > namcouple
  549. # -------------------------------------------------------------------------
  550. # *** Create ICMCL file with vegetation fields
  551. # -------------------------------------------------------------------------
  552. tempfile=tmp.$$
  553. case ${ifs_veg_source} in
  554. "ifs" )
  555. # Vegetation from IFS (climatology)
  556. icmclfile=${ini_data_dir}/ifs/${ifs_grid}/climate/ICMCL_ONLY_VEG_PD
  557. # Create data for december, the year before the leg starts
  558. ${grib_set} \
  559. -s dataDate=$(printf "%04d" $((leg_start_date_yyyy-1)))1215 \
  560. ${icmclfile}-12 ICMCL${exp_name}INIT
  561. # Create data for all month in the years of the leg
  562. for (( y=${leg_start_date_yyyy} ; y<=${leg_end_date_yyyy} ; y++ ))
  563. do
  564. yy=$(printf "%04d" $y)
  565. for m in {1..12}
  566. do
  567. mm=$(printf "%02d" $m)
  568. ${grib_set} -s dataDate=${yy}${mm}15 ${icmclfile}-${mm} ${tempfile}
  569. cat ${tempfile} >> ICMCL${exp_name}INIT
  570. done
  571. done
  572. # Create data for january, the year after the leg ends
  573. ${grib_set} \
  574. -s dataDate=$(printf "%04d" $((leg_end_date_yyyy+1)))0115 \
  575. ${icmclfile}-01 ${tempfile}
  576. cat ${tempfile} >> ICMCL${exp_name}INIT
  577. ;;
  578. "era20c" )
  579. # Vegetation from an off-line LPJG run forced with ERA20C (v16)
  580. rm -f ICMCL${exp_name}INIT
  581. # Create data for all years of the leg, including one year
  582. # before and one year after
  583. for (( yr=leg_start_date_yyyy-1 ; yr<=leg_end_date_yyyy+1 ; yr+=1 ))
  584. do
  585. if [ $ifs_cmip_fixyear -le 0 ]
  586. then
  587. cat ${ini_data_dir}/ifs/${ifs_grid}/icmcl_v16/icmcl_$yr.grb >> ICMCL${exp_name}INIT
  588. else
  589. # Fixed year forcing, requires cdo!
  590. # If cdo is not available at runtime you need to fix proper
  591. # icmcl files beforehand and use them here
  592. ${cdo} setyear,$yr ${ini_data_dir}/ifs/${ifs_grid}/icmcl_v16/icmcl_${ifs_cmip_fixyear}.grb ${tempfile}
  593. cat ${tempfile} >> ICMCL${exp_name}INIT
  594. fi
  595. done
  596. ;;
  597. * )
  598. error "Vegetation from ${ifs_veg_source} not implemented"
  599. ;;
  600. esac
  601. # Clean up
  602. rm -f ${tempfile}
  603. # -------------------------------------------------------------------------
  604. # *** Link the appropriate NEMO restart files of the previous leg
  605. # -------------------------------------------------------------------------
  606. if $leg_is_restart
  607. then
  608. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  609. for (( n=0 ; n<nem_numproc ; n++ ))
  610. do
  611. np=$(printf %04d ${n})
  612. ln -fs ${exp_name}_${ns}_restart_oce_${np}.nc restart_oce_${np}.nc
  613. ln -fs ${exp_name}_${ns}_restart_ice_${np}.nc restart_ice_${np}.nc
  614. done
  615. # Make sure there are no global restart files
  616. # If links are found, they will be removed. We are cautious and do
  617. # _not_ remove real files! However, if real global restart files are
  618. # present, NEMO/LIM will stop because time stamps will not match.
  619. [ -h restart_oce.nc ] && rm restart_oce.nc
  620. [ -h restart_ice.nc ] && rm restart_ice.nc
  621. fi
  622. # -------------------------------------------------------------------------
  623. # *** Remove some OASIS files of the previous leg
  624. # -------------------------------------------------------------------------
  625. if $leg_is_restart
  626. then
  627. rm -f anaisout_*
  628. fi
  629. # -------------------------------------------------------------------------
  630. # *** Start the run
  631. # -------------------------------------------------------------------------
  632. export DR_HOOK_IGNORE_SIGNALS='-1'
  633. export CPLNG='active'
  634. # Use the launch function from the platform configuration file
  635. t1=$(date +%s)
  636. launch \
  637. ${xio_numproc} ${xio_exe_file} -- \
  638. ${nem_numproc} ${nem_exe_file} -- \
  639. ${rnf_numproc} ${rnf_exe_file} -- \
  640. ${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name}
  641. t2=$(date +%s)
  642. tr=$(date -u -d "0 -$t1 sec + $t2 sec" +%T)
  643. # -------------------------------------------------------------------------
  644. # *** Check for signs of success
  645. # Note the tests provide no guarantee that things went fine! They are
  646. # just based on the IFS and NEMO log files. More tests (e.g. checking
  647. # restart files) could be implemented.
  648. # -------------------------------------------------------------------------
  649. # Checking for IFS success
  650. if [ -f ifs.stat ]
  651. then
  652. if [ "$(awk 'END{print $3}' ifs.stat)" == "CNT0" ]
  653. then
  654. info "Leg successfully completed according to IFS log file 'ifs.stat'."
  655. else
  656. error "Leg not completed according to IFS log file 'ifs.stat'."
  657. fi
  658. else
  659. error "IFS log file 'ifs.stat' not found after run."
  660. fi
  661. # Check for NEMO success
  662. if [ -f ocean.output ]
  663. then
  664. 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)" ]
  665. then
  666. info "Leg successfully completed according to NEMO log file 'ocean.output'."
  667. else
  668. error "Leg not completed according to NEMO log file 'ocean.output'."
  669. fi
  670. else
  671. error "NEMO log file 'ocean.output' not found after run."
  672. fi
  673. # -------------------------------------------------------------------------
  674. # *** Post-process initial conditions saved during the run if requested
  675. # -------------------------------------------------------------------------
  676. ${do_save_ic} && save_ic_postproc
  677. # -------------------------------------------------------------------------
  678. # *** Move IFS output files to archive directory
  679. # -------------------------------------------------------------------------
  680. outdir="${archive_dir}/output/ifs/$(printf %03d $((leg_number)))"
  681. mkdir -p ${outdir}
  682. prv_leg=$(printf %03d $((leg_number-1)))
  683. # This takes care of a special IFS feature: The output for the last time
  684. # step of each leg is written at the first time step of the new leg. The
  685. # following code makes sure that the output is appended to the appropriate
  686. # file. Since GRIB files are just streams, its done with a simple cat
  687. # command.
  688. for f in ICMSH${exp_name}+?????? ICMGG${exp_name}+??????
  689. do
  690. if [ -f output/ifs/${prv_leg}/${f} ]
  691. then
  692. cat ${f} >> output/ifs/${prv_leg}/${f}
  693. rm -f ${f}
  694. else
  695. mv ${f} ${outdir}
  696. fi
  697. done
  698. # -------------------------------------------------------------------------
  699. # *** Move NEMO output files to archive directory
  700. # -------------------------------------------------------------------------
  701. outdir="${archive_dir}/output/nemo/$(printf %03d $((leg_number)))"
  702. mkdir -p ${outdir}
  703. for v in grid_U grid_V grid_W grid_T icemod SBC scalar SBC_scalar diad_T \
  704. grid_T_2D grid_U_2D grid_V_2D grid_W_2D grid_T_3D grid_U_3D grid_V_3D grid_W_3D \
  705. grid_1point grid_T_3D_ncatice vert_sum \
  706. grid_ptr_W_3basin_3D grid_ptr_T_3basin_2D grid_ptr_T_2D \
  707. zoom_700_sum zoom_300_sum zoom_2000_sum
  708. do
  709. for f in ${exp_name}_*_????????_????????_*${v}.nc
  710. do
  711. test -f $f && mv $f $outdir/
  712. done
  713. done
  714. # -------------------------------------------------------------------------
  715. # *** Move IFS restart files to archive directory
  716. # -------------------------------------------------------------------------
  717. if $leg_is_restart
  718. then
  719. outdir="${archive_dir}/restart/ifs/$(printf %03d $((leg_number)))"
  720. mkdir -p ${outdir}
  721. # Figure out the time part of the restart files (cf. CTIME on rcf files)
  722. # NOTE: Assuming that restarts are at full days (time=0000) only!
  723. nd="$(printf %06d $((leg_start_sec/(24*3600))))0000"
  724. mv srf${nd}.???? ${outdir}
  725. fi
  726. # -------------------------------------------------------------------------
  727. # *** Move NEMO restart files to archive directory
  728. # -------------------------------------------------------------------------
  729. if $leg_is_restart
  730. then
  731. outdir="${archive_dir}/restart/nemo/$(printf %03d $((leg_number)))"
  732. mkdir -p ${outdir}
  733. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  734. for f in oce ice
  735. do
  736. mv ${exp_name}_${ns}_restart_${f}_????.nc ${outdir}
  737. done
  738. fi
  739. # -------------------------------------------------------------------------
  740. # *** Copy OASIS restart files to archive directory
  741. # NOTE: These files are copied and not moved as they are used in the
  742. # next leg!
  743. # Note also that the OASIS restart files present at the end of
  744. # the leg correspond to the start of the next leg!
  745. # -------------------------------------------------------------------------
  746. outdir="${archive_dir}/restart/oasis/$(printf %03d $((leg_number+1)))"
  747. mkdir -p ${outdir}
  748. for f in ${oas_rst_files}
  749. do
  750. test -f ${f} && cp ${f} ${outdir}
  751. done
  752. # -------------------------------------------------------------------------
  753. # *** Copy rcf files to the archive directory (of the next leg!)
  754. # -------------------------------------------------------------------------
  755. outdir="${archive_dir}/restart/ifs/$(printf %03d $((leg_number+1)))"
  756. mkdir -p ${outdir}
  757. for f in rcf
  758. do
  759. test -f ${f} && cp ${f} ${outdir}
  760. done
  761. # -------------------------------------------------------------------------
  762. # *** Move log files to archive directory
  763. # -------------------------------------------------------------------------
  764. outdir="${archive_dir}/log/$(printf %03d $((leg_number)))"
  765. mkdir -p ${outdir}
  766. for f in \
  767. ifs.log ifs.stat fort.4 ocean.output \
  768. time.step solver.stat \
  769. nout.000000 debug.??.?????? A*_??.nc O*_??.nc
  770. do
  771. test -f ${f} && mv ${f} ${outdir}
  772. done
  773. # -------------------------------------------------------------------------
  774. # *** Write the restart control file
  775. # -------------------------------------------------------------------------
  776. # Compute CPMIP performance
  777. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  778. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1)) $(($ifs_numproc + $nem_numproc + $rnf_numproc + $xio_numproc)))"
  779. echo "#" | tee -a ${ece_info_file}
  780. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  781. | tee -a ${ece_info_file}
  782. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  783. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  784. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  785. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  786. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  787. force_run_from_scratch=false
  788. special_restart=false
  789. done # loop over legs
  790. # -----------------------------------------------------------------------------
  791. # *** Platform dependent finalising of the run
  792. # -----------------------------------------------------------------------------
  793. finalise
  794. exit 0