ece-lsm.sh.tmpl 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. #!/usr/bin/env bash
  2. set -ue
  3. # librunscript defines some helper functions
  4. source ./librunscript.sh
  5. # =============================================================================
  6. # *** BEGIN User configuration
  7. # =============================================================================
  8. # -----------------------------------------------------------------------------
  9. # *** General configuration
  10. # -----------------------------------------------------------------------------
  11. # Component configuration (for syntax of the $config variable, see librunscript.sh)
  12. #
  13. # Currently maintained:
  14. # config="osm" # OSM (Offline Surface Model, H-TESSEL), forced by IFS output or reanalysis data
  15. # config="lpjg" # LPJG-Offline, forced by IFS or OSM output (lpjg_forcing)
  16. # In this config lpjg can take the option lpjg:spinup to run an offline spinup
  17. # config="lpjg:fdbck osm" # LPJG & OSM Coupled via OASIS - option lpjg:fdbck is used to feedback on the OSM
  18. config="lpjg:fdbck osm"
  19. # dummy tm5 coupling - co2 ppm + fluxes
  20. ccycle_co2_init_ppm=0
  21. oas_rst_ifs_tm5=''
  22. if has_config lpjg:cc_coup
  23. then
  24. # define initial CO2 concentrations in ppm
  25. ccycle_co2_init_ppm=284.32
  26. # set to true to write co2 fluxes
  27. ccycle_debug_fluxes=true
  28. config+=" tm5:co2 cc_coup"
  29. export tm5_exch_nlevs=10
  30. tm5_time_step_sec=[[[MOD:LPJG:TIME_STEP_SEC]]]
  31. oas_rst_ifs_tm5=$oas_rst_ifs_tm5' l_co2.nc rlpjg.nc'
  32. fi
  33. # minimum sanity
  34. has_config ifs && error "Cannot have ifs in config"
  35. has_config nemo && error "Cannot have nemo in config"
  36. has_config lpjg:spinup osm && error "Cannot have both lpjg:spinup and osm in config"
  37. # add lpjg_forcing to config when needed (lpjg non-spinup and no osm) - do not specify it in the config directly
  38. has_config lpjg_forcing && error "lpjg:lpjg_forcing not allowed in user config"
  39. has_config lpjg && ! has_config lpjg:spinup && ! has_config osm && config+=" lpjg_forcing"
  40. has_config lpjg_forcing osm && error "Cannot have both lpjg_forcing and osm in config"
  41. has_config lpjg:spinup lpjg_forcing && error "Cannot have both lpjg:spinup and lpjg_forcing in config"
  42. # liblsm.sh defines some OSM and LPJG pre/post-processing functions
  43. has_config any osm lpjg lpjg_forcing && source ./liblsm.sh
  44. # Experiment name (exactly 4 letters!)
  45. export exp_name=[[[MOD:GENERAL:EXP_NAME]]]
  46. # Simulation start and end date. Use any (reasonable) syntax you want.
  47. run_start_date="[[[MOD:GENERAL:RUN_START_DATE]]]"
  48. # define run_start_date_as with proper format e.g. 19900101
  49. export run_start_date_as=$(date -u -d "${run_start_date}" +%Y%m%d)
  50. run_end_date="[[[MOD:GENERAL:RUN_END_DATE]]]"
  51. # Set $force_run_from_scratch to 'true' if you want to force this run to start
  52. # from scratch, possibly ignoring any restart files present in the run
  53. # directory. Leave set to 'false' otherwise.
  54. # NOTE: If set to 'true' the run directory $run_dir is cleaned!
  55. force_run_from_scratch=[[[MOD:GENERAL:FORCE_RUN_FROM_SCRATCH]]]
  56. # Resolution (only T159 and T255 supported)
  57. ifs_grid=[[[MOD:IFS:GRID]]]
  58. #atm_grid=A128
  59. # Restart frequency. Use any (reasonable) number and time unit you want.
  60. # For runs without restart, leave this variable empty
  61. rst_freq="[[[MOD:GENERAL:RST_FREQ]]]"
  62. # Number of restart legs to be run in one go
  63. run_num_legs=[[[MOD:GENERAL:RUN_NUM_LEGS]]]
  64. # Coupling frequencies
  65. has_config lpjg && cpl_freq_atm_lpjg_hrs=[[[MOD:OASIS:CPL_FREQ_ATM_LPJG_HRS]]] #24
  66. # Directories
  67. start_dir=${PWD}
  68. ctrl_file_dir=${start_dir}/ctrl
  69. output_control_files_dir=${start_dir}/[[[MOD:GENERAL:OUTPUT_CONTROL_FILES_DIR]]]
  70. # Architecture
  71. build_arch=[[[PLT:ACTIVE:BUILD_ARCH]]]
  72. use_machinefile=[[[PLT:ACTIVE:USE_MACHINEFILE]]]
  73. # This file is used to store information about restarts
  74. ece_info_file="ece.info"
  75. # -----------------------------------------------------------------------------
  76. # *** Read platform dependent configuration
  77. # -----------------------------------------------------------------------------
  78. source ./ecconf.cfg
  79. configure
  80. [ -z $TMPDIR ] && error "you must define TMPDIR for your platform!!!"
  81. # -----------------------------------------------------------------------------
  82. # *** IFS/OSM configuration - some variables are needed by LPJG
  83. # -----------------------------------------------------------------------------
  84. ifs_version=36r4
  85. export ifs_res_hor=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\1:')
  86. ifs_res_ver=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\2:')
  87. osm_numproc=[[[MOD:OSM:NUMPROC]]] #
  88. has_config lpjg && osm_exe_file=${ecearth_src_dir}/ifs-${ifs_version}/src/surf/offline/osm/build/bin/master1s_cpl.exe \
  89. || osm_exe_file=${ecearth_src_dir}/ifs-${ifs_version}/src/surf/offline/osm/build/bin/master1s.exe
  90. osm_forcing_type="[[[MOD:OSM:OSM_FORCING_TYPE]]]"
  91. osm_ifs_output_dir="[[[MOD:OSM:OSM_IFS_OUTPUT_DIR]]]"
  92. osm_forcing_dir="[[[MOD:OSM:OSM_FORCING_DIR]]]"
  93. #uncomment these lines to use era20c/erai forcings, which are generated with the generate_forcing.sh script
  94. #osm_forcing_type="era20c"
  95. #osm_ifs_output_dir=""
  96. #osm_forcing_dir="${SCRATCH}/ECEARTH-RUNS/OSM_FORCING/${osm_forcing_type}/${ifs_grid}"
  97. export ifs_cmip_fixyear=[[[MOD:IFS:CMIP_FIXYEAR]]]
  98. ifs_cmip6=[[[MOD:IFS:CMIP6]]]
  99. ifs_cmip6_scenario=[[[MOD:IFS:CMIP6_SCENARIO]]]
  100. ifs_cmip_fixyear_ch4=[[[MOD:IFS:CMIP_FIXYEAR_CH4]]]
  101. ifs_A4xCO2=[[[MOD:IFS:CMIP6_A4xCO2]]]
  102. ifs_1PCTCO2=[[[MOD:IFS:CMIP6_1PCTCO2]]]
  103. bgc_1PCTCO2=[[[MOD:IFS:CMIP6_1PCTCO2_BGC]]]
  104. # *** Time step settings
  105. # setting ifs_time_step_sec breaks LPJG-offline oasis config so only set it when osm is active for now
  106. # usually we use the IFS time step setting for the target resolution, but for ERA5 forcing
  107. # we use 1h which is the resolution of the forcing
  108. if has_config osm
  109. then
  110. case "${ifs_grid}" in
  111. T159L*) ifs_time_step_sec=3600 ;;
  112. T255L*) ifs_time_step_sec=2700 ;;
  113. T511L*) ifs_time_step_sec=900 ;;
  114. *) error "Can't set time steps for unknown horizontal grid: ${ifs_grid}"
  115. ;;
  116. esac
  117. if [[ "$osm_forcing_type" != "ifs" ]]
  118. then
  119. info "Setting OSM time step to 1h because we are using reanalysis forcing"
  120. ifs_time_step_sec=3600
  121. fi
  122. # ifs_output_freq is defined below for ifs in the esm runscript, here it is hard-coded for osm
  123. ifs_output_freq=$(( 3 * 3600 / ifs_time_step_sec ))
  124. #ifs_di_freq=$(( 24 * 3600 / ifs_time_step_sec ))
  125. #ifs_ddh_freq=$(( 120 * 3600 / ifs_time_step_sec ))
  126. fi
  127. # Select source of vegetation data:
  128. # ifs climatology from IFS
  129. # era20c vegetation from an off-line LPJ-Guess run forced with ERA20C
  130. # (currently available only for T255 and T159)
  131. # cmip6 vegetation from an EC-Earth3-Veg (interactive LPJ-Guess) run
  132. # (currently available only for T255)
  133. # custom_exp vegetation from any EC-Earth3-Veg run exp
  134. # (must contain same variables as era20c & cmip6 and located in icmcl_exp folder)
  135. # none don't create an ICMCL file with vegetation data (this is set
  136. # automatically if LPJG is used with feedback)
  137. #
  138. ifs_veg_source="cmip6"
  139. has_config lpjg:fdbck && ! has_config osm && ifs_veg_source="none"
  140. case ${ifs_veg_source} in
  141. "ifs" )
  142. # Use Lambert-Beer to compute effective vegetation cover
  143. n_compute_eff_veg_fraction=2
  144. ;;
  145. "era20c" )
  146. # LPJG vegetation is provided as effective cover
  147. # Don't use Lambert-Beer
  148. n_compute_eff_veg_fraction=0
  149. case "${ifs_grid}" in
  150. T159L*) veg_version=v29 ;;
  151. T255L*) veg_version=v16 ;;
  152. *) error "Vegetation from off-line LPJ-Guess not available for ${ifs_grid}" ;;
  153. esac
  154. ;;
  155. "cmip6" )
  156. # LPJG vegetation is provided as effective cover
  157. # Don't use Lambert-Beer
  158. n_compute_eff_veg_fraction=0
  159. case "${ifs_grid}" in
  160. T255L*) veg_version=v32 ;;
  161. *) error "Vegetation from CMIP6 EC-Earth3-Veg not available for ${ifs_grid}" ;;
  162. esac
  163. ;;
  164. "custom_"* )
  165. # LPJG vegetation is provided as effective cover
  166. # Don't use Lambert-Beer
  167. n_compute_eff_veg_fraction=0
  168. veg_version=${ifs_veg_source:7}
  169. if [ ! -d ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version} ]
  170. then
  171. error "requested IFS_VEG_SOURCE = ${ifs_veg_source} but not found in ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version}"
  172. fi
  173. ;;
  174. "none" )
  175. # LPJG with feedback
  176. n_compute_eff_veg_fraction=0
  177. has_config osm && ! has_config lpjg:fdbck && error "OSM requires an offline source of vegetation"
  178. ;;
  179. * )
  180. error "Vegetation from ${ifs_veg_source} not implemented"
  181. ;;
  182. esac
  183. # use DMI land ice physics and varying snow albedo
  184. ifs_landice=false
  185. # -----------------------------------------------------------------------------
  186. # *** LPJ-GUESS configuration
  187. # -----------------------------------------------------------------------------
  188. lpjg_time_step_sec=[[[MOD:LPJG:TIME_STEP_SEC]]]
  189. lpjg_numproc=[[[MOD:LPJG:NUMPROC]]]
  190. has_config lpjg && lpjg_on=1
  191. has_config lpjg:fdbck && lpjg_fdbck=1
  192. has_config tm5:co2 && lpjg_fdbck_tm5=1 || lpjg_fdbck_tm5=0
  193. export lpjg_fixNdepafter=[[[MOD:LPJG:LPJG_FIXNDEPAFTER]]]
  194. export lpjg_fixLUafter=[[[MOD:LPJG:LPJG_FIXLUAFTER]]]
  195. info '!!!! CMIP FIX YEAR SETTINGS:'
  196. info "ifs_cmip_fixyear: $ifs_cmip_fixyear"
  197. info "lpjg_fixNDepAfter: $lpjg_fixNdepafter"
  198. info "lpjg_fixLUAfter: $lpjg_fixLUafter"
  199. info '!!!!'
  200. lpjg_res=T${ifs_res_hor}
  201. lpjg_exe_file=${ecearth_src_dir}/lpjg/build/guess_${lpjg_res}
  202. # -----------------------------------------------------------------------------
  203. # *** LPJ-GUESS offline forcing configuration
  204. # -----------------------------------------------------------------------------
  205. lpjg_forcing_exe_file=${ecearth_src_dir}/lpjg/offline/lpjg_forcing
  206. if $(has_config lpjg_forcing)
  207. then
  208. case "${ifs_grid}" in
  209. T159L*) lpjg_forcing_exe_file+="_ifs_T159" ;;
  210. T255L*) lpjg_forcing_exe_file+="_ifs_T255" ;;
  211. *) has_config lpjg && error "LPJG offline forcing doesn't exist for ifs-grid: ${ifs_grid}" ;;
  212. esac
  213. fi
  214. lpjg_forcing_numproc=1
  215. ccycle_coupling_exe_file=${ecearth_src_dir}/lpjg/offline/ccycle_coupling
  216. ccycle_coupling_numproc=1
  217. if $(has_config lpjg)
  218. then
  219. lpjg_ifs_output_dir="[[[MOD:LPJG:LPJG_IFS_OUTPUT_DIR]]]"
  220. lpjg_forcing_dir="[[[MOD:LPJG:LPJG_FORCING_DIR]]]"
  221. fi
  222. # Decide whether the OASIS weight files for interpolation should be linked from
  223. # the setup directory (true) or not (false). In the latter case, the weights
  224. # are re-computed at the start of the run.
  225. oas_link_weights=true
  226. # =============================================================================
  227. # *** END of User configuration
  228. # =============================================================================
  229. # =============================================================================
  230. # *** This is where the code begins ...
  231. # =============================================================================
  232. # -----------------------------------------------------------------------------
  233. # *** Create the run dir if necessary and go there
  234. # Everything is done from here.
  235. # -----------------------------------------------------------------------------
  236. if [ ! -d ${run_dir} ]
  237. then
  238. mkdir -p ${run_dir}
  239. fi
  240. cd ${run_dir}
  241. # -----------------------------------------------------------------------------
  242. # *** Determine the time span of this run and whether it's a restart leg
  243. # -----------------------------------------------------------------------------
  244. # Regularise the format of the start and end date of the simulation
  245. run_start_date=$(date -uR -d "${run_start_date}")
  246. run_end_date=$(date -uR -d "${run_end_date}")
  247. # -----------------------------------------------------------------------------
  248. # *** Set path to grib_set
  249. # -----------------------------------------------------------------------------
  250. grib_set=${GRIB_BIN_PATH}${GRIB_BIN_PATH:+/}grib_set
  251. grib_copy=${GRIB_BIN_PATH}${GRIB_BIN_PATH:+/}grib_copy
  252. # Loop over the number of legs
  253. for (( ; run_num_legs>0 ; run_num_legs-- ))
  254. do
  255. # Check for restart information file and set the current leg start date
  256. # Ignore restart information file if force_run_from_scratch is true
  257. if ${force_run_from_scratch} || ! [ -r ${ece_info_file} ]
  258. then
  259. leg_is_restart=false
  260. leg_start_date=${run_start_date}
  261. leg_number=1
  262. else
  263. leg_is_restart=true
  264. . ./${ece_info_file}
  265. leg_start_date=${leg_end_date}
  266. leg_number=$((leg_number+1))
  267. fi
  268. # Compute the end date of the current leg
  269. if [ -n "${rst_freq}" ]
  270. then
  271. leg_end_date=$(date -uR -d "${leg_start_date} + ${rst_freq}")
  272. else
  273. leg_end_date=${run_end_date}
  274. fi
  275. # Check if legs are integer multiples of full years if LPJG is used
  276. if has_config lpjg
  277. then
  278. if [[ $(date +%m%d%T -u -d "${leg_start_date}") != "010100:00:00" || \
  279. $(date +%m%d%T -u -d "${leg_start_date} + ${rst_freq}") != "010100:00:00" ]]
  280. then
  281. error "LPJ-GUESS runs must start on Jan 1 and end on Dec 31. Multi-year legs are allowed."
  282. fi
  283. fi
  284. if [ $(date -u -d "${leg_end_date}" +%s) -ge $(date -u -d "${run_end_date}" +%s) ]
  285. then
  286. leg_end_date=${run_end_date}
  287. ifs_lastout=true
  288. fi
  289. # Some time variables needed later
  290. leg_length_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${leg_start_date}" +%s) ))
  291. leg_start_sec=$(( $(date -u -d "${leg_start_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  292. leg_end_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  293. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d)
  294. leg_start_date_yyyy=$(date -u -d "${leg_start_date}" +%Y)
  295. leg_end_date_yyyy=$(date -u -d "${leg_end_date}" +%Y)
  296. # compute last full year of the leg, used for ICMCL data and OSM forcing when leg ends on Jan 1st
  297. if [ $(date -u -d "${leg_end_date}" +%m%d) == "0101" ]
  298. then
  299. leg_end_date_yyyy_full=$(( leg_end_date_yyyy - 1 ))
  300. else
  301. leg_end_date_yyyy_full=$leg_end_date_yyyy
  302. fi
  303. # Check whether there's actually time left to simulate - exit otherwise
  304. if [ ${leg_length_sec} -le 0 ]
  305. then
  306. info "Leg start date equal to or after end of simulation."
  307. info "Nothing left to do. Exiting."
  308. exit 0
  309. fi
  310. # -------------------------------------------------------------------------
  311. # *** Prepare the run directory for a run from scratch
  312. # -------------------------------------------------------------------------
  313. if ! $leg_is_restart
  314. then
  315. # ---------------------------------------------------------------------
  316. # *** Check if run dir is empty. If not, and if we are allowed to do so
  317. # by ${force_run_from_scratch}, remove everything
  318. # ---------------------------------------------------------------------
  319. if $(ls * >& /dev/null)
  320. then
  321. if ${force_run_from_scratch}
  322. then
  323. rm -fr ${run_dir}/*
  324. else
  325. error "Run directory ${run_dir} not empty and \$force_run_from_scratch not set."
  326. fi
  327. fi
  328. # ---------------------------------------------------------------------
  329. # *** Copy executables of model components
  330. # *** Additionally, create symlinks to the original place for reference
  331. # ---------------------------------------------------------------------
  332. if $(has_config osm)
  333. then
  334. cp ${osm_exe_file} .
  335. ln -s ${osm_exe_file} $(basename ${osm_exe_file}).lnk
  336. fi
  337. if $(has_config lpjg)
  338. then
  339. cp ${lpjg_exe_file} .
  340. ln -s ${lpjg_exe_file} $(basename ${lpjg_exe_file}).lnk
  341. fi
  342. if $(has_config lpjg_forcing)
  343. then
  344. cp ${lpjg_forcing_exe_file} .
  345. fi
  346. if $(has_config cc_coup)
  347. then
  348. cp ${ccycle_coupling_exe_file} .
  349. fi
  350. # ---------------------------------------------------------------------
  351. # *** Files needed for IFS/OSM (linked)
  352. # ---------------------------------------------------------------------
  353. if $(has_config osm)
  354. then
  355. # Initial data
  356. ln -s \
  357. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIUA \
  358. ICMGG${exp_name}INIUA
  359. ln -s \
  360. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMSHECE3INIT \
  361. ICMSH${exp_name}INIT
  362. rm -f ICMGG${exp_name}INIT
  363. cp ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIT \
  364. ICMGG${exp_name}INIT
  365. # add bare_soil_albedo to ICMGG*INIT
  366. tempfile=tmp.$$
  367. ${grib_set} -s dataDate=$(date -u -d "$run_start_date" +%Y%m%d) \
  368. ${ini_data_dir}/ifs/${ifs_grid}/climate/bare_soil_albedos.grb \
  369. ${tempfile}
  370. cat ${tempfile} >> ICMGG${exp_name}INIT
  371. rm -f ${tempfile}
  372. # add land ice mask if needed - not used in OSM yet
  373. if ${ifs_landice}
  374. then
  375. tempfile=tmp.$$
  376. cdo divc,10 -setcode,82 -selcode,141 ICMGG${exp_name}INIT ${tempfile}
  377. ${grib_set} -s gridType=reduced_gg ${tempfile} ${tempfile}
  378. cat ${tempfile} >> ICMGG${exp_name}INIT
  379. rm -f ${tempfile}
  380. fi
  381. fi #osm
  382. # ---------------------------------------------------------------------
  383. # *** Files needed for LPJ-GUESS
  384. # ---------------------------------------------------------------------
  385. if $(has_config lpjg)
  386. then
  387. # Check for valid grid
  388. if [ $lpjg_res != "T255" -a $lpjg_res != "T159" ]
  389. then
  390. error "LPJG-gridlist doesn't exist for ifs-grid: ${ifs_grid}"
  391. fi
  392. # Initial data - saved state for LPJ-GUESS (.bin format)
  393. lpjgstartdir=$(printf "lpjg_state_%04d" $leg_start_date_yyyy)
  394. if ! $(has_config lpjg:spinup)
  395. then
  396. ln -sf ${ini_data_dir}/lpjg/ini_state/${lpjg_res}/${lpjgstartdir} ${run_dir}/${lpjgstartdir}
  397. fi
  398. # Control files (i.e. .ins, landuse, N deposition, soil type files etc.)
  399. cp -f ${ecearth_src_dir}/lpjg/data/ins/*.ins .
  400. # activate the new litterfall scheme for C4MIP - for the coupled model this is done when both pisces and lpjg are activated
  401. has_config cc_coup && echo -e "!override for EC-Earth-CC in runscript\nifpftlitterfall 1\ncalc_phen_after_restart 0" >> global.ins
  402. mkdir -p ${run_dir}/landuse
  403. fi
  404. # if running an LPJG spinup, create fast forcing files and link to the ifs_spinup_dir expected by LPJG
  405. if $(has_config lpjg:spinup)
  406. then
  407. lpjg_gen_forcing_spinup
  408. ln -sf $lpjg_forcing_dir ifs_spinup_forcing
  409. fi
  410. # ---------------------------------------------------------------------
  411. # *** Files needed for OASIS (linked)
  412. # ---------------------------------------------------------------------
  413. # Name table file
  414. ln -s ${ini_data_dir}/oasis/cf_name_table.txt
  415. # we should use the L128 grid (only in AMIP grid file)
  416. # but for now let's use the same files as for the coupled runs
  417. #oas_grid_dir=${ini_data_dir}/oasis/AMIP
  418. oas_grid_dir=${ini_data_dir}/oasis/${lpjg_res}-ORCA1
  419. mycp='cp'
  420. # Grid definition files
  421. if $(has_config tm5)
  422. then
  423. ${mycp} ${oas_grid_dir}/areas.nc gcm_areas.nc
  424. ${mycp} ${oas_grid_dir}/grids.nc gcm_grids.nc
  425. ${mycp} ${oas_grid_dir}/masks.nc gcm_masks.nc
  426. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-TM5-LPJG
  427. cp ${oas_grid_dir}/tm5_areas.nc .
  428. cp ${oas_grid_dir}/tm5_grids.nc .
  429. cp ${oas_grid_dir}/tm5_masks.nc .
  430. if ${oas_link_weights}
  431. then
  432. for f in ${oas_grid_dir}/rmp_????_to_????_*.nc
  433. do
  434. ln -s $f
  435. done
  436. fi
  437. # -- Get restart files for TM5-IFS/LPJG/PISCES
  438. for f in ${oas_rst_ifs_tm5}
  439. do
  440. cp ${oas_grid_dir}/rst/${tm5_exch_nlevs}-levels/$f .
  441. done
  442. # set CO2 concentrations to 1850 levels as in TM5 code
  443. if true
  444. then
  445. for f in l_co2.nc
  446. do
  447. [ -f $f ] && mv -f $f $f.bak && cdo setrtoc,0,1000,${ccycle_co2_init_ppm} $f.bak $f
  448. done
  449. fi
  450. # -- Merge grid definition files
  451. cdo merge gcm_areas.nc tm5_areas.nc areas.nc
  452. cdo merge gcm_grids.nc tm5_grids.nc grids.nc
  453. cdo merge gcm_masks.nc tm5_masks.nc masks.nc
  454. else
  455. ln -s ${oas_grid_dir}/areas.nc
  456. ln -s ${oas_grid_dir}/grids.nc
  457. ln -s ${oas_grid_dir}/masks.nc
  458. fi
  459. else # i.e. $leg_is_restart == true
  460. # ---------------------------------------------------------------------
  461. # *** Remove all leftover output files from previous legs
  462. # ---------------------------------------------------------------------
  463. # IFS/OSM files
  464. rm -f ICM{SH,GG}${exp_name}+??????
  465. fi # ! $leg_is_restart
  466. # -------------------------------------------------------------------------
  467. # *** Create some control files
  468. # -------------------------------------------------------------------------
  469. # namelist and namcouple files
  470. has_config lpjg_forcing && . ${ctrl_file_dir}/namelist.lpjg_forcing.sh > namelist.lpjg_forcing
  471. has_config cc_coup && . ${ctrl_file_dir}/namelist.ccycle_coupling.sh > namelist.ccycle_coupling
  472. . ${ctrl_file_dir}/namcouple.sh > namcouple
  473. # -------------------------------------------------------------------------
  474. # *** LPJ-GUESS initial data
  475. # -------------------------------------------------------------------------
  476. if $(has_config lpjg)
  477. then
  478. # LPJG runtime rcfile - update with leg dates
  479. . ${ctrl_file_dir}/namelist.lpjg.sh > lpjg_steps.rc
  480. # determine lpjg scenario-name and co2-file middle-fix
  481. case $(echo ${ifs_cmip6_scenario} | tr '[:upper:]' '[:lower:]') in
  482. hist*) lpjg_scen="ssp370"; lu_src="AIM" ; lpjg_sco2_mfix="AIM-ssp370-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  483. ssp1-1.9*) lpjg_scen="ssp119"; lu_src="IMAGE" ; lpjg_sco2_mfix="IMAGE-ssp119-1-2-1" ; lu_file_posfix="2019_03_13.txt";;
  484. ssp1-2.6*) lpjg_scen="ssp126"; lu_src="IMAGE" ; lpjg_sco2_mfix="IMAGE-ssp126-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  485. 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";;
  486. ssp3-7.0*) lpjg_scen="ssp370"; lu_src="AIM" ; lpjg_sco2_mfix="AIM-ssp370-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  487. ssp4-3.4*) lpjg_scen="ssp434"; lu_src="GCAM" ; lpjg_sco2_mfix="GCAM4-ssp434-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  488. 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";;
  489. 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";;
  490. *) error "Scenario ${ifs_cmip6_scenario} not defined for LPJ-GUESS" ;;
  491. esac
  492. lpjg_scenario_new="historical + $lpjg_sco2_mfix"
  493. lpjg_scenario_info=${run_dir}/lpjg_scenario.info
  494. if [ -f $lpjg_scenario_info ]
  495. then
  496. source $lpjg_scenario_info
  497. if [ "$lpjg_scenario_new" = "$lpjg_scenario" ]
  498. then
  499. lpjg_copy_rte=false
  500. else
  501. lpjg_copy_rte=true
  502. fi
  503. else
  504. lpjg_copy_rte=true
  505. fi
  506. # copy RTE only if necessary (at beginning of a run or when scenario changes)
  507. if $lpjg_copy_rte
  508. then
  509. # write info about installed scenarios to file
  510. echo "lpjg_scenario=\"historical + $lpjg_sco2_mfix\"" > $lpjg_scenario_info
  511. # set file prefixes depending on scenario
  512. lu_file_prefix="1850_2100_luh2_Hist_ScenarioMIP_UofMD"
  513. lu_file_midfix="2_1_f"
  514. lu_path="${ini_data_dir}/lpjg/landuse/${lpjg_res}/${lpjg_scen}"
  515. # copy and reference-link landuse, gross transitions, crops, n-fertilisation
  516. for inp in lu gross crop nfert
  517. do
  518. if [ $inp == "crop" -o $inp == "nfert" ]
  519. then
  520. lu_src_file="${lu_path}/${inp}_rfirr_${lu_file_prefix}_${lu_src}_${lpjg_scen}_${lu_file_midfix}_${lpjg_res}_${lu_file_posfix}"
  521. else
  522. lu_src_file="${lu_path}/${inp}_${lu_file_prefix}_${lu_src}_${lpjg_scen}_${lu_file_midfix}_${lpjg_res}_${lu_file_posfix}"
  523. fi
  524. cp -f $lu_src_file ${run_dir}/landuse/${inp}_luh2.txt
  525. ln -fs $lu_src_file ${run_dir}/landuse/${inp}_luh2.txt.lnk
  526. done
  527. # nitrogen deposition files
  528. mkdir -p ${run_dir}/ndep
  529. for inp in drynhx2 drynoy2 wetnhx2 wetnoy2
  530. do
  531. ndep_src_file="${ini_data_dir}/lpjg/ndep/${lpjg_res}/${lpjg_scen}/${lpjg_scen}_${lpjg_res}_${inp}.nc"
  532. cp -f $ndep_src_file ${run_dir}/ndep/${inp}.nc
  533. ln -fs $ndep_src_file ${run_dir}/ndep/${inp}.nc.lnk
  534. done
  535. # concatenate historic and scenario (2015+) co2 concentration file
  536. # hist co2 file
  537. 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"
  538. # scenario co2 file
  539. 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"
  540. # combined file
  541. lpjg_co2_file="${run_dir}/mole_fraction_of_carbon_dioxide_in_air_input4MIPs_lpjg.nc"
  542. rm -f $lpjg_co2_file
  543. cdo mergetime $lpjg_hco2_file $lpjg_sco2_file $lpjg_co2_file
  544. fi
  545. # Populate or update LPJG run directories
  546. if $(has_config lpjg:ioopt)
  547. then
  548. export lpjg_numproc
  549. run_node 'echo creating lpjg temp dirs on `hostname` ; rm -rf $TMPDIR/lpjg/run* ; for (( n=1; n<=${lpjg_numproc}; n++ )) ; do mkdir -p $TMPDIR/lpjg/run${n}/output/CMIP6 ; done ; ls -l $TMPDIR/lpjg/'
  550. fi
  551. for (( n=1; n<=${lpjg_numproc}; n++ ))
  552. do
  553. # if run from scratch or number of procs has been extended
  554. if ! $leg_is_restart || [ ! -d ${run_dir}/run${n} ]
  555. then
  556. # Make output directories
  557. # add the ioopt config option if running on one node to speed up output
  558. if $(has_config lpjg:ioopt)
  559. then
  560. mkdir -p ${run_dir}/run${n}
  561. ln -sf $TMPDIR/lpjg/run${n}/output ${run_dir}/run${n}/output
  562. else
  563. mkdir -p ${run_dir}/run${n}/output/CMIP6
  564. fi
  565. # Copy *.ins, lpjg_steps.rc and OASIS-MCT restart files
  566. cp ${run_dir}/*.ins ${run_dir}/run${n}
  567. # Copy output control files
  568. cp ${output_control_files_dir}/lpjg_cmip6_output.ins ${run_dir}/run${n}
  569. ln -s ${output_control_files_dir}/lpjg_cmip6_output.ins ${run_dir}/run${n}/lpjg_cmip6_output.ins.lnk
  570. cp ${ini_data_dir}/lpjg/oasismct/ghg*.txt ${run_dir}/run${n}
  571. cp ${ini_data_dir}/lpjg/oasismct/${lpjg_res}/ece_gridlist_${lpjg_res}.txt ${run_dir}/run${n}/ece_gridlist.txt
  572. ln -s ${ini_data_dir}/lpjg/oasismct/${lpjg_res}/ece_gridlist_${lpjg_res}.txt ${run_dir}/run${n}/ece_gridlist.txt.lnk
  573. # Data only needed by master or spinup
  574. if [ $n == 1 ]
  575. then
  576. cp ${ini_data_dir}/lpjg/oasismct/${lpjg_res}/*.nc ${run_dir}
  577. fi
  578. fi
  579. # Refresh output-dirs after they hav been removed at end of the last leg
  580. mkdir -p ${run_dir}/run${n}/output/CMIP6
  581. mkdir -p ${run_dir}/run${n}/output/CRESCENDO
  582. done
  583. if $leg_is_restart
  584. then
  585. lpjg_restart_dir="restart/lpjg/$(printf %03d $((leg_number-1)))"
  586. lpjg_rst_state="${lpjg_restart_dir}/lpjg_state_${leg_start_date_yyyy}"
  587. if [ -d "$lpjg_rst_state" ]
  588. then
  589. ln -sf $lpjg_rst_state
  590. else
  591. echo "lpjg restart dir $lpjg_rst_state not available"
  592. exit -1
  593. fi
  594. # get oasis restart files
  595. oasis_restart_dir="restart/oasis/$(printf %03d $((leg_number)))"
  596. cp -f ${oasis_restart_dir}/*.nc ${run_dir}/
  597. fi
  598. # generate lpjg_forcing files
  599. if $(has_config lpjg_forcing)
  600. then
  601. lpjg_gen_forcing $leg_start_date_yyyy $leg_end_date_yyyy_full
  602. fi
  603. fi
  604. # -------------------------------------------------------------------------
  605. # *** Create ICMCL file with vegetation fields
  606. # not needed if LPJG is used with feedback
  607. # -------------------------------------------------------------------------
  608. if $(has_config osm)
  609. then
  610. tempfile=tmp.$$
  611. case ${ifs_veg_source} in
  612. "ifs" )
  613. # Vegetation from IFS (climatology)
  614. icmclfile=${ini_data_dir}/ifs/${ifs_grid}/climate/ICMCL_ONLY_VEG_PD
  615. # Create data for december, the year before the leg starts
  616. ${grib_set} \
  617. -s dataDate=$(printf "%04d" $((leg_start_date_yyyy-1)))1215,stepRange=0 \
  618. ${icmclfile}-12 ICMCL${exp_name}INIT
  619. # Create data for all month in the years of the leg
  620. for (( y=${leg_start_date_yyyy} ; y<=${leg_end_date_yyyy_full} ; y++ ))
  621. do
  622. yy=$(printf "%04d" $y)
  623. for m in {1..12}
  624. do
  625. mm=$(printf "%02d" $m)
  626. ${grib_set} -s dataDate=${yy}${mm}15,stepRange=0 ${icmclfile}-${mm} ${tempfile}
  627. cat ${tempfile} >> ICMCL${exp_name}INIT
  628. done
  629. done
  630. # Create data for january, the year after the leg ends
  631. ${grib_set} \
  632. -s dataDate=$(printf "%04d" $((leg_end_date_yyyy_full+1)))0115,stepRange=0 \
  633. ${icmclfile}-01 ${tempfile}
  634. cat ${tempfile} >> ICMCL${exp_name}INIT
  635. ;;
  636. "era20c"|"cmip6"|"custom_"* )
  637. # Vegetation from a LPJG run (off-line or EC-Earth3-Veg)
  638. rm -f ICMCL${exp_name}INIT
  639. # Create data for all years of the leg, including one year
  640. # before and one year after
  641. for (( yr=leg_start_date_yyyy-1 ; yr<=leg_end_date_yyyy_full+1 ; yr+=1 ))
  642. do
  643. case ${ifs_veg_source} in
  644. 'era20c' )
  645. # no scenario needed with era20c
  646. icmcl_scenario="" ;;
  647. 'custom_'* )
  648. # no scenario implemented yet with custom_dir
  649. icmcl_scenario="" ;;
  650. 'cmip6' )
  651. # select scenario, use SSP3-7.0 as default
  652. # if not otherwise specified
  653. icmcl_scenario="historical"
  654. if ( [ $ifs_cmip_fixyear -le 0 ] && [ $yr -ge 2015 ] ) || \
  655. [ $ifs_cmip_fixyear -ge 2015 ]
  656. then
  657. [[ ${ifs_cmip6_scenario} =~ ^SSP ]] \
  658. && icmcl_scenario=${ifs_cmip6_scenario} \
  659. || icmcl_scenario='SSP3-7.0'
  660. fi ;;
  661. esac
  662. if [ $ifs_cmip_fixyear -le 0 ]
  663. then
  664. cat ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version}/${icmcl_scenario}/icmcl_$yr.grb >> ICMCL${exp_name}INIT
  665. else
  666. # Fixed year forcing, requires cdo!
  667. # If cdo is not available at runtime you need to fix proper
  668. # icmcl files beforehand and use them here
  669. cdo setyear,$yr ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version}/${icmcl_scenario}/icmcl_${ifs_cmip_fixyear}.grb ${tempfile}
  670. cat ${tempfile} >> ICMCL${exp_name}INIT
  671. fi
  672. done
  673. ;;
  674. "none" )
  675. info "no ICMCL file is created"
  676. ;;
  677. * )
  678. error "Vegetation from ${ifs_veg_source} not implemented"
  679. ;;
  680. esac
  681. # Clean up
  682. rm -f ${tempfile}
  683. fi #osm
  684. # ---------------------------------------------------------------------
  685. # *** Create initial & climatological conditions for osm
  686. # ---------------------------------------------------------------------
  687. if $(has_config osm)
  688. then
  689. ## create initial conditions
  690. if ! $leg_is_restart
  691. then
  692. osm_gen_init_clim
  693. fi
  694. # used to generate daily veg from an IFS experiment to force the OSM
  695. osm_icmcl_ifs=false
  696. if $osm_icmcl_ifs
  697. then
  698. if ! [ -r ${osm_forcing_dir}/ICMCL_${leg_start_date_yyyy} ]
  699. then
  700. osm_gen_icmcl_from_ifs $leg_start_date_yyyy
  701. cp ICMCL${exp_name}INIT ${osm_forcing_dir}/ICMCL_${leg_start_date_yyyy}
  702. else
  703. # or get it from osm_forcing dir
  704. mv ICMCL${exp_name}INIT ICMCL${exp_name}INIT_ORI
  705. ln -sf ${osm_forcing_dir}/ICMCL_${leg_start_date_yyyy} ICMCL${exp_name}INIT
  706. fi
  707. fi
  708. # generate surfveg for osm simulation
  709. osm_gen_veg
  710. ## create forcing
  711. osm_gen_forcing $leg_start_date_yyyy $leg_end_date_yyyy_full
  712. if [[ $leg_start_date_yyyy == $leg_end_date_yyyy_full ]]
  713. then
  714. ln -sf ${osm_forcing_dir}/${leg_start_date_yyyy}/* .
  715. else
  716. ln -sf ${osm_forcing_dir}/${leg_start_date_yyyy}-${leg_end_date_yyyy_full}/* .
  717. fi
  718. ## generate osm namelist
  719. . ${ctrl_file_dir}/namelist.osm.sh > input
  720. fi
  721. # -------------------------------------------------------------------------
  722. # *** Remove some OASIS files of the previous leg
  723. # -------------------------------------------------------------------------
  724. # TODO check oasis restart files
  725. #if $leg_is_restart
  726. #then
  727. # rm -f anaisout_*
  728. #fi
  729. # -------------------------------------------------------------------------
  730. # *** Start the run
  731. # -------------------------------------------------------------------------
  732. # Activate OASIS coupling in OSM if necessary
  733. has_config osm lpjg && export CPLNG='active'
  734. # Use the launch function from the platform configuration file
  735. cmd=""
  736. if $(has_config lpjg)
  737. then
  738. [ "${cmd}" != "" ] && cmd=${cmd}" -- "
  739. has_config lpjg:spinup && lpjg_spinup="-islpjgspinup" || lpjg_spinup=""
  740. cmd=${cmd}"${lpjg_numproc} ${lpjg_exe_file} guess.ins ${lpjg_spinup} -parallel"
  741. has_config lpjg_forcing && cmd=${cmd}" -- ${lpjg_forcing_numproc} ${lpjg_forcing_exe_file}"
  742. has_config cc_coup && cmd=${cmd}" -- ${ccycle_coupling_numproc} ${ccycle_coupling_exe_file}"
  743. fi
  744. if $(has_config osm)
  745. then
  746. # TODO pass this only to the osm process?
  747. export OMP_NUM_THREADS=${osm_numproc}
  748. ### to do: special "launch" function for OpenMP only run
  749. [ "${cmd}" != "" ] && cmd=${cmd}" -- "
  750. cmd=${cmd}"1 ${osm_exe_file}"
  751. fi
  752. t1=$(date +%s)
  753. launch $cmd
  754. t2=$(date +%s)
  755. tr=$(date -d "0 -$t1 sec + $t2 sec" +%T)
  756. # -------------------------------------------------------------------------
  757. # *** Check for signs of success
  758. # Note the tests provide no guarantee that things went fine! They are
  759. # just based on the IFS, NEMO and TM5 log files. More tests (e.g. checking
  760. # restart files) could be implemented.
  761. # -------------------------------------------------------------------------
  762. # Check for LPJG/OSM success ???
  763. # -------------------------------------------------------------------------
  764. # *** Move LPJ-GUESS output files to archive directory
  765. # -------------------------------------------------------------------------
  766. if $(has_config lpjg)
  767. then
  768. outdir="output/lpjg/$(printf %03d $((leg_number)))"
  769. if [ -d ${outdir} ]
  770. then
  771. rm -rf ${outdir}
  772. fi
  773. mkdir -p ${outdir}
  774. if $(has_config lpjg:ioopt)
  775. then
  776. for (( n=1; n<=${lpjg_numproc}; n++ )) ; do [ -L ${run_dir}/run${n}/output ] && rm -f ${run_dir}/run${n}/output ; done
  777. export lpjg_numproc run_dir
  778. run_node 'echo copying lpjg temp dirs from `hostname` ; for (( n=1; n<=${lpjg_numproc}; n++ )) ; do cp -rvf $TMPDIR/lpjg/run${n}/output/ ${run_dir}/run${n} ; done'
  779. fi
  780. # LPJG run directories
  781. # concatenate *.out (or compressed *.out.gz) files from each run* into output dir
  782. flist=$(cd ${run_dir}/run1/output && find *.out.gz -type f 2>/dev/null || true)
  783. if [ "$flist" = "" ]
  784. then
  785. lpjg_compress_output=false
  786. flist=$(cd ${run_dir}/run1/output && find *.out -type f 2>/dev/null)
  787. else
  788. lpjg_compress_output=true
  789. fi
  790. mkdir ${outdir}/CMIP6
  791. for (( n=1; n<=${lpjg_numproc}; n++ ))
  792. do
  793. for ofile in $flist
  794. do
  795. if $lpjg_compress_output
  796. then
  797. [ $n == 1 ] && gzip -c ${run_dir}/run${n}/output/`basename ${ofile} .gz`.hdr > ${outdir}/$ofile
  798. cat ${run_dir}/run${n}/output/${ofile} >> ${outdir}/$ofile
  799. else
  800. if (( n == 1 ))
  801. then
  802. cat ${run_dir}/run${n}/output/${ofile} > ${outdir}/$ofile
  803. else
  804. awk '(FNR!=1){print $0}' ${run_dir}/run${n}/output/${ofile} >> ${outdir}/$ofile
  805. fi
  806. fi
  807. done
  808. rm -rf ${run_dir}/run${n}/output
  809. done
  810. # move monthly file if available
  811. if [ -f ${run_dir}/LPJ-GUESS_monthlyoutput.txt ]
  812. then
  813. mv ${run_dir}/LPJ-GUESS_monthlyoutput.txt ${outdir}
  814. fi
  815. fi
  816. # -------------------------------------------------------------------------
  817. # *** Move OSM output files to archive directory
  818. # -------------------------------------------------------------------------
  819. if $(has_config osm)
  820. then
  821. outdir="output/osm/$(printf %03d $((leg_number)))"
  822. mkdir -p ${outdir}
  823. mv o_*.nc $outdir
  824. rm -f Wind.nc Tair.nc Snowf.nc SWdown.nc Rainf.nc Qair.nc PSurf.nc LWdown.nc
  825. #------------------------------------------------------------------------
  826. # ** Post-process OSM data
  827. #------------------------------------------------------------------------
  828. osm_post_gen_script ${outdir} ${leg_number}
  829. # run osm_post script now if post_run is in config
  830. has_config osm:post_run && . ${exp_name}_osm_post_${leg_number}.sh
  831. fi
  832. # -------------------------------------------------------------------------
  833. # *** Move ccycle_coupling output files to archive directory
  834. # -------------------------------------------------------------------------
  835. if $(has_config tm5:co2)
  836. then
  837. outdir="output/ccycle/$(printf %03d $((leg_number)))"
  838. mkdir -p ${outdir}
  839. rm -f GUE_{CNAT,CANT,CNPP}_*.nc
  840. mv TM5_Land{CNAT,CANT,CNPP}_*.nc ${outdir}
  841. fi
  842. # -------------------------------------------------------------------------
  843. # *** Move LPJ-GUESS restart files to archive directory
  844. # -------------------------------------------------------------------------
  845. if $(has_config lpjg) && ! $(has_config lpjg:spinup)
  846. then
  847. outdir="restart/lpjg/$(printf %03d $((leg_number)))"
  848. if [ -d ${outdir} ]
  849. then
  850. rm -rf ${outdir}
  851. fi
  852. mkdir -p ${outdir}
  853. state_dir="./lpjg_state_$(printf %04d $((leg_end_date_yyyy)))"
  854. mv ${state_dir} ${outdir}
  855. # LPJG writes into run1 dir, so mv to main rundir
  856. mv -f run1/lpjgv.nc .
  857. has_config tm5:co2 lpjg && mv -f run1/rlpjg.nc .
  858. # remove restart link
  859. if $leg_is_restart
  860. then
  861. old_state_dir="./lpjg_state_$(printf %04d $((leg_start_date_yyyy)))"
  862. if [ -L $old_state_dir ]
  863. then
  864. rm -f "$old_state_dir"
  865. fi
  866. fi
  867. fi
  868. # -------------------------------------------------------------------------
  869. # *** Move OSM restart files to archive directory
  870. # -------------------------------------------------------------------------
  871. if $(has_config osm)
  872. then
  873. outdir="restart/osm/$(printf %03d $((leg_number)))"
  874. mkdir -p ${outdir}
  875. mv restartout.nc $outdir/
  876. rm -f restartin.nc restartin.nc.lnk
  877. cp -f $outdir/restartout.nc restartin.nc
  878. ln -sf $outdir/restartout.nc restartin.nc.lnk
  879. fi
  880. # -------------------------------------------------------------------------
  881. # *** Move log files to archive directory
  882. # -------------------------------------------------------------------------
  883. outdir="log/$(printf %03d $((leg_number)))"
  884. mkdir -p ${outdir}
  885. for f in \
  886. guess.log run1/guess0.log \
  887. nout.000000 debug.??.?????? A*_??.nc O*_??.nc \
  888. osm.log input
  889. do
  890. test -f ${f} && mv ${f} ${outdir}
  891. done
  892. # -------------------------------------------------------------------------
  893. # *** Copy OASIS restart files to archive directory
  894. # NOTE: These files are copied and not moved as they are used in the
  895. # next leg!
  896. # Note also that the OASIS restart files present at the end of
  897. # the leg correspond to the start of the next leg!
  898. # -------------------------------------------------------------------------
  899. outdir="restart/oasis/$(printf %03d $((leg_number+1)))"
  900. mkdir -p ${outdir}
  901. for f in vegin.nc lpjgv.nc
  902. do
  903. test -f ${f} && cp ${f} ${outdir}
  904. done
  905. # -------------------------------------------------------------------------
  906. # *** Write the restart control file
  907. # -------------------------------------------------------------------------
  908. # Compute CPMIP performance
  909. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  910. ncores=0
  911. has_config lpjg && (( ncores+=${lpjg_numproc} )) || :
  912. has_config lpjg_forcing && (( ncores+=${lpjg_forcing_numproc} )) || :
  913. has_config osm && (( ncores+=${osm_numproc} )) || :
  914. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1 +1)) $ncores)" #t_run+1 prevent div zero, just in case
  915. echo "#" | tee -a ${ece_info_file}
  916. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  917. | tee -a ${ece_info_file}
  918. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  919. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  920. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  921. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  922. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  923. force_run_from_scratch=false
  924. done # loop over legs
  925. # -----------------------------------------------------------------------------
  926. # *** Platform dependent finalising of the run
  927. # -----------------------------------------------------------------------------
  928. finalise
  929. exit 0