ece-esm.sh.tmpl 62 KB

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