ece-esm.sh.tmpl 79 KB

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