ece-lsm.sh.tmpl 46 KB

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