ece-esm.sh.tmpl 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  1. #!/usr/bin/env bash
  2. set -ue
  3. # librunscript defines some helper functions
  4. source ./librunscript.sh
  5. # =============================================================================
  6. # *** BEGIN User configuration
  7. # =============================================================================
  8. # -----------------------------------------------------------------------------
  9. # *** General configuration
  10. # -----------------------------------------------------------------------------
  11. # Component configuration (for syntax of the $config variable, see librunscript.sh)
  12. #
  13. # Currently maintained:
  14. # config="ifs amip oasis" # "GCM forced-SST" : IFS + AMIP
  15. # config="ifs amip oasis lpjg:fdbck" # "Veg" : forced-GCM + LPJ-Guess
  16. # config="ifs amip oasis tm5:chem,o3fb,ch4fb,aerfb" # "AerChem" : forced-GCM + TM5
  17. #
  18. # config="ifs nemo lim3 rnfmapper xios:detached oasis" # "GCM" : IFS+NEMO
  19. # config="ifs nemo lim3 rnfmapper xios:detached oasis lpjg:fdbck" # "Veg" : GCM+LPJ-Guess
  20. # config="ifs nemo lim3 rnfmapper xios:detached oasis pisces lpjg:fdbck tm5:co2,co2fb" # "C-cycle" : GCM+LPJG+TM5
  21. # config="ifs nemo lim3 rnfmapper xios:detached oasis tm5:chem,o3fb,ch4fb,aerfb" # "AerChem" : GCM+TM5
  22. #
  23. # config="ifs nemo pisces lim3 rnfmapper xios:detached oasis" # "GCM" : IFS+NEMO+PISCES
  24. #
  25. config="ifs nemo lim3 rnfmapper xios:detached oasis lpjg:fdbck tm5:co2"
  26. # minimum sanity
  27. has_config amip nemo && error "Cannot have both nemo and amip in config!!"
  28. ! has_config ifs && error "The ESM script requires ifs in config"
  29. # Experiment name (exactly 4 letters!)
  30. export exp_name=[[[MOD:GENERAL:EXP_NAME]]]
  31. # Simulation start and end date. Use any (reasonable) syntax you want.
  32. run_start_date="[[[MOD:GENERAL:RUN_START_DATE]]]"
  33. run_end_date="[[[MOD:GENERAL:RUN_END_DATE]]]"
  34. # Set $force_run_from_scratch to 'true' if you want to force this run to start
  35. # from scratch, possibly ignoring any restart files present in the run
  36. # directory. Leave set to 'false' otherwise.
  37. # NOTE: If set to 'true' the run directory $run_dir is cleaned!
  38. force_run_from_scratch=[[[MOD:GENERAL:FORCE_RUN_FROM_SCRATCH]]]
  39. # Resolution (TM5 resolution is set at compilation)
  40. ifs_grid=[[[MOD:IFS:GRID]]]
  41. nem_grid=[[[MOD:NEM:GRID]]]
  42. # Restart frequency. Use any (reasonable) number and time unit you want.
  43. # For runs without restart, leave this variable empty
  44. rst_freq="[[[MOD:GENERAL:RST_FREQ]]]"
  45. # Number of restart legs to be run in one go
  46. run_num_legs=[[[MOD:GENERAL:RUN_NUM_LEGS]]]
  47. # Coupling frequencies
  48. has_config ifs tm5 && cpl_freq_atm_ctm_hrs=[[[MOD:OASIS:CPL_FREQ_ATM_CHE_HRS]]]
  49. has_config ifs lpjg && cpl_freq_atm_lpjg_hrs=[[[MOD:OASIS:CPL_FREQ_ATM_LPJG_HRS]]]
  50. # Don't change the coupling frequency because UPDCLIE (where SST and SIC
  51. # are updated) is called every 24 hours (hardcoded in ifs-36r4/src/ifs/utility/updtim.F90)
  52. has_config amip && cpl_freq_amip_sec=86400
  53. # Directories
  54. start_dir=${PWD}
  55. ctrl_file_dir=${start_dir}/ctrl
  56. output_control_files_dir=${start_dir}/[[[MOD:GENERAL:OUTPUT_CONTROL_FILES_DIR]]]
  57. # Architecture
  58. build_arch=[[[PLT:ACTIVE:BUILD_ARCH]]]
  59. use_machinefile=[[[PLT:ACTIVE:USE_MACHINEFILE]]]
  60. # This file is used to store information about restarts
  61. ece_info_file="ece.info"
  62. # -----------------------------------------------------------------------------
  63. # *** Read platform dependent configuration
  64. # -----------------------------------------------------------------------------
  65. source ./ecconf.cfg
  66. configure
  67. # -----------------------------------------------------------------------------
  68. # *** Time step settings
  69. # -----------------------------------------------------------------------------
  70. if has_config ifs
  71. then
  72. case "${ifs_grid}" in
  73. T159L*) ifs_time_step_sec=3600 ;;
  74. T255L*) ifs_time_step_sec=2700 ;;
  75. T511L*) ifs_time_step_sec=900 ;;
  76. *) error "Can't set time steps for unknown horizontal grid: ${ifs_grid}"
  77. ;;
  78. esac
  79. fi
  80. if has_config nemo
  81. then
  82. case "${nem_grid}" in
  83. ORCA1L*) nem_time_step_sec=2700; lim_time_step_sec=2700 ;;
  84. ORCA025L*) nem_time_step_sec=900 ; lim_time_step_sec=900 ;;
  85. *) error "Can't set time steps for unknown horizontal grid: ${nem_grid}"
  86. ;;
  87. esac
  88. fi
  89. if has_config ifs nemo
  90. then
  91. case "${ifs_grid}--${nem_grid}" in
  92. T159L*--ORCA1L*)
  93. ifs_time_step_sec=3600; nem_time_step_sec=2700; lim_time_step_sec=2700; cpl_freq_atm_oce_sec=10800
  94. ;;
  95. T255L*--ORCA1L*)
  96. ifs_time_step_sec=2700; nem_time_step_sec=2700; lim_time_step_sec=2700; cpl_freq_atm_oce_sec=2700
  97. ;;
  98. T511L*--ORCA025L*)
  99. ifs_time_step_sec=900 ; nem_time_step_sec=900 ; lim_time_step_sec=900 ; cpl_freq_atm_oce_sec=2700
  100. ;;
  101. *) error "Can't set time steps for unknown combination of horizontal grids: ${ifs_grid}-${nem_grid}"
  102. ;;
  103. esac
  104. fi
  105. # -----------------------------------------------------------------------------
  106. # *** IFS configuration
  107. # -----------------------------------------------------------------------------
  108. ifs_version=36r4
  109. ifs_di_freq=$(( 24 * 3600 / ifs_time_step_sec ))
  110. ifs_ddh_freq=$(( 120 * 3600 / ifs_time_step_sec ))
  111. export ifs_res_hor=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\1:')
  112. ifs_res_ver=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\2:')
  113. ifs_numproc=[[[MOD:IFS:NUMPROC]]]
  114. ifs_exe_file=${ecearth_src_dir}/ifs-${ifs_version}/bin/ifsmaster-${build_arch}
  115. ifs_lastout=false
  116. ifs_cmip5=[[[MOD:IFS:CMIP5]]]
  117. ifs_cmip5_rcp=[[[MOD:IFS:CMIP5_RCP]]]
  118. export ifs_cmip_fixyear=[[[MOD:IFS:CMIP_FIXYEAR]]]
  119. export ifs_cmip_fixyear_ch4=[[[MOD:IFS:CMIP_FIXYEAR_CH4]]]
  120. # Repeat trap from ifs/suecrad.F90 for early catch
  121. if ! has_config tm5:ch4fb && (( $ifs_cmip_fixyear != $ifs_cmip_fixyear_ch4 ))
  122. then
  123. error 'CH4 in IFS is not provided by TM5, NCMIPFIXYR_CH4 should be set equal to NCMIPFIXYR'
  124. fi
  125. ifs_cmip6=[[[MOD:IFS:CMIP6]]]
  126. ifs_mac2sp=[[[MOD:IFS:CMIP6]]]
  127. ifs_cmip6piaer=[[[MOD:IFS:CMIP6]]]
  128. export ifs_cmip6_scenario=[[[MOD:IFS:CMIP6_SCENARIO]]]
  129. # Enable optional COVID-19 scenarios, will enforce ifs_cmip6_scenario=SSP2-4.5
  130. ifs_covid19=FALSE
  131. # Choose one scenario : Base TwoYearBlip ModerateGreen StrongGreen FossilFuel
  132. ifs_covid19scen=Base
  133. # Basic sanity checks
  134. if [ ${ifs_covid19} == TRUE ] ; then
  135. [ ${ifs_cmip6_scenario} != SSP2-4.5 ] && echo "*WARNING* with ifs_covid19=TRUE IFS uses ifs_cmip6_scenario=SSP2-4.5 not ${ifs_cmip6_scenario}"
  136. has_config any lpjg pisces tm5 && error "ifs_covid19=TRUE is not supported with LPJ-GUESS, PISCES nor TM5"
  137. fi
  138. lcmip6_strataer_simp=FALSE
  139. lcmip6_strataer_full=[[[MOD:IFS:CMIP6]]]
  140. lcmip6_strataer_bckgd=FALSE
  141. export ifs_A4xCO2=[[[MOD:IFS:CMIP6_A4xCO2]]]
  142. export ifs_1PCTCO2=[[[MOD:IFS:CMIP6_1PCTCO2]]]
  143. export bgc_1PCTCO2=[[[MOD:IFS:CMIP6_1PCTCO2_BGC]]]
  144. # Time-varying orbital forcing (Qiong Zhang, SU-2013-09)
  145. # https://dev.ec-earth.org/projects/ecearth3/wiki/Orbital_forcing_in_EC-Earth_3
  146. #
  147. # ifs_orb_switch=false, no orbital calculations applied
  148. # ifs_orb_switch=true, use orbital calculations according to ifs_orb_mode
  149. # ifs_orb_mode="fixed_year", or "variable_year", or "fixed_parameters"
  150. # fixed_year: calculate the orbital parameters at ifs_orb_iyear, e.g.,1850
  151. # variable_year: calculate orbital parameters annually start from ifs_orb_iyear
  152. # fixed_parameters: prescribe orbital parameters for given year
  153. case "${ifs_grid}" in
  154. T159*) ifs_orb_switch=true ;;
  155. *) ifs_orb_switch=false ;;
  156. esac
  157. ifs_orb_mode="variable_year"
  158. ifs_orb_iyear=$(date -u -d "${run_start_date}" +%Y)
  159. # Relaxation of soil moisture (Wilhelm May, LU; October 2017)
  160. #
  161. # LRXSM: Parameter indicating the levels to be nudged
  162. #
  163. # LRXSM = 0: no nudging
  164. # LRXSM = 12: 4xdaily data and 3 levels (excluding level 1)
  165. # LRXSM = 13: 4xdaily data and 4 levels
  166. #
  167. # LRXSMTx: time scale of the relaxation for level X (in hours)
  168. #
  169. # LRXSMTx = 0: actual values relpaced by external ones
  170. # LRXSMTx = 24: 1 day
  171. # LRXSMTx = 120: 5 days
  172. #
  173. # LRXSMS: indicates when the relaxation is done
  174. #
  175. # LRXSMS = 0: before the time step
  176. # LRXSMS = 1: after the time step
  177. #
  178. has_config soilnudg && ifs_lrxsm=13 || ifs_lrxsm=0
  179. ifs_lrxsmt1=96
  180. ifs_lrxsmt2=72
  181. ifs_lrxsmt3=48
  182. ifs_lrxsmt4=24
  183. ifs_lrxsms=1
  184. # IFS tuning parameters
  185. variant=
  186. has_config tm5:chem && variant=-AerChem
  187. ifs_tuning_parameter_file=${ctrl_file_dir}/ifs-tuning-parameters-${ifs_grid}${variant}.sh
  188. if [ -f ${ifs_tuning_parameter_file} ]
  189. then
  190. source ${ifs_tuning_parameter_file}
  191. else
  192. error "Sorry, ${ifs_tuning_parameter_file} not found, exiting."
  193. fi
  194. # Select source of vegetation data:
  195. # ifs climatology from IFS
  196. # era20c vegetation from an off-line LPJ-Guess run forced with ERA20C
  197. # (currently available only for T255 and T159)
  198. # cmip6 vegetation from an EC-Earth3-Veg (interactive LPJ-Guess) run
  199. # (currently available only for T255)
  200. # custom_exp vegetation from any EC-Earth3-Veg run exp
  201. # (must contain same variables as era20c & cmip6 and located in icmcl_exp folder)
  202. # none don't create an ICMCL file with vegetation data (this is set
  203. # automatically if LPJG is used with feedback)
  204. #
  205. ifs_veg_source="cmip6"
  206. has_config lpjg:fdbck && ifs_veg_source="none"
  207. case ${ifs_veg_source} in
  208. "ifs" )
  209. # Use Lambert-Beer to compute effective vegetation cover
  210. n_compute_eff_veg_fraction=2
  211. ;;
  212. "era20c" )
  213. # LPJG vegetation is provided as effective cover
  214. # Don't use Lambert-Beer
  215. n_compute_eff_veg_fraction=0
  216. case "${ifs_grid}" in
  217. T159L*) veg_version=v29 ;;
  218. T255L*) veg_version=v16 ;;
  219. *) error "Vegetation from off-line LPJ-Guess not available for ${ifs_grid}" ;;
  220. esac
  221. ;;
  222. "cmip6" )
  223. # LPJG vegetation is provided as effective cover
  224. # Don't use Lambert-Beer
  225. n_compute_eff_veg_fraction=0
  226. case "${ifs_grid}" in
  227. T255L*) veg_version=v32 ;;
  228. *) error "Vegetation from CMIP6 EC-Earth3-Veg not available for ${ifs_grid}" ;;
  229. esac
  230. ;;
  231. "custom_"* )
  232. # LPJG vegetation is provided as effective cover
  233. # Don't use Lambert-Beer
  234. n_compute_eff_veg_fraction=0
  235. veg_version=${ifs_veg_source:7}
  236. if [ ! -d ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version} ]
  237. then
  238. error "requested IFS_VEG_SOURCE = ${ifs_veg_source} but not found in ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version}"
  239. fi
  240. ;;
  241. "none" )
  242. # LPJG with feedback
  243. n_compute_eff_veg_fraction=0
  244. ! has_config lpjg:fdbck && error "IFS requires an offline source of vegetation"
  245. ;;
  246. * )
  247. error "Vegetation from ${ifs_veg_source} not implemented"
  248. ;;
  249. esac
  250. # use DMI land ice physics and varying snow albedo
  251. case "${ifs_grid}" in
  252. T159*) ifs_landice=true ;;
  253. *) ifs_landice=false ;;
  254. esac
  255. # -----------------------------------------------------------------------------
  256. # *** NEMO/LIM configuration
  257. # -----------------------------------------------------------------------------
  258. # This is only needed if the experiment is started from an existing set of NEMO
  259. # restart files
  260. nem_restart_file_path=${start_dir}/nemo-rst
  261. nem_restart_offset=0
  262. nem_res_hor=$(echo ${nem_grid} | sed 's:ORCA\([0-9]\+\)L[0-9]\+:\1:')
  263. nem_config=${nem_grid}
  264. has_config lim3 && nem_config=${nem_config}_LIM3
  265. if has_config pisces tm5:co2
  266. then
  267. nem_config=${nem_config}_CarbonCycle
  268. elif has_config pisces
  269. then
  270. nem_config=${nem_config}_PISCES
  271. fi
  272. # TODO - nemo standalone configs are not accounted for in this script, but this would set the required nem_config
  273. ! has_config ifs && nem_config=${nem_config}_standalone
  274. nem_exe_file=${ecearth_src_dir}/nemo-3.6/CONFIG/${nem_config}/BLD/bin/nemo.exe
  275. nem_numproc=[[[MOD:NEM:NUMPROC]]]
  276. # Thermal conductivity of snow, see comment in ctrl/namelist.lim3.ref.sh
  277. case "${ifs_grid}" in
  278. T159L* ) nem_rn_cdsn=0.25 ;;
  279. * ) nem_rn_cdsn=0.27 ;;
  280. esac
  281. # -----------------------------------------------------------------------------
  282. # *** Runoff mapper configuration
  283. # -----------------------------------------------------------------------------
  284. rnf_exe_file=${ecearth_src_dir}/runoff-mapper/bin/runoff-mapper.exe
  285. rnf_numproc=1
  286. # -----------------------------------------------------------------------------
  287. # *** LPJ-GUESS configuration
  288. # -----------------------------------------------------------------------------
  289. lpjg_time_step_sec=[[[MOD:LPJG:TIME_STEP_SEC]]]
  290. lpjg_numproc=[[[MOD:LPJG:NUMPROC]]]
  291. has_config lpjg && lpjg_on=1
  292. has_config lpjg:fdbck && lpjg_fdbck=1
  293. has_config tm5:co2 && lpjg_fdbck_tm5=1 || lpjg_fdbck_tm5=0
  294. export lpjg_fixNdepafter=[[[MOD:LPJG:LPJG_FIXNDEPAFTER]]]
  295. export lpjg_fixLUafter=[[[MOD:LPJG:LPJG_FIXLUAFTER]]]
  296. info '!!!! CMIP FIX YEAR SETTINGS:'
  297. info "ifs_cmip_fixyear: $ifs_cmip_fixyear"
  298. info "lpjg_fixNDepAfter: $lpjg_fixNdepafter"
  299. info "lpjg_fixLUAfter: $lpjg_fixLUafter"
  300. info '!!!!'
  301. lpjg_res=T${ifs_res_hor}
  302. lpjg_exe_file=${ecearth_src_dir}/lpjg/build/guess_${lpjg_res}
  303. # -----------------------------------------------------------------------------
  304. # *** AMIP-reader configuration
  305. # -----------------------------------------------------------------------------
  306. amip_exe_file=${ecearth_src_dir}/amip-forcing/bin/amip-forcing.exe
  307. amip_numproc=1
  308. # -----------------------------------------------------------------------------
  309. # *** TM5 configuration
  310. # -----------------------------------------------------------------------------
  311. if $(has_config tm5)
  312. then
  313. # With TM5, NPRTRV is set to 1 in the namelist. To avoid some out-of-bound
  314. # arrays in IFS, we must limit the number of cores for IFS
  315. if (( ifs_numproc > (ifs_res_hor+1) ))
  316. then
  317. error "too much cores requested for IFS, max is $((ifs_res_hor+1))"
  318. fi
  319. # TM5 settings
  320. has_config tm5:co2 && tmversion="co2" || tmversion="cb05"
  321. has_config tm5:co2 && export tm5_co2=1 || export tm5_co2=0
  322. export tm5_exch_nlevs=[[[MOD:TM5:NLEVS]]]
  323. tm5_time_step_sec=[[[MOD:TM5:TIME_STEP_SEC]]]
  324. export tm5_numproc_x=[[[MOD:TM5:NUMPROC_X]]]
  325. export tm5_numproc_y=[[[MOD:TM5:NUMPROC_Y]]]
  326. tm5_numproc=$(( tm5_numproc_x * tm5_numproc_y ))
  327. export tm5_emiss_fixyear=[[[MOD:TM5:EMISS_FIXYEAR]]]
  328. # limited number of levels for feedback (aerosols, currently set to lmax_conv in TM5)
  329. case ${tm5_exch_nlevs} in
  330. 34) export tm5_exch_nlevs_cutoff=23 ;;
  331. 10) export tm5_exch_nlevs_cutoff=10 ;;
  332. 4) export tm5_exch_nlevs_cutoff=4 ;;
  333. *) error "not supported number of levels for TM5"
  334. esac
  335. # executable
  336. tm5_exe_file=${ecearth_src_dir}/tm5mp/build-${tmversion}-ml${tm5_exch_nlevs}/appl-tm5-${tmversion}.x
  337. # path to initial conditions, modify as needed
  338. tm5_restart_file_path=${ini_data_dir}/tm5/restart/${tmversion}-ml${tm5_exch_nlevs}
  339. # fields sent back to IFS
  340. has_config tm5:o3fb && tm5_to_ifs=O3 || tm5_to_ifs=
  341. has_config tm5:ch4fb && tm5_to_ifs=${tm5_to_ifs},CH4
  342. has_config tm5:aerfb && tm5_to_ifs=${tm5_to_ifs},"\
  343. N2,SU2,BC2,OC2,N3,SU3,BC3,OC3,SS3,DU3,\
  344. N4,SU4,BC4,OC4,SS4,DU4,N5,BC5,OC5,N6,DU6,N7,DU7,\
  345. NO3,MSA,\
  346. AOD_01,AOD_02,AOD_03,AOD_04,AOD_05,AOD_06,AOD_07,AOD_08,AOD_09,AOD_10,AOD_11,AOD_12,AOD_13,AOD_14,\
  347. SSA_01,SSA_02,SSA_03,SSA_04,SSA_05,SSA_06,SSA_07,SSA_08,SSA_09,SSA_10,SSA_11,SSA_12,SSA_13,SSA_14,\
  348. ASF_01,ASF_02,ASF_03,ASF_04,ASF_05,ASF_06,ASF_07,ASF_08,ASF_09,ASF_10,ASF_11,ASF_12,ASF_13,ASF_14"
  349. has_config tm5:co2fb && tm5_to_ifs=${tm5_to_ifs},CO2
  350. export tm5_to_ifs=$(echo ${tm5_to_ifs} | sed "s/^,//")
  351. # coupled to LPJ-Guess and/or PISCES?
  352. has_config tm5:co2 lpjg && export cpl_tm_guess=T || export cpl_tm_guess=F
  353. has_config tm5:co2 pisces && export cpl_tm_pisces=T || export cpl_tm_pisces=F
  354. fi
  355. # -----------------------------------------------------------------------------
  356. # *** OASIS configuration
  357. # -----------------------------------------------------------------------------
  358. # Restart files for the coupling fields (note 8 character limit in OASIS)
  359. # rstas.nc : atmosphere single-category fields
  360. # rstam.nc : atmosphere multi-category fields
  361. # rstos.nc : ocean single-category fields
  362. # rstom.nc : ocean multi-category fields
  363. oas_rst_ifs_nemo="rstas.nc rstos.nc"
  364. oas_rst_ifs_lpjg="vegin.nc lpjgv.nc"
  365. # Met fields from IFS to TM (always required)
  366. oas_rst_ifs_tm5="r_hum.nc r_g2d.nc r_udr.nc r_div.nc r_vor.nc \
  367. r_ddr.nc r_tmp.nc r_dmf.nc r_s2d.nc r_umf.nc"
  368. has_config tm5:chem && \
  369. oas_rst_ifs_tm5=${oas_rst_ifs_tm5}' r_cc_.nc r_clw.nc r_cco.nc r_ciw.nc r_ccu.nc'
  370. has_config tm5:o3fb || has_config tm5:ch4fb && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' o3ch4.nc'
  371. has_config tm5:aerfb && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' C???????'
  372. # C-cycle configuration
  373. has_config tm5:co2 lpjg && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' l_co2.nc rlpjg.nc'
  374. has_config tm5:co2 pisces && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' o_co2.nc pisce.nc'
  375. has_config tm5:co2fb && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' co2mx.nc'
  376. # final list of files depends on the activated components - this is used in save_ic as well
  377. #oas_rst_files="${oas_rst_ifs_nemo} ${oas_rst_ifs_tm5} vegin.nc lpjgv.nc"
  378. oas_rst_files=""
  379. has_config ifs nemo && oas_rst_files+=" ${oas_rst_ifs_nemo}"
  380. has_config ifs lpjg && oas_rst_files+=" ${oas_rst_ifs_lpjg}"
  381. has_config ifs tm5 && oas_rst_files+=" ${oas_rst_ifs_tm5}"
  382. # Decide whether the OASIS weight files for interpolation should be linked from
  383. # the setup directory (true) or not (false). In the latter case, the weights
  384. # are re-computed at the start of the run.
  385. oas_link_weights=true
  386. # Flux correction for runoff (not calving) sent from Oasis to ocean.
  387. # 1.07945 is computed to compensate for a P-E=-0.016 mm/day (valid for std res)
  388. case "${ifs_grid}" in
  389. T159L* ) has_config nemo && oas_mb_fluxcorr=1.08652 ;;
  390. T511L* ) has_config nemo && oas_mb_fluxcorr=1.07945 ;;
  391. * ) has_config nemo && oas_mb_fluxcorr=1.07945 ;;
  392. esac
  393. # -----------------------------------------------------------------------------
  394. # *** XIOS configuration
  395. # -----------------------------------------------------------------------------
  396. xio_exe_file=${ecearth_src_dir}/xios-2.5/bin/xios_server.exe
  397. xio_numproc=[[[MOD:XIO:NUMPROC]]]
  398. # -----------------------------------------------------------------------------
  399. # *** Extra initial conditions saved during the run
  400. # -----------------------------------------------------------------------------
  401. if has_config save_ic
  402. then
  403. source ./libsave_ic.sh
  404. declare -a save_ic_date save_ic_date1 save_ic_sec save_ic_day save_ic_ppt_file save_ic_nemo_ts
  405. oas_rst_files="${oas_rst_ifs_nemo} ${oas_rst_ifs_tm5} vegin.nc lpjgv.nc"
  406. fi
  407. # -----------------------------------------------------------------------------
  408. # *** Carbon cycle configuration
  409. # -----------------------------------------------------------------------------
  410. # set to true to write co2 fluxes sent to TM5
  411. ccycle_debug_fluxes=true
  412. # =============================================================================
  413. # *** END of User configuration
  414. # =============================================================================
  415. # =============================================================================
  416. # *** This is where the code begins ...
  417. # =============================================================================
  418. # -----------------------------------------------------------------------------
  419. # *** Create the run dir if necessary and go there
  420. # Everything is done from here.
  421. # -----------------------------------------------------------------------------
  422. if [ ! -d ${run_dir} ]
  423. then
  424. mkdir -p ${run_dir}
  425. fi
  426. cd ${run_dir}
  427. # -----------------------------------------------------------------------------
  428. # *** Determine the time span of this run and whether it's a restart leg
  429. # -----------------------------------------------------------------------------
  430. # Regularise the format of the start and end date of the simulation
  431. run_start_date=$(date -uR -d "${run_start_date}")
  432. run_end_date=$(date -uR -d "${run_end_date}")
  433. # -----------------------------------------------------------------------------
  434. # *** Set path to grib_set
  435. # -----------------------------------------------------------------------------
  436. grib_set=${GRIB_BIN_PATH}${GRIB_BIN_PATH:+/}grib_set
  437. # Loop over the number of legs
  438. for (( ; run_num_legs>0 ; run_num_legs-- ))
  439. do
  440. # Check for restart information file and set the current leg start date
  441. # Ignore restart information file if force_run_from_scratch is true
  442. if ${force_run_from_scratch} || ! [ -r ${ece_info_file} ]
  443. then
  444. leg_is_restart=false
  445. leg_start_date=${run_start_date}
  446. leg_number=1
  447. else
  448. leg_is_restart=true
  449. . ./${ece_info_file}
  450. leg_start_date=${leg_end_date}
  451. leg_number=$((leg_number+1))
  452. fi
  453. # Compute the end date of the current leg
  454. if [ -n "${rst_freq}" ]
  455. then
  456. leg_end_date=$(date -uR -d "${leg_start_date} + ${rst_freq}")
  457. else
  458. leg_end_date=${run_end_date}
  459. fi
  460. # Check if legs are integer multiples of full years if LPJG is used
  461. if has_config lpjg
  462. then
  463. if [[ $(date +%m%d%T -u -d "${leg_start_date}") != "010100:00:00" || \
  464. $(date +%m%d%T -u -d "${leg_start_date} + ${rst_freq}") != "010100:00:00" ]]
  465. then
  466. error "LPJ-GUESS runs must start on Jan 1 and end on Dec 31. Multi-year legs are allowed."
  467. fi
  468. fi
  469. if [ $(date -u -d "${leg_end_date}" +%s) -ge $(date -u -d "${run_end_date}" +%s) ]
  470. then
  471. leg_end_date=${run_end_date}
  472. ifs_lastout=true
  473. fi
  474. # Some time variables needed later
  475. leg_length_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${leg_start_date}" +%s) ))
  476. leg_start_sec=$(( $(date -u -d "${leg_start_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  477. leg_end_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  478. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d)
  479. leg_start_date_yyyy=$(date -u -d "${leg_start_date}" +%Y)
  480. leg_end_date_yyyy=$(date -u -d "${leg_end_date}" +%Y)
  481. # Check whether there's actually time left to simulate - exit otherwise
  482. if [ ${leg_length_sec} -le 0 ]
  483. then
  484. info "Leg start date equal to or after end of simulation."
  485. info "Nothing left to do. Exiting."
  486. exit 0
  487. fi
  488. # Initial conditions saved during the run
  489. do_save_ic=false
  490. has_config save_ic && save_ic_get_config
  491. # if you do not use an option with save_ic, you must define 'do_save_ic' and
  492. # 'save_ic_date_offset' here or in ../libsave_ic.sh/save_ic_get_config()
  493. ${do_save_ic} && save_ic_define_vars
  494. # -------------------------------------------------------------------------
  495. # *** Prepare the run directory for a run from scratch
  496. # -------------------------------------------------------------------------
  497. if ! $leg_is_restart
  498. then
  499. # ---------------------------------------------------------------------
  500. # *** Check if run dir is empty. If not, and if we are allowed to do so
  501. # by ${force_run_from_scratch}, remove everything
  502. # ---------------------------------------------------------------------
  503. if $(ls * >& /dev/null)
  504. then
  505. if ${force_run_from_scratch}
  506. then
  507. rm -fr ${run_dir}/*
  508. else
  509. error "Run directory not empty and \$force_run_from_scratch not set."
  510. fi
  511. fi
  512. # ---------------------------------------------------------------------
  513. # *** Copy executables of model components
  514. # *** Additionally, create symlinks to the original place for reference
  515. # ---------------------------------------------------------------------
  516. cp ${ifs_exe_file} .
  517. ln -s ${ifs_exe_file} $(basename ${ifs_exe_file}).lnk
  518. if $(has_config amip)
  519. then
  520. cp ${amip_exe_file} .
  521. ln -s ${amip_exe_file} $(basename ${amip_exe_file}).lnk
  522. fi
  523. if $(has_config nemo)
  524. then
  525. cp ${nem_exe_file} .
  526. ln -s ${nem_exe_file} $(basename ${nem_exe_file}).lnk
  527. cp ${rnf_exe_file} .
  528. ln -s ${rnf_exe_file} $(basename ${rnf_exe_file}).lnk
  529. cp ${xio_exe_file} .
  530. ln -s ${xio_exe_file} $(basename ${xio_exe_file}).lnk
  531. fi
  532. if $(has_config lpjg)
  533. then
  534. cp ${lpjg_exe_file} .
  535. ln -s ${lpjg_exe_file} $(basename ${lpjg_exe_file}).lnk
  536. fi
  537. if $(has_config tm5)
  538. then
  539. cp ${tm5_exe_file} .
  540. ln -s ${tm5_exe_file} $(basename ${tm5_exe_file}).lnk
  541. fi
  542. # ---------------------------------------------------------------------
  543. # *** Files needed for IFS (linked)
  544. # ---------------------------------------------------------------------
  545. # Initial data
  546. ln -s \
  547. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIUA \
  548. ICMGG${exp_name}INIUA
  549. ln -s \
  550. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMSHECE3INIT \
  551. ICMSH${exp_name}INIT
  552. rm -f ICMGG${exp_name}INIT
  553. cp ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIT \
  554. ICMGG${exp_name}INIT
  555. # add bare_soil_albedo to ICMGG*INIT
  556. tempfile=tmp.$$
  557. ${grib_set} -s dataDate=$(date -u -d "$run_start_date" +%Y%m%d) \
  558. ${ini_data_dir}/ifs/${ifs_grid}/climate/bare_soil_albedos.grb \
  559. ${tempfile}
  560. cat ${tempfile} >> ICMGG${exp_name}INIT
  561. rm -f ${tempfile}
  562. # add land ice mask if needed
  563. if ${ifs_landice}
  564. then
  565. tempfile=tmp.$$
  566. cdo divc,10 -setcode,82 -selcode,141 ICMGG${exp_name}INIT ${tempfile}
  567. ${grib_set} -s gridType=reduced_gg ${tempfile} ${tempfile}
  568. cat ${tempfile} >> ICMGG${exp_name}INIT
  569. rm -f ${tempfile}
  570. fi
  571. # Other stuff
  572. ln -s ${ini_data_dir}/ifs/rtables/* .
  573. # Output control (ppt files)
  574. if [ ! -f ${output_control_files_dir}/pptdddddd0600 ] && [ ! -f ${output_control_files_dir}/pptdddddd0300 ];then
  575. echo "Error from ece-esm.sh: Neither the file pptdddddd0600 or pptdddddd0300 exists in the directory:"
  576. echo " " ${output_control_files_dir}
  577. exit -1
  578. fi
  579. mkdir postins
  580. cp ${output_control_files_dir}/ppt* postins/
  581. if [ -f postins/pptdddddd0600 ];then
  582. ln -s pptdddddd0600 postins/pptdddddd0000
  583. ln -s pptdddddd0600 postins/pptdddddd1200
  584. ln -s pptdddddd0600 postins/pptdddddd1800
  585. fi
  586. if [ -f postins/pptdddddd0300 ];then
  587. ln -s pptdddddd0300 postins/pptdddddd0900
  588. ln -s pptdddddd0300 postins/pptdddddd1500
  589. ln -s pptdddddd0300 postins/pptdddddd2100
  590. if [ ! -f postins/pptdddddd0600 ];then
  591. ln -s pptdddddd0300 postins/pptdddddd0000
  592. ln -s pptdddddd0300 postins/pptdddddd0600
  593. ln -s pptdddddd0300 postins/pptdddddd1200
  594. ln -s pptdddddd0300 postins/pptdddddd1800
  595. fi
  596. fi
  597. /bin/ls -1 postins/* > dirlist
  598. # ---------------------------------------------------------------------
  599. # *** Files needed for LPJ-GUESS
  600. # ---------------------------------------------------------------------
  601. if $(has_config lpjg)
  602. then
  603. # Check for valid grid
  604. if [ $lpjg_res != "T255" -a $lpjg_res != "T159" ]
  605. then
  606. error "LPJG-gridlist doesn't exist for ifs-grid: ${ifs_grid}"
  607. fi
  608. # Initial data - saved state for LPJ-GUESS (.bin format)
  609. lpjgstartdir=$(printf "lpjg_state_%04d" $leg_start_date_yyyy)
  610. ln -sf ${ini_data_dir}/lpjg/ini_state/${lpjg_res}/${lpjgstartdir} ${run_dir}/${lpjgstartdir}
  611. # Control files (i.e. .ins, landuse, N deposition, soil type files etc.)
  612. cp -f ${ecearth_src_dir}/lpjg/data/ins/*.ins .
  613. # activate the new litterfall scheme for C4MIP - for the coupled model this is done when both pisces and lpjg are activated
  614. has_config pisces lpjg && echo -e "!override for EC-Earth-CC in runscript\nifpftlitterfall 1\ncalc_phen_after_restart 0" >> global.ins
  615. mkdir -p ${run_dir}/landuse
  616. fi
  617. # ---------------------------------------------------------------------
  618. # *** Files needed for NEMO (linked)
  619. # ---------------------------------------------------------------------
  620. if $(has_config nemo)
  621. then
  622. # Link initialisation files for matching ORCA grid
  623. for f in \
  624. bathy_meter.nc coordinates.nc \
  625. ahmcoef.nc \
  626. K1rowdrg.nc M2rowdrg.nc mask_itf.nc \
  627. decay_scale_bot.nc decay_scale_cri.nc \
  628. mixing_power_bot.nc mixing_power_cri.nc mixing_power_pyc.nc \
  629. runoff_depth.nc subbasins.nc
  630. do
  631. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && ln -s ${ini_data_dir}/nemo/initial/${nem_grid}/$f
  632. done
  633. # Copying the time independent NEMO files for the matching ORCA grid in order to facilitate cmorisation:
  634. for f in \
  635. bathy_meter.nc subbasins.nc
  636. do
  637. mkdir -p output/nemo/ofx-data
  638. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && cp -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f output/nemo/ofx-data/
  639. done
  640. # Link geothermal heating file (independent of grid) and matching weight file
  641. ln -s ${ini_data_dir}/nemo/initial/Goutorbe_ghflux.nc
  642. ln -s ${ini_data_dir}/nemo/initial/weights_Goutorbe1_2_orca${nem_res_hor}_bilinear.nc
  643. # Link the salinity climatology file (needed for diagnostics)
  644. ln -s ${ini_data_dir}/nemo/climatology/${nem_grid}/sali_ref_clim_monthly.nc
  645. # Link either restart files or climatology files for the initial state
  646. if $(has_config nemo:start_from_restart)
  647. then
  648. # When linking restart files, we accept three options:
  649. # (1) Merged files for ocean and ice, i.e.
  650. # restart_oce.nc and restart_ice.nc
  651. # (2) One-file-per-MPI-rank, i.e.
  652. # restart_oce_????.nc and restart_ice_????.nc
  653. # No check is done whether the number of restart files agrees
  654. # with the number of MPI ranks for NEMO!
  655. # (3) One-file-per-MPI-rank with a prefix, i.e.
  656. # <exp_name>_<time_step>_restart_oce_????.nc (similar for the ice)
  657. # The prefix is ignored.
  658. # The code assumes that one of the options can be applied! If more
  659. # options are applicable, the first is chosen. If none of the
  660. # options apply, NEMO will crash with missing restart file.
  661. if ls -U ${nem_restart_file_path}/restart_[oi]ce.nc > /dev/null 2>&1
  662. then
  663. ln -s ${nem_restart_file_path}/restart_[oi]ce.nc ./
  664. elif ls -U ${nem_restart_file_path}/restart_[oi]ce_????.nc > /dev/null 2>&1
  665. then
  666. ln -s ${nem_restart_file_path}/restart_[oi]ce_????.nc ./
  667. else
  668. for f in ${nem_restart_file_path}/????_????????_restart_[oi]ce_????.nc
  669. do
  670. ln -s $f $(echo $f | sed 's/.*_\(restart_[oi]ce_....\.nc\)/\1/')
  671. done
  672. fi
  673. else
  674. # Temperature and salinity files for initialisation
  675. ln -s ${ini_data_dir}/nemo/climatology/absolute_salinity_WOA13_decav_Reg1L75_clim.nc
  676. ln -s ${ini_data_dir}/nemo/climatology/conservative_temperature_WOA13_decav_Reg1L75_clim.nc
  677. ln -s ${ini_data_dir}/nemo/climatology/weights_WOA13d1_2_orca${nem_res_hor}_bilinear.nc
  678. # Grid dependent runoff files
  679. case ${nem_grid} in
  680. ORCA1*) ln -s ${ini_data_dir}/nemo/climatology/runoff-icb_DaiTrenberth_Depoorter_ORCA1_JD.nc ;;
  681. ORCA025*) ln -s ${ini_data_dir}/nemo/climatology/ORCA_R025_runoff_v1.1.nc ;;
  682. esac
  683. fi
  684. # for ocean_nudging
  685. if $(has_config nemo:ocenudg) ; then
  686. ln -s ${ini_data_dir}/nemo/oce_nudg/resto.nc
  687. fi
  688. # XIOS files
  689. . ${ctrl_file_dir}/iodef.xml.sh > iodef.xml
  690. ln -s ${ctrl_file_dir}/context_nemo.xml
  691. . ${ctrl_file_dir}/domain_def_nemo.xml.sh > domain_def_nemo.xml
  692. ln -s ${ctrl_file_dir}/axis_def_nemo.xml
  693. ln -s ${ctrl_file_dir}/grids_def_nemo.xml
  694. ln -s ${ctrl_file_dir}/field_def_nemo-lim.xml
  695. ln -s ${ctrl_file_dir}/field_def_nemo-opa.xml
  696. ln -s ${ctrl_file_dir}/field_def_nemo-pisces.xml
  697. ln -s ${ctrl_file_dir}/field_def_nemo-inerttrc.xml
  698. ln -s ${output_control_files_dir}/file_def_nemo-lim3.xml file_def_nemo-lim.xml
  699. ln -s ${output_control_files_dir}/file_def_nemo-opa.xml
  700. ln -s ${output_control_files_dir}/file_def_nemo-pisces.xml
  701. if [ -f ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ]
  702. then
  703. cp ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ./
  704. else
  705. info "File 'coordinates_xios.nc' not found. NEMO can not be run with land domain removal!"
  706. fi
  707. # Files needed for TOP/PISCES
  708. if $(has_config pisces)
  709. then
  710. ln -fs ${ini_data_dir}/nemo/pisces/dust_INCA_ORCA_R1.nc
  711. ln -fs ${ini_data_dir}/nemo/pisces/ndeposition_Duce_ORCA_R1.nc
  712. ln -fs ${ini_data_dir}/nemo/pisces/pmarge_etopo_ORCA_R1.nc
  713. ln -fs ${ini_data_dir}/nemo/pisces/river_global_news_ORCA_R1.nc
  714. ln -fs ${ini_data_dir}/nemo/pisces/Solubility_T62_Mahowald_ORCA_R1.nc
  715. ln -fs ${ini_data_dir}/nemo/pisces/par_fraction_gewex_clim90s00s_ORCA_R1.nc
  716. ln -fs ${ini_data_dir}/nemo/pisces/DIC_GLODAP_annual_ORCA_R1.nc
  717. ln -fs ${ini_data_dir}/nemo/pisces/Alkalini_GLODAP_annual_ORCA_R1.nc
  718. ln -fs ${ini_data_dir}/nemo/pisces/O2_WOA2009_monthly_ORCA_R1.nc
  719. ln -fs ${ini_data_dir}/nemo/pisces/PO4_WOA2009_monthly_ORCA_R1.nc
  720. ln -fs ${ini_data_dir}/nemo/pisces/Si_WOA2009_monthly_ORCA_R1.nc
  721. ln -fs ${ini_data_dir}/nemo/pisces/DOC_PISCES_monthly_ORCA_R1.nc
  722. ln -fs ${ini_data_dir}/nemo/pisces/Fer_PISCES_monthly_ORCA_R1.nc
  723. ln -fs ${ini_data_dir}/nemo/pisces/NO3_WOA2009_monthly_ORCA_R1.nc
  724. # create co2 concentration file atcco2.txt if required
  725. if { [ $ifs_cmip_fixyear -gt 0 ] || [[ "${ifs_A4xCO2}" = "TRUE" ]]; } && [[ "${bgc_1PCTCO2}" = "FALSE" ]]
  726. then
  727. rm -f atcco2.txt
  728. elif [[ "${bgc_1PCTCO2}" = "TRUE" ]]
  729. then
  730. cp -f ${ini_data_dir}/nemo/pisces/mole-fraction-of-carbon-dioxide-in-air_1pctCO2_1849-2016.txt atcco2.txt
  731. else
  732. # determine scenario-name and co2-file middle-fix
  733. case $(echo ${ifs_cmip6_scenario} | tr '[:upper:]' '[:lower:]') in
  734. hist*) pis_scen="ssp585"; pis_sco2_mfix="REMIND-MAGPIE-ssp585-1-2-1";;
  735. ssp1-1.9*) pis_scen="ssp119"; pis_sco2_mfix="IMAGE-ssp119-1-2-1";;
  736. ssp1-2.6*) pis_scen="ssp126"; pis_sco2_mfix="IMAGE-ssp126-1-2-1";;
  737. ssp2-4.5*) pis_scen="ssp245"; pis_sco2_mfix="MESSAGE-GLOBIOM-ssp245-1-2-1";;
  738. ssp5-3.4*) pis_scen="ssp534os"; pis_sco2_mfix="REMIND-MAGPIE-ssp534-over-1-2-1";;
  739. ssp5-8.5*) pis_scen="ssp585"; pis_sco2_mfix="REMIND-MAGPIE-ssp585-1-2-1";;
  740. *) error "Scenario ${ifs_cmip6_scenario} not defined for PISCES" ;;
  741. esac
  742. # concatenate historic and scenario (2015+) co2 concentration file
  743. pis_sco2_pfix="${ini_data_dir}/nemo/pisces/mole-fraction-of-carbon-dioxide-in-air_input4MIPs_GHGConcentrations"
  744. cat ${pis_sco2_pfix}_CMIP_UoM-CMIP-1-2-0_gr1-GMNHSH_1849-2014.txt ${pis_sco2_pfix}_ScenarioMIP_UoM-${pis_sco2_mfix}_gr1-GMNHSH_2015-2500.txt > atcco2.txt
  745. fi
  746. fi
  747. #linking surface boundary conditions for CFCs (even if CFCs are not included)
  748. ln -fs ${ini_data_dir}/nemo/cfc/CFCs_CDIAC_extension_1637_2019.dat CFCs_CDIAC.dat
  749. if $(has_config pisces:start_from_restart)
  750. then
  751. # Same three options as for nemo:start_from_restart
  752. if ls -U ${nem_restart_file_path}/restart_trc.nc > /dev/null 2>&1
  753. then
  754. ln -s ${nem_restart_file_path}/restart_trc.nc ./
  755. elif ls -U ${nem_restart_file_path}/restart_trc_????.nc > /dev/null 2>&1
  756. then
  757. ln -s ${nem_restart_file_path}/restart_trc_????.nc ./
  758. else
  759. for f in ${nem_restart_file_path}/????_????????_restart_trc_????.nc
  760. do
  761. ln -s $f $(echo $f | sed 's/.*_\(restart_trc_....\.nc\)/\1/')
  762. done
  763. fi
  764. fi
  765. fi
  766. # ---------------------------------------------------------------------
  767. # *** Files needed for the Runoff mapper (linked)
  768. # ---------------------------------------------------------------------
  769. has_config rnfmapper && \
  770. ln -s ${ini_data_dir}/runoff-mapper/runoff_maps.nc
  771. # -------------------------------------------------------------------------
  772. # *** File and dir needed for TM5
  773. # -------------------------------------------------------------------------
  774. if $(has_config tm5)
  775. then
  776. tm5_istart=[[[MOD:TM5:ISTART]]]
  777. case ${tm5_istart} in
  778. 33|32) ln -s \
  779. ${tm5_restart_file_path}/TM5_restart_${leg_start_date_yyyymmdd}_0000_glb300x200.nc
  780. ;;
  781. 31) ln -s ${tm5_restart_file_path}/tm5_save.hdf
  782. ;;
  783. 5) ln -s ${tm5_restart_file_path}/tm5_mmix.hdf
  784. ;;
  785. 2|9)
  786. ;;
  787. *) error "Unsupported initial fields option (TM5): ${tm5_istart}"
  788. ;;
  789. esac
  790. # spectral info
  791. ln -s ${ini_data_dir}/tm5/TM5_INPUT/T${ifs_res_hor}_info.txt
  792. # Profiling dir for TM5
  793. mkdir -p ${run_dir}/tm5_profile
  794. fi
  795. # ---------------------------------------------------------------------
  796. # *** Files needed for OASIS (linked)
  797. # ---------------------------------------------------------------------
  798. # Name table file
  799. ln -s ${ini_data_dir}/oasis/cf_name_table.txt
  800. # -- Get grid definition and weight files for IFS/NEMO or IFS/AMIP coupling
  801. has_config nemo && \
  802. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-ORCA${nem_res_hor} && \
  803. mycp='cp'
  804. has_config amip && \
  805. oas_grid_dir=${ini_data_dir}/oasis/AMIP && \
  806. mycp='cdo -f nc copy' # to enforce nc format, needed for 'cdo merge' to work (have nc4c with Primavera files)
  807. # Grid definition files
  808. if $(has_config tm5)
  809. then
  810. ${mycp} ${oas_grid_dir}/areas.nc gcm_areas.nc
  811. ${mycp} ${oas_grid_dir}/grids.nc gcm_grids.nc
  812. ${mycp} ${oas_grid_dir}/masks.nc gcm_masks.nc
  813. else
  814. ln -s ${oas_grid_dir}/areas.nc
  815. ln -s ${oas_grid_dir}/grids.nc
  816. ln -s ${oas_grid_dir}/masks.nc
  817. fi
  818. # Weight files
  819. case ${ifs_res_hor} in
  820. 159) oas_agrd=080
  821. ;;
  822. 255) oas_agrd=128
  823. ;;
  824. 511) oas_agrd=256
  825. ;;
  826. 799) oas_agrd=400
  827. ;;
  828. *) error "Unsupported horizontal resolution (IFS): ${ifs_res_hor}"
  829. ;;
  830. esac
  831. if $(has_config nemo)
  832. then
  833. case ${nem_res_hor} in
  834. 1) oas_ogrd=O1t0
  835. ;;
  836. 025) oas_ogrd=Ot25
  837. ;;
  838. *) error "Unsupported horizontal resolution (NEMO): ${nem_res_hor}"
  839. ;;
  840. esac
  841. fi
  842. if ${oas_link_weights}
  843. then
  844. for f in ${oas_grid_dir}/rmp_????_to_????_GAUSWGT.nc
  845. do
  846. ln -s $f
  847. done
  848. fi
  849. if $(has_config ifs nemo)
  850. then
  851. for f in ${oas_rst_ifs_nemo}
  852. do
  853. cp ${oas_grid_dir}/rst/$f .
  854. done
  855. fi
  856. # -- Get grid definition, weight and restart files for TM5 coupling
  857. if $(has_config tm5)
  858. then
  859. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-TM5-LPJG
  860. cp ${oas_grid_dir}/tm5_areas.nc .
  861. cp ${oas_grid_dir}/tm5_grids.nc .
  862. cp ${oas_grid_dir}/tm5_masks.nc .
  863. if ${oas_link_weights}
  864. then
  865. for f in ${oas_grid_dir}/rmp_????_to_????_*.nc
  866. do
  867. ln -s $f
  868. done
  869. fi
  870. # -- Get restart files for TM5-IFS/LPJG/PISCES
  871. for f in ${oas_rst_ifs_tm5}
  872. do
  873. cp ${oas_grid_dir}/rst/${tm5_exch_nlevs}-levels/$f .
  874. done
  875. # -- Merge grid definition files
  876. cdo merge gcm_areas.nc tm5_areas.nc areas.nc
  877. cdo merge gcm_grids.nc tm5_grids.nc grids.nc
  878. cdo merge gcm_masks.nc tm5_masks.nc masks.nc
  879. fi
  880. else # i.e. $leg_is_restart == true
  881. # ---------------------------------------------------------------------
  882. # *** Remove all leftover output files from previous legs
  883. # ---------------------------------------------------------------------
  884. # IFS files
  885. rm -f ICM{SH,GG}${exp_name}+??????
  886. # NEMO files
  887. rm -f ${exp_name}_??_????????_????????_{grid_U,grid_V,grid_W,grid_T,icemod,SBC,scalar,SBC_scalar,diad_T}.nc
  888. # TM5 restart file type
  889. tm5_istart=33
  890. if [ $tm5_istart -eq 31 ] && $(has_config tm5)
  891. then
  892. ln -sf save_${leg_start_date_yyyymmdd}00_glb300x200.hdf tm5_save.hdf
  893. fi
  894. fi # ! $leg_is_restart
  895. #--------------------------------------------------------------------------
  896. # *** Surface restoring and ocean nudging options
  897. #--------------------------------------------------------------------------
  898. if $(has_config nemo:ocenudg) ; then
  899. ln -fs ${ini_data_dir}/nemo/oce_nudg/temp_sal*.nc ./
  900. fi
  901. if $(has_config nemo:surfresto) ; then
  902. ln -fs ${ini_data_dir}/nemo/surface_restoring/sss_restore_data*.nc ./
  903. ln -fs ${ini_data_dir}/nemo/surface_restoring/sst_restore_data*.nc ./
  904. ln -fs ${ini_data_dir}/nemo/surface_restoring/mask_restore*.nc ./
  905. fi
  906. # -------------------------------------------------------------------------
  907. # *** Remove land grid-points
  908. # -------------------------------------------------------------------------
  909. if $(has_config nemo:elpin)
  910. then
  911. if [ ! -f coordinates_xios.nc ]
  912. then
  913. error "ELpIN requested, but file 'coordinates_xios.nc' was not found"
  914. fi
  915. jpns=($(${ecearth_src_dir}/util/ELPiN/ELPiNv2.cmd ${nem_numproc}))
  916. info "nemo domain decompostion from ELpIN: ${jpns[@]}"
  917. nem_numproc=${jpns[0]}
  918. nem_jpni=${jpns[1]}
  919. nem_jpnj=${jpns[2]}
  920. elif has_config nemo
  921. then
  922. info "nemo original domain decomposition (not using ELPiN)"
  923. fi
  924. # -------------------------------------------------------------------------
  925. # *** Initial conditions saved during the run
  926. # -------------------------------------------------------------------------
  927. ${do_save_ic} && save_ic_prepare_output
  928. # -------------------------------------------------------------------------
  929. # *** Create some control files
  930. # -------------------------------------------------------------------------
  931. # Create TM5 runtime rcfile
  932. tm5_start_date=$(date -u -d "${leg_start_date}" +%F\ %T)
  933. tm5_end_date=$(date -u -d "${leg_end_date}" +%F\ %T)
  934. if $(has_config tm5)
  935. then
  936. cp -f ${ctrl_file_dir}/tm5-config-run.rc ${run_dir}
  937. ${ecearth_src_dir}/tm5mp/setup_tm5 --no-compile \
  938. --time-start="${tm5_start_date}" --time-final="${tm5_end_date}" \
  939. --istart=${tm5_istart} ${run_dir}/tm5-config-run.rc
  940. fi
  941. # IFS frequency output for namelist
  942. if [ -f postins/pptdddddd0300 ]
  943. then
  944. ifs_output_freq=$(( 3 * 3600 / ifs_time_step_sec ))
  945. elif [ -f postins/pptdddddd0600 ]
  946. then
  947. ifs_output_freq=$(( 6 * 3600 / ifs_time_step_sec ))
  948. else
  949. error "IFS output frequency undefined."
  950. fi
  951. # IFS, NEMO, LIM, AMIP namelist and OASIS namcouple files
  952. has_config ifs && . ${ctrl_file_dir}/namelist.ifs.sh > fort.4
  953. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.ref.sh > namelist_ref
  954. has_config ifs nemo && . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-coupled.cfg.sh > namelist_cfg
  955. has_config lim3 && . ${ctrl_file_dir}/namelist.lim3.ref.sh > namelist_ice_ref
  956. has_config lim3 && . ${ctrl_file_dir}/namelist.lim3-${nem_grid}.cfg.sh > namelist_ice_cfg
  957. has_config rnfmapper && . ${ctrl_file_dir}/namelist.runoffmapper.sh > namelist.runoffmapper
  958. has_config amip && . ${ctrl_file_dir}/namelist.amip.sh > namelist.amip
  959. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.top.ref.sh > namelist_top_ref
  960. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.top.cfg.sh > namelist_top_cfg
  961. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.pisces.ref.sh > namelist_pisces_ref
  962. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.pisces.cfg.sh > namelist_pisces_cfg
  963. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.age.ref.sh > namelist_age_ref
  964. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.age.cfg.sh > namelist_age_cfg
  965. #include CFCs namelist even if CFCs are not included
  966. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.cfc.ref.sh > namelist_cfc_ref
  967. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.cfc.cfg.sh > namelist_cfc_cfg
  968. # C-cycle - overwrite coupled nemo namelist
  969. has_config pisces tm5:co2 && \
  970. . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-carboncycle.cfg.sh > namelist_cfg
  971. lucia=[[[MOD:OASIS:LUCIA]]]
  972. . ${ctrl_file_dir}/namcouple.sh > namcouple
  973. # -------------------------------------------------------------------------
  974. # *** LPJ-GUESS initial data
  975. # -------------------------------------------------------------------------
  976. if $(has_config lpjg)
  977. then
  978. # LPJG runtime rcfile - update with leg dates
  979. . ${ctrl_file_dir}/namelist.lpjg.sh > lpjg_steps.rc
  980. # determine lpjg scenario-name and co2-file middle-fix
  981. case $(echo ${ifs_cmip6_scenario} | tr '[:upper:]' '[:lower:]') in
  982. hist*) lpjg_scen="ssp370"; lu_src="AIM" ; lpjg_sco2_mfix="AIM-ssp370-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  983. ssp1-1.9*) lpjg_scen="ssp119"; lu_src="IMAGE" ; lpjg_sco2_mfix="IMAGE-ssp119-1-2-1" ; lu_file_posfix="2019_03_13.txt";;
  984. ssp1-2.6*) lpjg_scen="ssp126"; lu_src="IMAGE" ; lpjg_sco2_mfix="IMAGE-ssp126-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  985. ssp2-4.5*) lpjg_scen="ssp245"; lu_src="MESSAGE"; lpjg_sco2_mfix="MESSAGE-GLOBIOM-ssp245-1-2-1"; lu_file_posfix="2018_10_08.txt";;
  986. ssp3-7.0*) lpjg_scen="ssp370"; lu_src="AIM" ; lpjg_sco2_mfix="AIM-ssp370-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  987. ssp4-3.4*) lpjg_scen="ssp434"; lu_src="GCAM" ; lpjg_sco2_mfix="GCAM4-ssp434-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  988. ssp5-3.4*) lpjg_scen="ssp534os"; lu_src="MAGPIE"; lpjg_sco2_mfix="REMIND-MAGPIE-ssp534-over-1-2-1" ; lu_file_posfix="2019_05_10.txt";;
  989. ssp5-8.5*) lpjg_scen="ssp585"; lu_src="MAGPIE" ; lpjg_sco2_mfix="REMIND-MAGPIE-ssp585-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  990. *) error "Scenario ${ifs_cmip6_scenario} not defined for LPJ-GUESS" ;;
  991. esac
  992. lpjg_scenario_new="historical + $lpjg_sco2_mfix"
  993. lpjg_scenario_info=${run_dir}/lpjg_scenario.info
  994. if [ -f $lpjg_scenario_info ]
  995. then
  996. source $lpjg_scenario_info
  997. if [ "$lpjg_scenario_new" = "$lpjg_scenario" ]
  998. then
  999. lpjg_copy_rte=false
  1000. else
  1001. lpjg_copy_rte=true
  1002. fi
  1003. else
  1004. lpjg_copy_rte=true
  1005. fi
  1006. # copy RTE only if necessary (at beginning of a run or when scenario changes)
  1007. if $lpjg_copy_rte
  1008. then
  1009. # write info about installed scenarios to file
  1010. echo "lpjg_scenario=\"historical + $lpjg_sco2_mfix\"" > $lpjg_scenario_info
  1011. # set file prefixes depending on scenario
  1012. lu_file_prefix="1850_2100_luh2_Hist_ScenarioMIP_UofMD"
  1013. lu_file_midfix="2_1_f"
  1014. lu_path="${ini_data_dir}/lpjg/landuse/${lpjg_res}/${lpjg_scen}"
  1015. # copy and reference-link landuse, gross transitions, crops, n-fertilisation
  1016. for inp in lu gross crop nfert
  1017. do
  1018. if [ $inp == "crop" -o $inp == "nfert" ]
  1019. then
  1020. lu_src_file="${lu_path}/${inp}_rfirr_${lu_file_prefix}_${lu_src}_${lpjg_scen}_${lu_file_midfix}_${lpjg_res}_${lu_file_posfix}"
  1021. else
  1022. lu_src_file="${lu_path}/${inp}_${lu_file_prefix}_${lu_src}_${lpjg_scen}_${lu_file_midfix}_${lpjg_res}_${lu_file_posfix}"
  1023. fi
  1024. cp -f $lu_src_file ${run_dir}/landuse/${inp}_luh2.txt
  1025. ln -fs $lu_src_file ${run_dir}/landuse/${inp}_luh2.txt.lnk
  1026. done
  1027. # nitrogen deposition files
  1028. mkdir -p ${run_dir}/ndep
  1029. for inp in drynhx2 drynoy2 wetnhx2 wetnoy2
  1030. do
  1031. ndep_src_file="${ini_data_dir}/lpjg/ndep/${lpjg_res}/${lpjg_scen}/${lpjg_scen}_${lpjg_res}_${inp}.nc"
  1032. cp -f $ndep_src_file ${run_dir}/ndep/${inp}.nc
  1033. ln -fs $ndep_src_file ${run_dir}/ndep/${inp}.nc.lnk
  1034. done
  1035. # concatenate historic and scenario (2015+) co2 concentration file
  1036. # hist co2 file
  1037. lpjg_hco2_file="${ini_data_dir}/ifs/cmip6-data/mole-fraction-of-carbon-dioxide-in-air_input4MIPs_GHGConcentrations_CMIP_UoM-CMIP-1-2-0_gr1-GMNHSH_0000-2014.nc"
  1038. # scenario co2 file
  1039. lpjg_sco2_file="${ini_data_dir}/ifs/cmip6-data/mole-fraction-of-carbon-dioxide-in-air_input4MIPs_GHGConcentrations_ScenarioMIP_UoM-${lpjg_sco2_mfix}_gr1-GMNHSH_2015-2500.nc"
  1040. # combined file
  1041. lpjg_co2_file="${run_dir}/mole_fraction_of_carbon_dioxide_in_air_input4MIPs_lpjg.nc"
  1042. rm -f $lpjg_co2_file
  1043. cdo mergetime $lpjg_hco2_file $lpjg_sco2_file $lpjg_co2_file
  1044. fi
  1045. # Populate or update LPJG run directories
  1046. for (( n=1; n<=${lpjg_numproc}; n++ ))
  1047. do
  1048. # if run from scratch or number of procs has been extended
  1049. if ! $leg_is_restart || [ ! -d ${run_dir}/run${n} ]
  1050. then
  1051. # Make output directories
  1052. mkdir -p ${run_dir}/run${n}/output
  1053. # Copy *.ins, lpjg_steps.rc and OASIS-MCT restart files
  1054. cp ${run_dir}/*.ins ${run_dir}/run${n}
  1055. # Copy output control files
  1056. cp ${output_control_files_dir}/lpjg_cmip6_output.ins ${run_dir}/run${n}
  1057. ln -s ${output_control_files_dir}/lpjg_cmip6_output.ins ${run_dir}/run${n}/lpjg_cmip6_output.ins.lnk
  1058. cp ${ini_data_dir}/lpjg/oasismct/ghg*.txt ${run_dir}/run${n}
  1059. cp ${ini_data_dir}/lpjg/oasismct/${lpjg_res}/ece_gridlist_${lpjg_res}.txt ${run_dir}/run${n}/ece_gridlist.txt
  1060. ln -s ${ini_data_dir}/lpjg/oasismct/${lpjg_res}/ece_gridlist_${lpjg_res}.txt ${run_dir}/run${n}/ece_gridlist.txt.lnk
  1061. # Data only needed by master
  1062. if [ $n == 1 ]
  1063. then
  1064. cp ${ini_data_dir}/lpjg/oasismct/${lpjg_res}/*.nc ${run_dir}
  1065. cp ${ini_data_dir}/lpjg/oasismct/lpjgv.txt ${run_dir}/run${n}
  1066. fi
  1067. fi
  1068. # Refresh output-dirs after they hav been removed at end of the last leg
  1069. mkdir -p ${run_dir}/run${n}/output/CMIP6
  1070. mkdir -p ${run_dir}/run${n}/output/CRESCENDO
  1071. done
  1072. if $leg_is_restart
  1073. then
  1074. lpjg_restart_dir="restart/lpjg/$(printf %03d $((leg_number-1)))"
  1075. lpjg_rst_state="${lpjg_restart_dir}/lpjg_state_${leg_start_date_yyyy}"
  1076. if [ -d "$lpjg_rst_state" ]
  1077. then
  1078. ln -sf $lpjg_rst_state
  1079. else
  1080. echo "lpjg restart dir $lpjg_rst_state not available"
  1081. exit -1
  1082. fi
  1083. # get oasis restart files
  1084. oasis_restart_dir="restart/oasis/$(printf %03d $((leg_number)))"
  1085. cp -f ${oasis_restart_dir}/*.nc ${run_dir}/
  1086. fi
  1087. fi
  1088. # -------------------------------------------------------------------------
  1089. # *** Create ICMCL file with vegetation fields
  1090. # not needed if LPJG is used with feedback
  1091. # -------------------------------------------------------------------------
  1092. tempfile=tmp.$$
  1093. case ${ifs_veg_source} in
  1094. "ifs" )
  1095. # Vegetation from IFS (climatology)
  1096. icmclfile=${ini_data_dir}/ifs/${ifs_grid}/climate/ICMCL_ONLY_VEG_PD
  1097. # Create data for december, the year before the leg starts
  1098. ${grib_set} \
  1099. -s dataDate=$(printf "%04d" $((leg_start_date_yyyy-1)))1215 \
  1100. ${icmclfile}-12 ICMCL${exp_name}INIT
  1101. # Create data for all month in the years of the leg
  1102. for (( y=${leg_start_date_yyyy} ; y<=${leg_end_date_yyyy} ; y++ ))
  1103. do
  1104. yy=$(printf "%04d" $y)
  1105. for m in {1..12}
  1106. do
  1107. mm=$(printf "%02d" $m)
  1108. ${grib_set} -s dataDate=${yy}${mm}15 ${icmclfile}-${mm} ${tempfile}
  1109. cat ${tempfile} >> ICMCL${exp_name}INIT
  1110. done
  1111. done
  1112. # Create data for january, the year after the leg ends
  1113. ${grib_set} \
  1114. -s dataDate=$(printf "%04d" $((leg_end_date_yyyy+1)))0115 \
  1115. ${icmclfile}-01 ${tempfile}
  1116. cat ${tempfile} >> ICMCL${exp_name}INIT
  1117. ;;
  1118. "era20c"|"cmip6"|"custom_"* )
  1119. # Vegetation from a LPJG run (off-line or EC-Earth3-Veg)
  1120. rm -f ICMCL${exp_name}INIT
  1121. # Create data for all years of the leg, including one year
  1122. # before and one year after
  1123. for (( yr=leg_start_date_yyyy-1 ; yr<=leg_end_date_yyyy+1 ; yr+=1 ))
  1124. do
  1125. case ${ifs_veg_source} in
  1126. 'era20c' )
  1127. # no scenario needed with era20c
  1128. icmcl_scenario="" ;;
  1129. 'custom_'* )
  1130. # no scenario implemented yet with custom_dir
  1131. icmcl_scenario="" ;;
  1132. 'cmip6' )
  1133. # select scenario, use SSP3-7.0 as default
  1134. # if not otherwise specified
  1135. icmcl_scenario="historical"
  1136. if ( [ $ifs_cmip_fixyear -le 0 ] && [ $yr -ge 2015 ] ) || \
  1137. [ $ifs_cmip_fixyear -ge 2015 ]
  1138. then
  1139. [[ ${ifs_cmip6_scenario} =~ ^SSP ]] \
  1140. && icmcl_scenario=${ifs_cmip6_scenario} \
  1141. || if [ ${ifs_covid19} == TRUE ]
  1142. then
  1143. icmcl_scenario='SSP2-4.5'
  1144. else
  1145. icmcl_scenario='SSP3-7.0'
  1146. fi
  1147. fi ;;
  1148. esac
  1149. if [ $ifs_cmip_fixyear -le 0 ] || [[ ${ifs_veg_source} == custom_* ]]
  1150. then
  1151. cat ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version}/${icmcl_scenario}/icmcl_$yr.grb >> ICMCL${exp_name}INIT
  1152. else
  1153. # Fixed year forcing, requires cdo! (only when not using ifs_veg_source=custom_exp*)
  1154. # If cdo is not available at runtime you need to fix proper
  1155. # icmcl files beforehand and use them here
  1156. cdo setyear,$yr ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version}/${icmcl_scenario}/icmcl_${ifs_cmip_fixyear}.grb ${tempfile}
  1157. cat ${tempfile} >> ICMCL${exp_name}INIT
  1158. fi
  1159. done
  1160. ;;
  1161. "none" )
  1162. info "no ICMCL file is created"
  1163. ;;
  1164. * )
  1165. error "Vegetation from ${ifs_veg_source} not implemented"
  1166. ;;
  1167. esac
  1168. # Clean up
  1169. rm -f ${tempfile}
  1170. # -------------------------------------------------------------------------
  1171. # *** Link the appropriate NEMO restart files of the previous leg
  1172. # -------------------------------------------------------------------------
  1173. if $leg_is_restart && $(has_config nemo)
  1174. then
  1175. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  1176. for (( n=0 ; n<nem_numproc ; n++ ))
  1177. do
  1178. np=$(printf %04d ${n})
  1179. ln -fs ${exp_name}_${ns}_restart_oce_${np}.nc restart_oce_${np}.nc
  1180. ln -fs ${exp_name}_${ns}_restart_ice_${np}.nc restart_ice_${np}.nc
  1181. has_config pisces && \
  1182. ln -fs ${exp_name}_${ns}_restart_trc_${np}.nc restart_trc_${np}.nc
  1183. done
  1184. # Make sure there are no global restart files
  1185. # If links are found, they will be removed. We are cautious and do
  1186. # _not_ remove real files! However, if real global restart files are
  1187. # present, NEMO/LIM will stop because time stamps will not match.
  1188. [ -h restart_oce.nc ] && rm restart_oce.nc
  1189. [ -h restart_ice.nc ] && rm restart_ice.nc
  1190. [ -h restart_trc.nc ] && rm restart_trc.nc
  1191. fi
  1192. # -------------------------------------------------------------------------
  1193. # *** Remove some OASIS files of the previous leg
  1194. # -------------------------------------------------------------------------
  1195. if $leg_is_restart
  1196. then
  1197. rm -f anaisout_*
  1198. fi
  1199. # -------------------------------------------------------------------------
  1200. # *** Remove any ccycle debug output files
  1201. # -------------------------------------------------------------------------
  1202. if ${ccycle_debug_fluxes} && $leg_is_restart && $(has_config tm5:co2)
  1203. then
  1204. if $(has_config lpjg)
  1205. then
  1206. rm -f GUE_{CNAT,CANT,CNPP}_*.nc run1/GUE_{CNAT,CANT,CNPP}_*.nc
  1207. rm -f TM5_Land{CNAT,CANT,CNPP}_*.nc
  1208. fi
  1209. if $(has_config pisces)
  1210. then
  1211. rm -f O_CO2FLX_*.nc
  1212. rm -f TM5_OceCFLX_*.nc
  1213. fi
  1214. fi
  1215. # -------------------------------------------------------------------------
  1216. # *** Check consistency of OASIS restarts and IFS rcf with ece_info_file
  1217. # -------------------------------------------------------------------------
  1218. if $leg_is_restart
  1219. then
  1220. info "Check OASIS restarts and IFS rcf before launch"
  1221. leg_nb_3d=$(printf %03d $((leg_number)))
  1222. for oasis_restart_file in restart/oasis/${leg_nb_3d}/*
  1223. do
  1224. [ ! -f "${oasis_restart_file}" ] && break
  1225. if ! diff -q $(basename ${oasis_restart_file}) ${oasis_restart_file} >/dev/null
  1226. then
  1227. echo "*WARNING* Overwriting OASIS restart (${oasis_restart_file})"
  1228. cp -f ${oasis_restart_file} .
  1229. fi
  1230. done
  1231. rcf_restart_file=restart/ifs/${leg_nb_3d}/rcf
  1232. if [ -f "${rcf_restart_file}" ]
  1233. then
  1234. if ! diff -q rcf ${rcf_restart_file} >/dev/null
  1235. then
  1236. echo "*WARNING* Overwriting IFS rcf file (${rcf_restart_file})"
  1237. cp -f ${rcf_restart_file} .
  1238. fi
  1239. fi
  1240. fi
  1241. # -------------------------------------------------------------------------
  1242. # *** Start the run
  1243. # -------------------------------------------------------------------------
  1244. export DR_HOOK_IGNORE_SIGNALS='-1'
  1245. export CPLNG='active'
  1246. # Use the launch function from the platform configuration file
  1247. has_config nemo && \
  1248. cmd="${xio_numproc} ${xio_exe_file} -- \
  1249. ${nem_numproc} ${nem_exe_file} -- \
  1250. ${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name}" || \
  1251. cmd="${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name}"
  1252. has_config lpjg && cmd=${cmd}" -- ${lpjg_numproc} ${lpjg_exe_file} guess.ins -parallel"
  1253. has_config tm5 && cmd=${cmd}" -- ${tm5_numproc} ${tm5_exe_file} tm5-run.rc"
  1254. has_config amip && cmd=${cmd}" -- ${amip_numproc} ${amip_exe_file}"
  1255. has_config nemo && cmd=${cmd}" -- ${rnf_numproc} ${rnf_exe_file}"
  1256. t1=$(date +%s)
  1257. launch $cmd
  1258. t2=$(date +%s)
  1259. tr=$(date -d "0 -$t1 sec + $t2 sec" +%T)
  1260. # -------------------------------------------------------------------------
  1261. # *** Check for signs of success
  1262. # Note the tests provide no guarantee that things went fine! They are
  1263. # just based on the IFS, NEMO and TM5 log files. More tests (e.g. checking
  1264. # restart files) could be implemented.
  1265. # -------------------------------------------------------------------------
  1266. # Checking for IFS success
  1267. if [ -f ifs.stat ]
  1268. then
  1269. if [ "$(awk 'END{print $3}' ifs.stat)" == "CNT0" ]
  1270. then
  1271. info "Leg successfully completed according to IFS log file 'ifs.stat'."
  1272. else
  1273. error "Leg not completed according to IFS log file 'ifs.stat'."
  1274. fi
  1275. else
  1276. error "IFS log file 'ifs.stat' not found after run."
  1277. fi
  1278. # Check for NEMO success
  1279. if $(has_config nemo)
  1280. then
  1281. if [ -f ocean.output ]
  1282. then
  1283. 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)" ]
  1284. then
  1285. info "Leg successfully completed according to NEMO log file 'ocean.output'."
  1286. else
  1287. error "Leg not completed according to NEMO log file 'ocean.output'."
  1288. fi
  1289. else
  1290. error "NEMO log file 'ocean.output' not found after run."
  1291. fi
  1292. fi
  1293. # Check for TM5 success
  1294. if $(has_config tm5)
  1295. then
  1296. if [ -f tm5.ok ]
  1297. then
  1298. info "Leg successfully completed according to existing TM5 file 'tm5.ok'."
  1299. else
  1300. error "Leg not completed according to non-existing TM5 file 'tm5.ok'."
  1301. fi
  1302. fi
  1303. # -------------------------------------------------------------------------
  1304. # *** Post-process initial conditions saved during the run if requested
  1305. # -------------------------------------------------------------------------
  1306. ${do_save_ic} && save_ic_postproc
  1307. # -------------------------------------------------------------------------
  1308. # *** Move IFS output files to archive directory
  1309. # -------------------------------------------------------------------------
  1310. outdir="output/ifs/$(printf %03d $((leg_number)))"
  1311. mkdir -p ${outdir}
  1312. prv_leg=$(printf %03d $((leg_number-1)))
  1313. # This takes care of a special IFS feature: The output for the last time
  1314. # step of each leg is written at the first time step of the new leg. The
  1315. # following code makes sure that the output is appended to the appropriate
  1316. # file. Since GRIB files are just streams, its done with a simple cat
  1317. # command.
  1318. for f in ICMSH${exp_name}+?????? ICMGG${exp_name}+??????
  1319. do
  1320. if [ -f output/ifs/${prv_leg}/${f} ]
  1321. then
  1322. cat ${f} >> output/ifs/${prv_leg}/${f}
  1323. rm -f ${f}
  1324. else
  1325. mv ${f} ${outdir}
  1326. fi
  1327. done
  1328. # -------------------------------------------------------------------------
  1329. # *** Move NEMO output files to archive directory
  1330. # -------------------------------------------------------------------------
  1331. if $(has_config nemo)
  1332. then
  1333. outdir="output/nemo/$(printf %03d $((leg_number)))"
  1334. mkdir -p ${outdir}
  1335. for v in grid_U grid_V grid_W grid_T icemod SBC scalar SBC_scalar diad_T ptrc_T bioscalar \
  1336. grid_T_2D grid_U_2D grid_V_2D grid_W_2D grid_T_3D grid_U_3D grid_V_3D grid_W_3D \
  1337. grid_T_SFC grid_1point grid_T_3D_ncatice vert_sum \
  1338. grid_ptr_W_3basin_3D grid_ptr_T_3basin_2D grid_ptr_T_2D \
  1339. zoom_700_sum zoom_300_sum zoom_2000_sum
  1340. do
  1341. for f in ${exp_name}_*_????????_????????_*${v}.nc
  1342. do
  1343. test -f $f && mv $f $outdir/
  1344. done
  1345. done
  1346. fi
  1347. # -------------------------------------------------------------------------
  1348. # *** Move LPJ-GUESS output files to archive directory
  1349. # -------------------------------------------------------------------------
  1350. if $(has_config lpjg)
  1351. then
  1352. outdir="output/lpjg/$(printf %03d $((leg_number)))"
  1353. if [ -d ${outdir} ]
  1354. then
  1355. rm -rf ${outdir}
  1356. fi
  1357. mkdir -p ${outdir}
  1358. # LPJG run directories
  1359. # concatenate *.out (or compressed *.out.gz) files from each run* into output dir
  1360. flist=$(cd ${run_dir}/run1/output && find *.out.gz -type f 2>/dev/null || true)
  1361. if [ "$flist" = "" ]
  1362. then
  1363. lpjg_compress_output=false
  1364. flist=$(cd ${run_dir}/run1/output && find *.out -type f 2>/dev/null)
  1365. else
  1366. lpjg_compress_output=true
  1367. fi
  1368. mkdir ${outdir}/CMIP6
  1369. for (( n=1; n<=${lpjg_numproc}; n++ ))
  1370. do
  1371. for ofile in $flist
  1372. do
  1373. if $lpjg_compress_output
  1374. then
  1375. [ $n == 1 ] && gzip -c ${run_dir}/run${n}/output/`basename ${ofile} .gz`.hdr > ${outdir}/$ofile
  1376. cat ${run_dir}/run${n}/output/${ofile} >> ${outdir}/$ofile
  1377. else
  1378. if (( n == 1 ))
  1379. then
  1380. cat ${run_dir}/run${n}/output/${ofile} > ${outdir}/$ofile
  1381. else
  1382. awk '(FNR!=1){print $0}' ${run_dir}/run${n}/output/${ofile} >> ${outdir}/$ofile
  1383. fi
  1384. fi
  1385. done
  1386. rm -rf ${run_dir}/run${n}/output
  1387. done
  1388. # move monthly file if available
  1389. if [ -f ${run_dir}/LPJ-GUESS_monthlyoutput.txt ]
  1390. then
  1391. mv ${run_dir}/LPJ-GUESS_monthlyoutput.txt ${outdir}
  1392. fi
  1393. fi
  1394. # -------------------------------------------------------------------------
  1395. # *** Move TM5 output files to archive directory
  1396. # -------------------------------------------------------------------------
  1397. if $(has_config tm5)
  1398. then
  1399. outdir="output/tm5/$(printf %03d $((leg_number)))"
  1400. mkdir -p ${outdir}
  1401. set +e
  1402. mv budget_??????????_??????????_global.hdf ${outdir}
  1403. mv j_statistics_??????????_??????????.hdf ${outdir}
  1404. mv mmix_??????????_??????????_glb???x???.hdf ${outdir}
  1405. mv aerocom?_TM5_*_????????_daily.nc ${outdir}
  1406. mv aerocom?_TM5_*_??????_monthly.nc ${outdir}
  1407. mv AOD_????_??_??.nc ${outdir}
  1408. mv -f TM5MP_${exp_name}_griddef.nc ${outdir}
  1409. mv TM5MP_${exp_name}_TP_????_??_??.nc ${outdir}
  1410. mv TM5MP_${exp_name}_vmr3_????_??_??.nc ${outdir}
  1411. mv general_TM5_${exp_name}_??????????_hourly.nc ${outdir}
  1412. mv general_TM5_${exp_name}_??????_monthly.nc ${outdir}
  1413. mv *EC-Earth3-*_${exp_name}_*.nc ${outdir}
  1414. set -e
  1415. # move profiling files if any
  1416. if [ "$(ls -A ${run_dir}/tm5_profile)" ]
  1417. then
  1418. outdir="output/tm5/profile_$(printf %03d $((leg_number)))"
  1419. mkdir -p ${outdir}
  1420. for f in ${run_dir}/tm5_profile/*
  1421. do
  1422. test -f ${f} && mv $f ${outdir}
  1423. done
  1424. fi
  1425. fi
  1426. # -------------------------------------------------------------------------
  1427. # *** Move IFS restart files to archive directory
  1428. # -------------------------------------------------------------------------
  1429. if $leg_is_restart
  1430. then
  1431. outdir="restart/ifs/$(printf %03d $((leg_number)))"
  1432. mkdir -p ${outdir}
  1433. # Figure out the time part of the restart files (cf. CTIME on rcf files)
  1434. # NOTE: Assuming that restarts are at full days (time=0000) only!
  1435. nd="$(printf %06d $((leg_start_sec/(24*3600))))0000"
  1436. mv srf${nd}.???? ${outdir}
  1437. fi
  1438. # -------------------------------------------------------------------------
  1439. # *** Move ccycle debug output files to archive directory
  1440. # -------------------------------------------------------------------------
  1441. if ${ccycle_debug_fluxes} && $(has_config tm5:co2)
  1442. then
  1443. outdir="output/tm5/$(printf %03d $((leg_number)))"
  1444. mkdir -p ${outdir}
  1445. if $(has_config lpjg)
  1446. then
  1447. for f in CNAT CANT CNPP ; do
  1448. mv TM5_Land${f}_*.nc ${outdir}
  1449. rm -f GUE_${f}_*.nc run1/GUE_${f}_*.nc
  1450. #gf=`ls -1 GUE_${f}_*.nc | head -n 1`
  1451. #cdo mergetime ${gf} run1/${gf} ${outdir}/${gf}
  1452. done
  1453. fi
  1454. if $(has_config pisces)
  1455. then
  1456. mv TM5_OceCFLX_*.nc ${outdir}
  1457. rm -f O_CO2FLX_*.nc
  1458. #mv O_CO2FLX_*.nc ${outdir}
  1459. fi
  1460. fi
  1461. # -------------------------------------------------------------------------
  1462. # *** Move LPJ-GUESS restart files to archive directory
  1463. # -------------------------------------------------------------------------
  1464. if $(has_config lpjg)
  1465. then
  1466. outdir="restart/lpjg/$(printf %03d $((leg_number)))"
  1467. if [ -d ${outdir} ]
  1468. then
  1469. rm -rf ${outdir}
  1470. fi
  1471. mkdir -p ${outdir}
  1472. state_dir="./lpjg_state_$(printf %04d $((leg_end_date_yyyy)))"
  1473. mv ${state_dir} ${outdir}
  1474. # LPJG writes into run1 dir, so mv to main rundir
  1475. mv -f run1/lpjgv.nc .
  1476. has_config tm5:co2 lpjg && mv -f run1/rlpjg.nc .
  1477. # remove restart link
  1478. if $leg_is_restart
  1479. then
  1480. old_state_dir="./lpjg_state_$(printf %04d $((leg_start_date_yyyy)))"
  1481. if [ -L $old_state_dir ]
  1482. then
  1483. rm -f "$old_state_dir"
  1484. fi
  1485. fi
  1486. fi
  1487. # -------------------------------------------------------------------------
  1488. # *** Move NEMO restart files to archive directory
  1489. # -------------------------------------------------------------------------
  1490. if $leg_is_restart && $(has_config nemo)
  1491. then
  1492. outdir="restart/nemo/$(printf %03d $((leg_number)))"
  1493. mkdir -p ${outdir}
  1494. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  1495. for f in oce ice
  1496. do
  1497. mv ${exp_name}_${ns}_restart_${f}_????.nc ${outdir}
  1498. done
  1499. if has_config pisces
  1500. then
  1501. mv ${exp_name}_${ns}_restart_trc_????.nc ${outdir}
  1502. fi
  1503. fi
  1504. # -------------------------------------------------------------------------
  1505. # *** Move TM5 restart file to archive directory
  1506. # -------------------------------------------------------------------------
  1507. if $leg_is_restart && $(has_config tm5)
  1508. then
  1509. outdir="restart/tm5/$(printf %03d $((leg_number)))"
  1510. mkdir -p ${outdir}
  1511. case ${tm5_istart} in
  1512. 33|32) f=TM5_restart_${leg_start_date_yyyymmdd}_0000_glb300x200.nc
  1513. ;;
  1514. 31) f=save_${leg_start_date_yyyymmdd}00_glb300x200.hdf
  1515. ;;
  1516. esac
  1517. mv $f ${outdir}
  1518. fi
  1519. # -------------------------------------------------------------------------
  1520. # *** Copy OASIS restart files to archive directory
  1521. # NOTE: These files are copied and not moved as they are used in the
  1522. # next leg!
  1523. # Note also that the OASIS restart files present at the end of
  1524. # the leg correspond to the start of the next leg!
  1525. # -------------------------------------------------------------------------
  1526. outdir="restart/oasis/$(printf %03d $((leg_number+1)))"
  1527. mkdir -p ${outdir}
  1528. for f in ${oas_rst_files}
  1529. do
  1530. test -f ${f} && cp ${f} ${outdir}
  1531. done
  1532. # -------------------------------------------------------------------------
  1533. # *** Copy rcf files to the archive directory (of the next leg!)
  1534. # -------------------------------------------------------------------------
  1535. outdir="restart/ifs/$(printf %03d $((leg_number+1)))"
  1536. mkdir -p ${outdir}
  1537. for f in rcf
  1538. do
  1539. test -f ${f} && cp ${f} ${outdir}
  1540. done
  1541. # -------------------------------------------------------------------------
  1542. # *** Move log files to archive directory
  1543. # -------------------------------------------------------------------------
  1544. outdir="log/$(printf %03d $((leg_number)))"
  1545. mkdir -p ${outdir}
  1546. for f in \
  1547. ifs.log ifs.stat fort.4 ocean.output \
  1548. time.step solver.stat guess.log run1/guess0.log \
  1549. amip.log namelist.amip \
  1550. nout.000000 debug.root.?? \
  1551. ctm.tm5.log.0
  1552. do
  1553. test -f ${f} && mv ${f} ${outdir}
  1554. done
  1555. has_config pisces && cp ocean.carbon ${outdir}
  1556. for f in ctm.tm5.log.*
  1557. do
  1558. if [[ -f ${f} ]]
  1559. then
  1560. [[ -s ${f} ]] && mv ${f} ${outdir} || \rm -f ${f}
  1561. fi
  1562. done
  1563. # -------------------------------------------------------------------------
  1564. # *** Write the restart control file
  1565. # -------------------------------------------------------------------------
  1566. # Compute CPMIP performance
  1567. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  1568. ncores=0
  1569. has_config nemo && (( ncores+=${nem_numproc} )) || :
  1570. has_config ifs && (( ncores+=${ifs_numproc} )) || :
  1571. has_config xios && (( ncores+=${xio_numproc} )) || :
  1572. has_config rnfmapper && (( ncores+=${rnf_numproc} )) || :
  1573. has_config lpjg && (( ncores+=${lpjg_numproc} )) || :
  1574. has_config tm5 && (( ncores+=${tm5_numproc} )) || :
  1575. has_config amip && (( ncores+=${amip_numproc} )) || :
  1576. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1)) $ncores)"
  1577. echo "#" | tee -a ${ece_info_file}
  1578. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  1579. | tee -a ${ece_info_file}
  1580. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  1581. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  1582. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  1583. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  1584. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  1585. force_run_from_scratch=false
  1586. # -------------------------------------------------------------------------
  1587. # *** Trigger post-processing jobs
  1588. # -------------------------------------------------------------------------
  1589. #postprocess
  1590. done # loop over legs
  1591. # -----------------------------------------------------------------------------
  1592. # *** Platform dependent finalising of the run
  1593. # -----------------------------------------------------------------------------
  1594. finalise
  1595. exit 0