ece-ifs+nemo.sh.tmpl 38 KB

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