ece-ifs+nemo.sh.tmpl 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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. # Coupling frequency between atmosphere and ocean (in seconds)
  34. cpl_freq_atm_oce_sec=[[[MOD:OASIS:CPL_FREQ_ATM_OCE_SEC]]]
  35. # Directories
  36. #start_dir=${PWD}
  37. ctrl_file_dir=${start_dir}/ctrl
  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. # -----------------------------------------------------------------------------
  48. # *** Time step settings
  49. # -----------------------------------------------------------------------------
  50. case "${ifs_grid}--${nem_grid}" in
  51. T255L*--ORCA1L*)
  52. ifs_time_step_sec=2700; nem_time_step_sec=2700; lim_time_step_sec=2700; cpl_freq_atm_oce_sec=2700
  53. ;;
  54. T511L*--ORCA025L*)
  55. ifs_time_step_sec=900 ; nem_time_step_sec=900 ; lim_time_step_sec=900 ; cpl_freq_atm_oce_sec=2700
  56. ;;
  57. *) error "Can't set time steps for unknown combination of horizontal grids: ${ifs_grid}-${nem_grid}"
  58. ;;
  59. esac
  60. # -----------------------------------------------------------------------------
  61. # *** IFS configuration
  62. # -----------------------------------------------------------------------------
  63. ifs_version=36r4
  64. ifs_output_freq=$(( 6 * 3600 / ifs_time_step_sec ))
  65. ifs_di_freq=$(( 24 * 3600 / ifs_time_step_sec ))
  66. ifs_ddh_freq=$(( 120 * 3600 / ifs_time_step_sec ))
  67. ifs_res_hor=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\1:')
  68. ifs_res_ver=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\2:')
  69. ifs_numproc=[[[MOD:IFS:NUMPROC]]]
  70. ifs_exe_file=${ecearth_src_dir}/ifs-${ifs_version}/bin/ifsmaster-${build_arch}
  71. ifs_lastout=false
  72. ifs_cmip5=[[[MOD:IFS:CMIP5]]]
  73. ifs_cmip5_rcp=[[[MOD:IFS:CMIP5_RCP]]]
  74. ifs_cmip_fixyear=[[[MOD:IFS:CMIP_FIXYEAR]]]
  75. ifs_mac2sp=[[[MOD:IFS:MAC2SP]]]
  76. ifs_cmip6piaer=[[[MOD:IFS:CMIP6PIAER]]]
  77. ifs_cmip6=[[[MOD:IFS:CMIP6]]]
  78. lcmip6_strataer_simp=FALSE
  79. lcmip6_strataer_full=[[[MOD:IFS:CMIP6]]]
  80. lcmip6_strataer_bckgd=FALSE
  81. ifs_A4xCO2=[[[MOD:IFS:CMIP6_A4xCO2]]]
  82. ifs_1PCTCO2=[[[MOD:IFS:CMIP6_1PCTCO2]]]
  83. # Time-varying orbital forcing (Qiong Zhang, SU-2013-09)
  84. # https://dev.ec-earth.org/projects/ecearth3/wiki/Orbital_forcing_in_EC-Earth_3
  85. #
  86. # ifs_orb_switch=FALSE, no orbital calculations applied
  87. # ifs_orb_switch=TRUE, use orbital calculations according to ifs_orb_mode
  88. # ifs_orb_mode="fixed_year", or "variable_year", or "fixed_parameters"
  89. # fixed_year: calculate the orbital parameters at ifs_orb_iyear, e.g.,1850
  90. # variable_year: calculate orbital parameters annually start from ifs_orb_iyear
  91. # fixed_parameters: prescribe orbital parameters for given year
  92. ifs_orb_switch=FALSE
  93. ifs_orb_mode="variable_year"
  94. ifs_orb_iyear=$(date -u -d "${run_start_date}" +%Y)
  95. # *** IFS tuning (the commented values are EC-Earth 3.2beta and IFS cy36r4)
  96. # Default based on the v16 LPJG vegetation dataset discussed in #449-197 (jcn4)
  97. # The default values are WITH 2nd indirect effect NCLOUDACT=2, NAERCLD=9
  98. # jvg6 is the best alternative configuration found in #449 with NCLOUDACT=0
  99. # jvg6 ECE32b IFS cy36r4
  100. RPRCON=1.34E-3 # 1.52e-4 1.2E-3 1.4E-3
  101. RVICE=0.137 # 0.126 0.13 0.15
  102. RLCRITSNOW=4.0E-5 # 4.2e-5 3.0E-5 5.0E-5
  103. RSNOWLIN2=0.035 # 0.035 0.035 0.025
  104. ENTRORG=1.70E-4 # 1.58e-4 1.5E-4 1.8E-4
  105. DETRPEN=0.75E-4 # 0.75e-4 0.75E-4 0.75E-4
  106. ENTRDD=3.0E-4 # 3.5e-4 3.0E-4 2.0E-4
  107. RMFDEPS=0.3 # 0.27 0.3 0.35
  108. RCLDIFF=3.E-6 # 3.6e-6 3.E-6
  109. RCLDIFFC=5.0 # 5.0
  110. RLCRIT_UPHYS=0.875e-5
  111. # Select source of vegetation data:
  112. # ifs climatology from IFS
  113. # era20c vegetation from an off-line LPJ-Guess run forced with ERA20C
  114. # (currently available only for T255 and T159)
  115. #
  116. ifs_veg_source="era20c"
  117. case ${ifs_veg_source} in
  118. "ifs" )
  119. # Use Lambert-Beer to compute effective vegetation cover
  120. n_compute_eff_veg_fraction=2
  121. ;;
  122. "era20c" )
  123. # LPJG vegetation is provided as effective cover
  124. # Don't use Lambert-Beer
  125. n_compute_eff_veg_fraction=0
  126. ;;
  127. * )
  128. error "Vegetation from ${ifs_veg_source} not implemented"
  129. ;;
  130. esac
  131. # -----------------------------------------------------------------------------
  132. # *** NEMO/LIM configuration
  133. # -----------------------------------------------------------------------------
  134. # This is only needed if the experiment is started from an existing set of NEMO
  135. # restart files
  136. nem_restart_file_path=${start_dir}/nemo-rst
  137. nem_restart_offset=0
  138. nem_res_hor=$(echo ${nem_grid} | sed 's:ORCA\([0-9]\+\)L[0-9]\+:\1:')
  139. nem_exe_file=${ecearth_src_dir}/nemo-3.6/CONFIG/${nem_grid}_LIM3/BLD/bin/nemo.exe
  140. nem_numproc=[[[MOD:NEM:NUMPROC]]]
  141. # -----------------------------------------------------------------------------
  142. # *** Runoff mapper configuration
  143. # -----------------------------------------------------------------------------
  144. rnf_exe_file=${ecearth_src_dir}/runoff-mapper/bin/runoff-mapper.exe
  145. rnf_numproc=1
  146. # -----------------------------------------------------------------------------
  147. # *** OASIS configuration
  148. # -----------------------------------------------------------------------------
  149. # Restart files for the coupling fields (note 8 character limit in OASIS)
  150. # rstas.nc : atmoshpere single-category fields
  151. # rstam.nc : atmoshpere multi-category fields
  152. # rstos.nc : ocean single-category fields
  153. # rstom.nc : ocean multi-category fields
  154. oas_rst_files="rstas.nc rstos.nc"
  155. # Decide whether the OASIS weight files for interpolation should be linked from
  156. # the setup directory (true) or not (false). In the latter case, the weights
  157. # are re-computed at the start of the run.
  158. oas_link_weights=true
  159. # Flux correction for runoff (not calving) sent from Oasis to ocean.
  160. # 1.07945 is computed to compensate for a P-E=-0.016 mm/day
  161. oas_mb_fluxcorr=1.07945
  162. # -----------------------------------------------------------------------------
  163. # *** XIOS configuration
  164. # -----------------------------------------------------------------------------
  165. xio_exe_file=${ecearth_src_dir}/xios-2/bin/xios_server.exe
  166. xio_numproc=[[[MOD:XIO:NUMPROC]]]
  167. # -----------------------------------------------------------------------------
  168. # *** Extra initial conditions saved during the run
  169. # -----------------------------------------------------------------------------
  170. if has_config save_ic
  171. then
  172. source ./libsave_ic.sh
  173. declare -a save_ic_date save_ic_date1 save_ic_sec save_ic_day save_ic_ppt_file save_ic_nemo_ts
  174. fi
  175. # =============================================================================
  176. # *** END of User configuration
  177. # =============================================================================
  178. # =============================================================================
  179. # *** This is where the code begins ...
  180. # =============================================================================
  181. # -----------------------------------------------------------------------------
  182. # *** Create the run dir if necessary and go there
  183. # Everything is done from here.
  184. # -----------------------------------------------------------------------------
  185. if [ ! -d ${run_dir} ]
  186. then
  187. mkdir -p ${run_dir}
  188. if $special_restart
  189. then
  190. force_run_from_scratch=false
  191. 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}
  192. cp -f ${nem_exe_file} ${run_dir}
  193. cp -f ${ifs_exe_file} ${run_dir}
  194. cp -f ${rnf_exe_file} ${run_dir}
  195. cp -f ${xio_exe_file} ${run_dir}
  196. special_year=${special_restart_date:0:4}
  197. sed -i "/$special_year/q" ${run_dir}/ece.info
  198. . ${run_dir}/ece.info
  199. special_restart_leg=$(printf %03d $((leg_number+1)))
  200. # PUT HERE THE INSTRUCTIONS TO COPY THE restart files
  201. rsync -av ${run_dir}/../${special_restart_from}/restart/ifs/${special_restart_leg}/ ${run_dir}
  202. rsync -av ${run_dir}/../${special_restart_from}/restart/oasis/${special_restart_leg}/ ${run_dir}
  203. cd ${run_dir}/../${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 -d "${leg_end_date}" +%s) -gt $(date -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 -d "${leg_end_date}" +%s) - $(date -d "${leg_start_date}" +%s) ))
  264. leg_start_sec=$(( $(date -d "${leg_start_date}" +%s) - $(date -d "${run_start_date}" +%s) ))
  265. leg_end_sec=$(( $(date -d "${leg_end_date}" +%s) - $(date -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}/ICMGGECE3INIT \
  321. ICMGG${exp_name}INIT
  322. ln -s \
  323. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMSHECE3INIT \
  324. ICMSH${exp_name}INIT
  325. # Other stuff
  326. ln -s ${ini_data_dir}/ifs/rtables/* .
  327. # Output control (ppt files)
  328. mkdir postins
  329. cp ${ctrl_file_dir}/ppt* postins/
  330. f_min=$(( ifs_output_freq * ifs_time_step_sec / 60 ))
  331. for t in $(seq $f_min $f_min 1439)
  332. do
  333. hh=$(printf %02d $((t/60)) )
  334. mm=$(printf %02d $((t%60)) )
  335. ln -s pptdddddd0000 postins/pptdddddd$hh$mm
  336. done
  337. /bin/ls -1 postins/* > dirlist
  338. # ---------------------------------------------------------------------
  339. # *** Files needed for NEMO (linked)
  340. # ---------------------------------------------------------------------
  341. # Link initialisation files for matching ORCA grid
  342. for f in \
  343. bathy_meter.nc coordinates.nc \
  344. ahmcoef.nc \
  345. K1rowdrg.nc M2rowdrg.nc mask_itf.nc \
  346. decay_scale_bot.nc decay_scale_cri.nc \
  347. mixing_power_bot.nc mixing_power_cri.nc mixing_power_pyc.nc \
  348. runoff_depth.nc
  349. do
  350. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && ln -s ${ini_data_dir}/nemo/initial/${nem_grid}/$f
  351. done
  352. # Link geothermal heating file (independent of grid) and matching weight file
  353. ln -s ${ini_data_dir}/nemo/initial/Goutorbe_ghflux.nc
  354. ln -s ${ini_data_dir}/nemo/initial/weights_Goutorbe1_2_orca${nem_res_hor}_bilinear.nc
  355. # Link either restart files or climatology files for the initial state
  356. if $(has_config nemo:start_from_restart)
  357. then
  358. # When linking restart files, we accept three options:
  359. # (1) Merged files for ocean and ice, i.e.
  360. # restart_oce.nc and restart_ice.nc
  361. # (2) One-file-per-MPI-rank, i.e.
  362. # restart_oce_????.nc and restart_ice_????.nc
  363. # No check is done whether the number of restart files agrees
  364. # with the number of MPI ranks for NEMO!
  365. # (3) One-file-per-MPI-rank with a prefix, i.e.
  366. # <exp_name>_<time_step>_restart_oce_????.nc (similar for the ice)
  367. # The prefix is ignored.
  368. # The code assumes that one of the options can be applied! If more
  369. # options are applicable, the first is chosen. If none of the
  370. # options apply, NEMO will crash with missing restart file.
  371. if ls -U ${nem_restart_file_path}/restart_[oi]ce.nc > /dev/null 2>&1
  372. then
  373. ln -s ${nem_restart_file_path}/restart_[oi]ce.nc ./
  374. elif ls -U ${nem_restart_file_path}/restart_[oi]ce_????.nc > /dev/null 2>&1
  375. then
  376. ln -s ${nem_restart_file_path}/restart_[oi]ce_????.nc ./
  377. else
  378. for f in ${nem_restart_file_path}/????_????????_restart_[oi]ce_????.nc
  379. do
  380. ln -s $f $(echo $f | sed 's/.*_\(restart_[oi]ce_....\.nc\)/\1/')
  381. done
  382. fi
  383. else
  384. # Temperature and salinity files for initialisation
  385. ln -s ${ini_data_dir}/nemo/climatology/absolute_salinity_WOA13_decav_Reg1L75_clim.nc
  386. ln -s ${ini_data_dir}/nemo/climatology/conservative_temperature_WOA13_decav_Reg1L75_clim.nc
  387. ln -s ${ini_data_dir}/nemo/climatology/weights_WOA13d1_2_orca${nem_res_hor}_bilinear.nc
  388. # Grid dependent runoff files
  389. case ${nem_grid} in
  390. ORCA1*) ln -s ${ini_data_dir}/nemo/climatology/runoff-icb_DaiTrenberth_Depoorter_ORCA1_JD.nc ;;
  391. ORCA025*) ln -s ${ini_data_dir}/nemo/climatology/ORCA_R025_runoff_v1.1.nc ;;
  392. esac
  393. fi
  394. # XIOS files
  395. . ${ctrl_file_dir}/iodef.xml.sh > iodef.xml
  396. ln -s ${ctrl_file_dir}/context_nemo.xml
  397. ln -s ${ctrl_file_dir}/domain_def_nemo.xml
  398. ln -s ${ctrl_file_dir}/axis_def_nemo.xml
  399. ln -s ${ctrl_file_dir}/grids_def_nemo.xml
  400. ln -s ${ctrl_file_dir}/field_def_nemo-lim.xml
  401. ln -s ${ctrl_file_dir}/field_def_nemo-opa.xml
  402. ln -s ${ctrl_file_dir}/field_def_nemo-pisces.xml
  403. ln -s ${ctrl_file_dir}/field_def_nemo-inerttrc.xml
  404. ln -s ${ctrl_file_dir}/file_def_nemo-lim3.xml file_def_nemo-lim.xml
  405. ln -s ${ctrl_file_dir}/file_def_nemo-opa.xml
  406. ln -s ${ctrl_file_dir}/file_def_nemo-pisces.xml
  407. # ---------------------------------------------------------------------
  408. # *** Files needed for the Runoff mapper (linked)
  409. # ---------------------------------------------------------------------
  410. ln -s ${ini_data_dir}/runoff-mapper/runoff_maps.nc
  411. # ---------------------------------------------------------------------
  412. # *** Files needed for OASIS (linked)
  413. # ---------------------------------------------------------------------
  414. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-ORCA${nem_res_hor}
  415. # Name table file
  416. ln -s ${ini_data_dir}/oasis/cf_name_table.txt
  417. # Grid definition files
  418. ln -s ${oas_grid_dir}/areas.nc
  419. ln -s ${oas_grid_dir}/grids.nc
  420. ln -s ${oas_grid_dir}/masks.nc
  421. # Weight files
  422. case ${ifs_res_hor} in
  423. 159) oas_agrd=080
  424. ;;
  425. 255) oas_agrd=128
  426. ;;
  427. 511) oas_agrd=256
  428. ;;
  429. 799) oas_agrd=400
  430. ;;
  431. *) error "Unsupported horizontal resolution (IFS): ${ifs_res_hor}"
  432. ;;
  433. esac
  434. case ${nem_res_hor} in
  435. 1) oas_ogrd=O1t0
  436. ;;
  437. 025) oas_ogrd=Ot25
  438. ;;
  439. *) error "Unsupported horizontal resolution (NEMO): ${nem_res_hor}"
  440. ;;
  441. esac
  442. if ${oas_link_weights}
  443. then
  444. for f in ${oas_grid_dir}/rmp_????_to_????_GAUSWGT.nc
  445. do
  446. ln -s $f
  447. done
  448. fi
  449. for f in ${oas_rst_files}
  450. do
  451. cp ${oas_grid_dir}/rst/$f .
  452. done
  453. else # i.e. $leg_is_restart == true
  454. # ---------------------------------------------------------------------
  455. # *** Remove all leftover output files from previous legs
  456. # ---------------------------------------------------------------------
  457. # IFS files
  458. rm -f ICM{SH,GG}${exp_name}+??????
  459. # NEMO files
  460. rm -f ${exp_name}_??_????????_????????_{grid_U,grid_V,grid_W,grid_T,icemod,SBC,scalar,SBC_scalar}.nc
  461. fi # ! $leg_is_restart
  462. # -------------------------------------------------------------------------
  463. # *** Remove land grid-points
  464. # -------------------------------------------------------------------------
  465. if $(has_config nemo:elpin)
  466. then
  467. jpns=($(${ecearth_src_dir}/util/ELPiN/ELPiNv2.cmd ${nem_numproc}))
  468. info "nemo domain decompostion from ELpIN: ${jpns[@]}"
  469. nem_numproc=${jpns[0]}
  470. nem_jpni=${jpns[1]}
  471. nem_jpnj=${jpns[2]}
  472. else
  473. info "nemo original domain decomposition (not using ELPiN)"
  474. fi
  475. # -------------------------------------------------------------------------
  476. # *** Initial conditions saved during the run
  477. # -------------------------------------------------------------------------
  478. ${do_save_ic} && save_ic_prepare_output
  479. # -------------------------------------------------------------------------
  480. # *** Create some control files
  481. # -------------------------------------------------------------------------
  482. # IFS, NEMO, LIM namelist and OASIS namcouple files
  483. . ${ctrl_file_dir}/namelist.ifs.sh > fort.4
  484. . ${ctrl_file_dir}/namelist.nemo.ref.sh > namelist_ref
  485. . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-coupled.cfg.sh > namelist_cfg
  486. . ${ctrl_file_dir}/namelist.lim3.ref.sh > namelist_ice_ref
  487. . ${ctrl_file_dir}/namelist.lim3-${nem_grid}.cfg.sh > namelist_ice_cfg
  488. . ${ctrl_file_dir}/namelist.runoffmapper.sh > namelist.runoffmapper
  489. . ${ctrl_file_dir}/namcouple.sh > namcouple
  490. # -------------------------------------------------------------------------
  491. # *** Create ICMCL file with vegetation fields
  492. # -------------------------------------------------------------------------
  493. tempfile=tmp.$$
  494. case ${ifs_veg_source} in
  495. "ifs" )
  496. # Vegetation from IFS (climatology)
  497. icmclfile=${ini_data_dir}/ifs/${ifs_grid}/climate/ICMCL_ONLY_VEG_PD
  498. # Create data for december, the year before the leg starts
  499. ${grib_set} \
  500. -s dataDate=$(printf "%04d" $((leg_start_date_yyyy-1)))1215 \
  501. ${icmclfile}-12 ICMCL${exp_name}INIT
  502. # Create data for all month in the years of the leg
  503. for (( y=${leg_start_date_yyyy} ; y<=${leg_end_date_yyyy} ; y++ ))
  504. do
  505. yy=$(printf "%04d" $y)
  506. for m in {1..12}
  507. do
  508. mm=$(printf "%02d" $m)
  509. ${grib_set} -s dataDate=${yy}${mm}15 ${icmclfile}-${mm} ${tempfile}
  510. cat ${tempfile} >> ICMCL${exp_name}INIT
  511. done
  512. done
  513. # Create data for january, the year after the leg ends
  514. ${grib_set} \
  515. -s dataDate=$(printf "%04d" $((leg_end_date_yyyy+1)))0115 \
  516. ${icmclfile}-01 ${tempfile}
  517. cat ${tempfile} >> ICMCL${exp_name}INIT
  518. ;;
  519. "era20c" )
  520. # Vegetation from an off-line LPJG run forced with ERA20C (v16)
  521. rm -f ICMCL${exp_name}INIT
  522. # Create data for all years of the leg, including one year
  523. # before and one year after
  524. for (( yr=leg_start_date_yyyy-1 ; yr<=leg_end_date_yyyy+1 ; yr+=1 ))
  525. do
  526. if [ $ifs_cmip_fixyear -le 0 ]
  527. then
  528. cat ${ini_data_dir}/ifs/${ifs_grid}/icmcl_v16/icmcl_$yr.grb >> ICMCL${exp_name}INIT
  529. else
  530. # Fixed year forcing, requires cdo!
  531. # If cdo is not available at runtime you need to fix proper
  532. # icmcl files beforehand and use them here
  533. cdo setyear,$yr ${ini_data_dir}/ifs/${ifs_grid}/icmcl_v16/icmcl_${ifs_cmip_fixyear}.grb ${tempfile}
  534. cat ${tempfile} >> ICMCL${exp_name}INIT
  535. fi
  536. done
  537. ;;
  538. * )
  539. error "Vegetation from ${ifs_veg_source} not implemented"
  540. ;;
  541. esac
  542. # Clean up
  543. rm -f ${tempfile}
  544. # -------------------------------------------------------------------------
  545. # *** Link the appropriate NEMO restart files of the previous leg
  546. # -------------------------------------------------------------------------
  547. if $leg_is_restart
  548. then
  549. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  550. for (( n=0 ; n<nem_numproc ; n++ ))
  551. do
  552. np=$(printf %04d ${n})
  553. ln -fs ${exp_name}_${ns}_restart_oce_${np}.nc restart_oce_${np}.nc
  554. ln -fs ${exp_name}_${ns}_restart_ice_${np}.nc restart_ice_${np}.nc
  555. done
  556. # Make sure there are no global restart files
  557. # If links are found, they will be removed. We are cautious and do
  558. # _not_ remove real files! However, if real global restart files are
  559. # present, NEMO/LIM will stop because time stamps will not match.
  560. [ -h restart_oce.nc ] && rm restart_oce.nc
  561. [ -h restart_ice.nc ] && rm restart_ice.nc
  562. fi
  563. # -------------------------------------------------------------------------
  564. # *** Remove some OASIS files of the previous leg
  565. # -------------------------------------------------------------------------
  566. if $leg_is_restart
  567. then
  568. rm -f anaisout_*
  569. fi
  570. # -------------------------------------------------------------------------
  571. # *** Start the run
  572. # -------------------------------------------------------------------------
  573. export DR_HOOK_IGNORE_SIGNALS='-1'
  574. export CPLNG='active'
  575. # Use the launch function from the platform configuration file
  576. t1=$(date +%s)
  577. launch \
  578. ${xio_numproc} ${xio_exe_file} -- \
  579. ${nem_numproc} ${nem_exe_file} -- \
  580. ${rnf_numproc} ${rnf_exe_file} -- \
  581. ${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name}
  582. t2=$(date +%s)
  583. tr=$(date -d "0 -$t1 sec + $t2 sec" +%T)
  584. # -------------------------------------------------------------------------
  585. # *** Check for signs of success
  586. # Note the tests provide no guarantee that things went fine! They are
  587. # just based on the IFS and NEMO log files. More tests (e.g. checking
  588. # restart files) could be implemented.
  589. # -------------------------------------------------------------------------
  590. # Checking for IFS success
  591. if [ -f ifs.stat ]
  592. then
  593. if [ "$(awk 'END{print $3}' ifs.stat)" == "CNT0" ]
  594. then
  595. info "Leg successfully completed according to IFS log file 'ifs.stat'."
  596. else
  597. error "Leg not completed according to IFS log file 'ifs.stat'."
  598. fi
  599. else
  600. error "IFS log file 'ifs.stat' not found after run."
  601. fi
  602. # Check for NEMO success
  603. if [ -f ocean.output ]
  604. then
  605. if [ "$(awk '/New day/{d=$10}END{print d}' ocean.output)" == "$(date -d "${leg_end_date} - 1 day" +%Y/%m/%d)" ]
  606. then
  607. info "Leg successfully completed according to NEMO log file 'ocean.output'."
  608. else
  609. error "Leg not completed according to NEMO log file 'ocean.output'."
  610. fi
  611. else
  612. error "NEMO log file 'ocean.output' not found after run."
  613. fi
  614. # -------------------------------------------------------------------------
  615. # *** Move IFS output files to archive directory
  616. # -------------------------------------------------------------------------
  617. outdir="${archive_dir}/output/ifs/$(printf %03d $((leg_number)))"
  618. mkdir -p ${outdir}
  619. prv_leg=$(printf %03d $((leg_number-1)))
  620. # This takes care of a special IFS feature: The output for the last time
  621. # step of each leg is written at the first time step of the new leg. The
  622. # following code makes sure that the output is appended to the appropriate
  623. # file. Since GRIB files are just streams, its done with a simple cat
  624. # command.
  625. for f in ICMSH${exp_name}+?????? ICMGG${exp_name}+??????
  626. do
  627. if [ -f output/ifs/${prv_leg}/${f} ]
  628. then
  629. cat ${f} >> output/ifs/${prv_leg}/${f}
  630. rm -f ${f}
  631. else
  632. mv ${f} ${outdir}
  633. fi
  634. done
  635. # -------------------------------------------------------------------------
  636. # *** Move NEMO output files to archive directory
  637. # -------------------------------------------------------------------------
  638. outdir="${archive_dir}/output/nemo/$(printf %03d $((leg_number)))"
  639. mkdir -p ${outdir}
  640. for f in ${exp_name}_??_????????_????????_*.nc ; do mv $f $outdir/ ; done
  641. #for v in grid_U grid_V grid_W grid_T icemod SBC scalar SBC_scalar
  642. #do
  643. # for f in ${exp_name}_??_????????_????????_${v}.nc
  644. # do
  645. # test -f $f && mv $f $outdir/
  646. # done
  647. #done
  648. # -------------------------------------------------------------------------
  649. # *** Move IFS restart files to archive directory
  650. # -------------------------------------------------------------------------
  651. if $leg_is_restart
  652. then
  653. outdir="${archive_dir}/restart/ifs/$(printf %03d $((leg_number)))"
  654. mkdir -p ${outdir}
  655. # Figure out the time part of the restart files (cf. CTIME on rcf files)
  656. # NOTE: Assuming that restarts are at full days (time=0000) only!
  657. nd="$(printf %06d $((leg_start_sec/(24*3600))))0000"
  658. mv srf${nd}.???? ${outdir}
  659. fi
  660. # -------------------------------------------------------------------------
  661. # *** Move NEMO restart files to archive directory
  662. # -------------------------------------------------------------------------
  663. if $leg_is_restart
  664. then
  665. outdir="${archive_dir}/restart/nemo/$(printf %03d $((leg_number)))"
  666. mkdir -p ${outdir}
  667. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  668. for f in oce ice
  669. do
  670. mv ${exp_name}_${ns}_restart_${f}_????.nc ${outdir}
  671. done
  672. fi
  673. # -------------------------------------------------------------------------
  674. # *** Copy OASIS restart files to archive directory
  675. # NOTE: These files are copied and not moved as they are used in the
  676. # next leg!
  677. # Note also that the OASIS restart files present at the end of
  678. # the leg correspond to the start of the next leg!
  679. # -------------------------------------------------------------------------
  680. outdir="${archive_dir}/restart/oasis/$(printf %03d $((leg_number+1)))"
  681. mkdir -p ${outdir}
  682. for f in ${oas_rst_files}
  683. do
  684. test -f ${f} && cp ${f} ${outdir}
  685. done
  686. # -------------------------------------------------------------------------
  687. # *** Copy rcf files to the archive directory (of the next leg!)
  688. # -------------------------------------------------------------------------
  689. outdir="${archive_dir}/restart/ifs/$(printf %03d $((leg_number+1)))"
  690. mkdir -p ${outdir}
  691. for f in rcf
  692. do
  693. test -f ${f} && cp ${f} ${outdir}
  694. done
  695. # -------------------------------------------------------------------------
  696. # *** Move log files to archive directory
  697. # -------------------------------------------------------------------------
  698. outdir="${archive_dir}/log/$(printf %03d $((leg_number)))"
  699. mkdir -p ${outdir}
  700. for f in \
  701. ifs.log ifs.stat fort.4 ocean.output \
  702. time.step solver.stat \
  703. nout.000000 debug.??.?????? A*_??.nc O*_??.nc
  704. do
  705. test -f ${f} && mv ${f} ${outdir}
  706. done
  707. # -------------------------------------------------------------------------
  708. # *** Write the restart control file
  709. # -------------------------------------------------------------------------
  710. # Compute CPMIP performance
  711. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  712. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1)) $(($ifs_numproc + $nem_numproc + $rnf_numproc + $xio_numproc)))"
  713. echo "#" | tee -a ${ece_info_file}
  714. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  715. | tee -a ${ece_info_file}
  716. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  717. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  718. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  719. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  720. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  721. force_run_from_scratch=false
  722. special_restart=false
  723. done # loop over legs
  724. # -----------------------------------------------------------------------------
  725. # *** Platform dependent finalising of the run
  726. # -----------------------------------------------------------------------------
  727. finalise
  728. exit 0