ece-ifs.sh.tmpl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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
  12. # (for syntax of the $config variable, see librunscript.sh)
  13. config="ifs amip"
  14. # Experiment name (exactly 4 letters!)
  15. exp_name=[[[MOD:GENERAL:EXP_NAME]]]
  16. # Simulation start and end date. Use any (reasonable) syntax you want.
  17. run_start_date="[[[MOD:GENERAL:RUN_START_DATE]]]"
  18. run_end_date="[[[MOD:GENERAL:RUN_END_DATE]]]"
  19. # Set $force_run_from_scratch to 'true' if you want to force this run to start
  20. # from scratch, possibly ignoring any restart files present in the run
  21. # directory. Leave set to 'false' otherwise.
  22. # NOTE: If set to 'true' the run directory $run_dir is cleaned!
  23. force_run_from_scratch=[[[MOD:GENERAL:FORCE_RUN_FROM_SCRATCH]]]
  24. # Resolution
  25. ifs_grid=[[[MOD:IFS:GRID]]]
  26. # Restart frequency. Use any (reasonable) number and time unit you want.
  27. # For runs without restart, leave this variable empty
  28. rst_freq="[[[MOD:GENERAL:RST_FREQ]]]"
  29. # Number of restart legs to be run in one go
  30. run_num_legs=[[[MOD:GENERAL:RUN_NUM_LEGS]]]
  31. # Coupling frequency [sec]
  32. # Don't change the coupling frequency because UPDCLIE (where SST and SIC
  33. # are updated) is called every 24 hours (hardcoded in ifs-36r4/src/ifs/utility/updtim.F90)
  34. cpl_freq_amip_sec=86400
  35. # Directories
  36. start_dir=${PWD}
  37. ctrl_file_dir=${start_dir}/ctrl
  38. output_control_files_dir=${start_dir}/[[[MOD:GENERAL:OUTPUT_CONTROL_FILES_DIR]]]
  39. # Architecture
  40. build_arch=[[[PLT:ACTIVE:BUILD_ARCH]]]
  41. # This file is used to store information about restarts
  42. ece_info_file="ece.info"
  43. # -----------------------------------------------------------------------------
  44. # *** Read platform dependent configuration
  45. # -----------------------------------------------------------------------------
  46. source ./ecconf.cfg
  47. configure
  48. # -----------------------------------------------------------------------------
  49. # *** Time step settings
  50. # -----------------------------------------------------------------------------
  51. case "${ifs_grid}" in
  52. T159L*) ifs_time_step_sec=3600 ;;
  53. T255L*) ifs_time_step_sec=2700 ;;
  54. T511L*) ifs_time_step_sec=900 ;;
  55. *) error "Can't set time steps for unknown horizontal grid: ${ifs_grid}"
  56. ;;
  57. esac
  58. # -----------------------------------------------------------------------------
  59. # *** IFS configuration
  60. # -----------------------------------------------------------------------------
  61. ifs_version=36r4
  62. ifs_di_freq=$(( 24 * 3600 / ifs_time_step_sec ))
  63. ifs_ddh_freq=$(( 120 * 3600 / ifs_time_step_sec ))
  64. ifs_res_hor=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\1:')
  65. ifs_res_ver=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\2:')
  66. ifs_numproc=[[[MOD:IFS:NUMPROC]]]
  67. ifs_exe_file=${ecearth_src_dir}/ifs-${ifs_version}/bin/ifsmaster-${build_arch}
  68. ifs_lastout=false
  69. ifs_cmip5=[[[MOD:IFS:CMIP5]]]
  70. ifs_cmip5_rcp=[[[MOD:IFS:CMIP5_RCP]]]
  71. ifs_cmip_fixyear=[[[MOD:IFS:CMIP_FIXYEAR]]]
  72. ifs_cmip6=[[[MOD:IFS:CMIP6]]]
  73. ifs_mac2sp=[[[MOD:IFS:CMIP6]]]
  74. ifs_cmip6piaer=[[[MOD:IFS:CMIP6]]]
  75. ifs_cmip6_scenario=[[[MOD:IFS:CMIP6_SCENARIO]]]
  76. lcmip6_strataer_simp=FALSE
  77. lcmip6_strataer_full=[[[MOD:IFS:CMIP6]]]
  78. lcmip6_strataer_bckgd=FALSE
  79. ifs_A4xCO2=[[[MOD:IFS:CMIP6_A4xCO2]]]
  80. ifs_1PCTCO2=[[[MOD:IFS:CMIP6_1PCTCO2]]]
  81. # Time-varying orbital forcing (Qiong Zhang, SU-2013-09)
  82. # https://dev.ec-earth.org/projects/ecearth3/wiki/Orbital_forcing_in_EC-Earth_3
  83. #
  84. # ifs_orb_switch=FALSE, no orbital calculations applied
  85. # ifs_orb_switch=TRUE, use orbital calculations according to ifs_orb_mode
  86. # ifs_orb_mode="fixed_year", or "variable_year", or "fixed_parameters"
  87. # fixed_year: calculate the orbital parameters at ifs_orb_iyear, e.g.,1850
  88. # variable_year: calculate orbital parameters annually start from ifs_orb_iyear
  89. # fixed_parameters: prescribe orbital parameters for given year
  90. ifs_orb_switch=FALSE
  91. ifs_orb_mode="variable_year"
  92. ifs_orb_iyear=$(date -u -d "${run_start_date}" +%Y)
  93. # IFS tuning parameters
  94. ifs_tuning_parameter_file=${ctrl_file_dir}/ifs-tuning-parameters-${ifs_grid}.sh
  95. if [ -f ${ifs_tuning_parameter_file} ]
  96. then
  97. source ${ifs_tuning_parameter_file}
  98. else
  99. error "Sorry, ${ifs_tuning_parameter_file} not found, exiting."
  100. fi
  101. # Select source of vegetation data:
  102. # ifs climatology from IFS
  103. # era20c vegetation from an off-line LPJ-Guess run forced with ERA20C
  104. # (currently available only for T255 and T159)
  105. #
  106. ifs_veg_source="era20c"
  107. case ${ifs_veg_source} in
  108. "ifs" )
  109. # Use Lambert-Beer to compute effective vegetation cover
  110. n_compute_eff_veg_fraction=2
  111. ;;
  112. "era20c" )
  113. # LPJG vegetation is provided as effective cover
  114. # Don't use Lambert-Beer
  115. n_compute_eff_veg_fraction=0
  116. ;;
  117. * )
  118. error "Vegetation from ${ifs_veg_source} not implemented"
  119. ;;
  120. esac
  121. # use DMI land ice physics and varying snow albedo
  122. ifs_landice=false
  123. # -----------------------------------------------------------------------------
  124. # *** AMIP-reader configuration
  125. # -----------------------------------------------------------------------------
  126. amip_exe_file=${ecearth_src_dir}/amip-forcing/bin/amip-forcing.exe
  127. amip_numproc=1
  128. # -----------------------------------------------------------------------------
  129. # *** OASIS configuration
  130. # -----------------------------------------------------------------------------
  131. # Decide whether the OASIS weight files for interpolation should be linked from
  132. # the setup directory (true) or not (false). In the latter case, the weights
  133. # are re-computed at the start of the run.
  134. oas_link_weights=true
  135. # -----------------------------------------------------------------------------
  136. # *** Extra initial conditions saved during the run
  137. # -----------------------------------------------------------------------------
  138. if has_config save_ic
  139. then
  140. source ./libsave_ic.sh
  141. declare -a save_ic_date save_ic_date1 save_ic_sec save_ic_day save_ic_ppt_file save_ic_nemo_ts
  142. fi
  143. # =============================================================================
  144. # *** END of User configuration
  145. # =============================================================================
  146. # =============================================================================
  147. # *** This is where the code begins ...
  148. # =============================================================================
  149. # -----------------------------------------------------------------------------
  150. # *** Create the run dir if necessary and go there
  151. # Everything is done from here.
  152. # -----------------------------------------------------------------------------
  153. if [ ! -d ${run_dir} ]
  154. then
  155. mkdir -p ${run_dir}
  156. fi
  157. cd ${run_dir}
  158. # -----------------------------------------------------------------------------
  159. # *** Determine the time span of this run and whether it's a restart leg
  160. # -----------------------------------------------------------------------------
  161. # Regularise the format of the start and end date of the simulation
  162. run_start_date=$(date -uR -d "${run_start_date}")
  163. run_end_date=$(date -uR -d "${run_end_date}")
  164. # -----------------------------------------------------------------------------
  165. # *** Set path to grib_set
  166. # -----------------------------------------------------------------------------
  167. grib_set=${GRIB_BIN_PATH}${GRIB_BIN_PATH:+/}grib_set
  168. # Loop over the number of legs
  169. for (( ; run_num_legs>0 ; run_num_legs-- ))
  170. do
  171. # Check for restart information file and set the current leg start date
  172. # Ignore restart information file if force_run_from_scratch is true
  173. if ${force_run_from_scratch} || ! [ -r ${ece_info_file} ]
  174. then
  175. leg_is_restart=false
  176. leg_start_date=${run_start_date}
  177. leg_number=1
  178. else
  179. leg_is_restart=true
  180. . ./${ece_info_file}
  181. leg_start_date=${leg_end_date}
  182. leg_number=$((leg_number+1))
  183. fi
  184. # Compute the end date of the current leg
  185. if [ -n "${rst_freq}" ]
  186. then
  187. leg_end_date=$(date -uR -d "${leg_start_date} + ${rst_freq}")
  188. else
  189. leg_end_date=${run_end_date}
  190. fi
  191. if [ $(date -d "${leg_end_date}" +%s) -ge $(date -d "${run_end_date}" +%s) ]
  192. then
  193. leg_end_date=${run_end_date}
  194. ifs_lastout=true
  195. fi
  196. # Some time variables needed later
  197. leg_length_sec=$(( $(date -d "${leg_end_date}" +%s) - $(date -d "${leg_start_date}" +%s) ))
  198. leg_start_sec=$(( $(date -d "${leg_start_date}" +%s) - $(date -d "${run_start_date}" +%s) ))
  199. leg_end_sec=$(( $(date -d "${leg_end_date}" +%s) - $(date -d "${run_start_date}" +%s) ))
  200. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d)
  201. leg_start_date_yyyy=$(date -u -d "${leg_start_date}" +%Y)
  202. leg_end_date_yyyy=$(date -u -d "${leg_end_date}" +%Y)
  203. # Check whether there's actually time left to simulate - exit otherwise
  204. if [ ${leg_length_sec} -le 0 ]
  205. then
  206. info "Leg start date equal to or after end of simulation."
  207. info "Nothing left to do. Exiting."
  208. exit 0
  209. fi
  210. # Initial conditions saved during the run
  211. do_save_ic=false
  212. has_config save_ic && save_ic_get_config
  213. # if you do not use an option with save_ic, you must define 'do_save_ic' and
  214. # 'save_ic_date_offset' here or in ../libsave_ic.sh/save_ic_get_config()
  215. ${do_save_ic} && save_ic_define_vars
  216. # -------------------------------------------------------------------------
  217. # *** Prepare the run directory for a run from scratch
  218. # -------------------------------------------------------------------------
  219. if ! $leg_is_restart
  220. then
  221. # ---------------------------------------------------------------------
  222. # *** Check if run dir is empty. If not, and if we are allowed to do so
  223. # by ${force_run_from_scratch}, remove everything
  224. # ---------------------------------------------------------------------
  225. if $(ls * >& /dev/null)
  226. then
  227. if ${force_run_from_scratch}
  228. then
  229. rm -fr ${run_dir}/*
  230. else
  231. error "Run directory not empty and \$force_run_from_scratch not set."
  232. fi
  233. fi
  234. # ---------------------------------------------------------------------
  235. # *** Copy executables of model components
  236. # *** Additionally, create symlinks to the original place for reference
  237. # ---------------------------------------------------------------------
  238. cp ${ifs_exe_file} .
  239. ln -s ${ifs_exe_file} $(basename ${ifs_exe_file}).lnk
  240. cp ${amip_exe_file} .
  241. ln -s ${amip_exe_file} $(basename ${amip_exe_file}).lnk
  242. # ---------------------------------------------------------------------
  243. # *** Files needed for IFS (linked)
  244. # ---------------------------------------------------------------------
  245. # Initial data
  246. ln -s \
  247. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIUA \
  248. ICMGG${exp_name}INIUA
  249. ln -s \
  250. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMSHECE3INIT \
  251. ICMSH${exp_name}INIT
  252. rm -f ICMGG${exp_name}INIT
  253. cp ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIT \
  254. ICMGG${exp_name}INIT
  255. # add bare_soil_albedo to ICMGG*INIT
  256. tempfile=tmp.$$
  257. ${grib_set} -s dataDate=$(date -u -d "$run_start_date" +%Y%m%d) \
  258. ${ini_data_dir}/ifs/${ifs_grid}/climate/bare_soil_albedos.grb \
  259. ${tempfile}
  260. cat ${tempfile} >> ICMGG${exp_name}INIT
  261. rm -f ${tempfile}
  262. # add land ice mask if needed
  263. if ${ifs_landice}
  264. then
  265. tempfile=tmp.$$
  266. cdo divc,10 -setcode,82 -selcode,141 ICMGG${exp_name}INIT ${tempfile}
  267. ${grib_set} -s gridType=reduced_gg ${tempfile} ${tempfile}
  268. cat ${tempfile} >> ICMGG${exp_name}INIT
  269. rm -f ${tempfile}
  270. fi
  271. # Other stuff
  272. ln -s ${ini_data_dir}/ifs/rtables/* .
  273. # Output control (ppt files)
  274. if [ ! -f ${output_control_files_dir}/pptdddddd0600 ] && [ ! -f ${output_control_files_dir}/pptdddddd0300 ];then
  275. echo "Error from ece-esm.sh: Neither the file pptdddddd0600 or pptdddddd0300 exists in the directory:"
  276. echo " " ${output_control_files_dir}
  277. exit -1
  278. fi
  279. mkdir postins
  280. cp ${output_control_files_dir}/ppt* postins/
  281. if [ -f postins/pptdddddd0600 ];then
  282. ln -s pptdddddd0600 postins/pptdddddd0000
  283. ln -s pptdddddd0600 postins/pptdddddd1200
  284. ln -s pptdddddd0600 postins/pptdddddd1800
  285. fi
  286. if [ -f postins/pptdddddd0300 ];then
  287. ln -s pptdddddd0300 postins/pptdddddd0900
  288. ln -s pptdddddd0300 postins/pptdddddd1500
  289. ln -s pptdddddd0300 postins/pptdddddd2100
  290. if [ ! -f postins/pptdddddd0600 ];then
  291. ln -s pptdddddd0300 postins/pptdddddd0000
  292. ln -s pptdddddd0300 postins/pptdddddd0600
  293. ln -s pptdddddd0300 postins/pptdddddd1200
  294. ln -s pptdddddd0300 postins/pptdddddd1800
  295. fi
  296. fi
  297. /bin/ls -1 postins/* > dirlist
  298. # ---------------------------------------------------------------------
  299. # *** Files needed for OASIS (linked)
  300. # ---------------------------------------------------------------------
  301. oas_grid_dir=${ini_data_dir}/oasis/AMIP
  302. # Name table file
  303. ln -s ${ini_data_dir}/oasis/cf_name_table.txt
  304. # Grid definition files
  305. ln -s ${oas_grid_dir}/areas.nc
  306. ln -s ${oas_grid_dir}/grids.nc
  307. ln -s ${oas_grid_dir}/masks.nc
  308. # Weight files
  309. case ${ifs_res_hor} in
  310. 159) oas_agrd=080
  311. ;;
  312. 255) oas_agrd=128
  313. ;;
  314. 511) oas_agrd=256
  315. ;;
  316. 799) oas_agrd=400
  317. ;;
  318. *) error "Unsupported horizontal resolution (IFS): ${ifs_res_hor}"
  319. ;;
  320. esac
  321. if ${oas_link_weights}
  322. then
  323. for f in ${oas_grid_dir}/rmp_AMIP_to_L${oas_agrd}_GAUSWGT.nc
  324. do
  325. ln -s $f
  326. done
  327. fi
  328. else # i.e. $leg_is_restart == true
  329. # ---------------------------------------------------------------------
  330. # *** Remove all leftover output files from previous legs
  331. # ---------------------------------------------------------------------
  332. # IFS files
  333. rm -f ICM{SH,GG}${exp_name}+??????
  334. fi # ! $leg_is_restart
  335. # -------------------------------------------------------------------------
  336. # *** Initial conditions saved during the run
  337. # -------------------------------------------------------------------------
  338. ${do_save_ic} && save_ic_prepare_output
  339. # -------------------------------------------------------------------------
  340. # *** Create some control files
  341. # -------------------------------------------------------------------------
  342. # IFS frequency output for namelist
  343. if [ -f postins/pptdddddd0300 ]
  344. then
  345. ifs_output_freq=$(( 3 * 3600 / ifs_time_step_sec ))
  346. elif [ -f postins/pptdddddd0600 ]
  347. then
  348. ifs_output_freq=$(( 6 * 3600 / ifs_time_step_sec ))
  349. else
  350. error "IFS output frequency undefined."
  351. fi
  352. # IFS, AMIP-reader namelists and OASIS namcouple files
  353. . ${ctrl_file_dir}/namelist.ifs.sh > fort.4
  354. . ${ctrl_file_dir}/namelist.amip.sh > namelist.amip
  355. . ${ctrl_file_dir}/namcouple.sh > namcouple
  356. # -------------------------------------------------------------------------
  357. # *** Create ICMCL file with vegetation fields
  358. # -------------------------------------------------------------------------
  359. tempfile=tmp.$$
  360. case ${ifs_veg_source} in
  361. "ifs" )
  362. # Vegetation from IFS (climatology)
  363. icmclfile=${ini_data_dir}/ifs/${ifs_grid}/climate/ICMCL_ONLY_VEG_PD
  364. # Create data for december, the year before the leg starts
  365. ${grib_set} \
  366. -s dataDate=$(printf "%04d" $((leg_start_date_yyyy-1)))1215 \
  367. ${icmclfile}-12 ICMCL${exp_name}INIT
  368. # Create data for all month in the years of the leg
  369. for (( y=${leg_start_date_yyyy} ; y<=${leg_end_date_yyyy} ; y++ ))
  370. do
  371. yy=$(printf "%04d" $y)
  372. for m in {1..12}
  373. do
  374. mm=$(printf "%02d" $m)
  375. ${grib_set} -s dataDate=${yy}${mm}15 ${icmclfile}-${mm} ${tempfile}
  376. cat ${tempfile} >> ICMCL${exp_name}INIT
  377. done
  378. done
  379. # Create data for january, the year after the leg ends
  380. ${grib_set} \
  381. -s dataDate=$(printf "%04d" $((leg_end_date_yyyy+1)))0115 \
  382. ${icmclfile}-01 ${tempfile}
  383. cat ${tempfile} >> ICMCL${exp_name}INIT
  384. ;;
  385. "era20c" )
  386. # Vegetation from an off-line LPJG run forced with ERA20C (v16)
  387. rm -f ICMCL${exp_name}INIT
  388. # Create data for all years of the leg, including one year
  389. # before and one year after
  390. for (( yr=leg_start_date_yyyy-1 ; yr<=leg_end_date_yyyy+1 ; yr+=1 ))
  391. do
  392. if [ $ifs_cmip_fixyear -le 0 ]
  393. then
  394. cat ${ini_data_dir}/ifs/${ifs_grid}/icmcl_v16/icmcl_$yr.grb >> ICMCL${exp_name}INIT
  395. else
  396. # Fixed year forcing, requires cdo!
  397. # If cdo is not available at runtime you need to fix proper
  398. # icmcl files beforehand and use them here
  399. cdo setyear,$yr ${ini_data_dir}/ifs/${ifs_grid}/icmcl_v16/icmcl_${ifs_cmip_fixyear}.grb ${tempfile}
  400. cat ${tempfile} >> ICMCL${exp_name}INIT
  401. fi
  402. done
  403. ;;
  404. * )
  405. error "Vegetation from ${ifs_veg_source} not implemented"
  406. ;;
  407. esac
  408. # Clean up
  409. rm -f ${tempfile}
  410. # -------------------------------------------------------------------------
  411. # *** Start the run
  412. # -------------------------------------------------------------------------
  413. export DR_HOOK_IGNORE_SIGNALS='-1'
  414. export CPLNG='active'
  415. # Use the launch function from the platform configuration file
  416. t1=$(date +%s)
  417. launch \
  418. ${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name} -- \
  419. ${amip_numproc} ${amip_exe_file}
  420. t2=$(date +%s)
  421. tr=$(date -d "0 -$t1 sec + $t2 sec" +%T)
  422. # -------------------------------------------------------------------------
  423. # *** Check for signs of success
  424. # Note the tests provide no guarantee that things went fine! They are
  425. # just based on the IFS and NEMO log files. More tests (e.g. checking
  426. # restart files) could be implemented.
  427. # -------------------------------------------------------------------------
  428. # Checking for IFS success
  429. if [ -f ifs.stat ]
  430. then
  431. if [ "$(awk 'END{print $3}' ifs.stat)" == "CNT0" ]
  432. then
  433. info "Leg successfully completed according to IFS log file 'ifs.stat'."
  434. else
  435. error "Leg not completed according to IFS log file 'ifs.stat'."
  436. fi
  437. else
  438. error "IFS log file 'ifs.stat' not found after run."
  439. fi
  440. # -------------------------------------------------------------------------
  441. # *** Post-process initial conditions saved during the run if requested
  442. # -------------------------------------------------------------------------
  443. ${do_save_ic} && save_ic_postproc
  444. # -------------------------------------------------------------------------
  445. # *** Move IFS output files to archive directory
  446. # -------------------------------------------------------------------------
  447. outdir="output/ifs/$(printf %03d $((leg_number)))"
  448. mkdir -p ${outdir}
  449. prv_leg=$(printf %03d $((leg_number-1)))
  450. # This takes care of a special IFS feature: The output for the last time
  451. # step of each leg is written at the first time step of the new leg. The
  452. # following code makes sure that the output is appended to the appropriate
  453. # file. Since GRIB files are just streams, its done with a simple cat
  454. # command.
  455. for f in ICMSH${exp_name}+?????? ICMGG${exp_name}+??????
  456. do
  457. if [ -f output/ifs/${prv_leg}/${f} ]
  458. then
  459. cat ${f} >> output/ifs/${prv_leg}/${f}
  460. rm -f ${f}
  461. else
  462. mv ${f} ${outdir}
  463. fi
  464. done
  465. # -------------------------------------------------------------------------
  466. # *** Move IFS restart files to archive directory
  467. # -------------------------------------------------------------------------
  468. if $leg_is_restart
  469. then
  470. outdir="restart/ifs/$(printf %03d $((leg_number)))"
  471. mkdir -p ${outdir}
  472. # Figure out the time part of the restart files (cf. CTIME on rcf files)
  473. # NOTE: Assuming that restarts are at full days (time=0000) only!
  474. nd="$(printf %06d $((leg_start_sec/(24*3600))))0000"
  475. mv srf${nd}.???? ${outdir}
  476. fi
  477. # -------------------------------------------------------------------------
  478. # *** Copy rcf files to the archive directory (of the next leg!)
  479. # -------------------------------------------------------------------------
  480. outdir="restart/ifs/$(printf %03d $((leg_number+1)))"
  481. mkdir -p ${outdir}
  482. for f in rcf
  483. do
  484. test -f ${f} && cp ${f} ${outdir}
  485. done
  486. # -------------------------------------------------------------------------
  487. # *** Move log files to archive directory
  488. # -------------------------------------------------------------------------
  489. outdir="log/$(printf %03d $((leg_number)))"
  490. mkdir -p ${outdir}
  491. for f in \
  492. ifs.log ifs.stat fort.4 amip.log namelist.amip
  493. do
  494. test -f ${f} && mv ${f} ${outdir}
  495. done
  496. # -------------------------------------------------------------------------
  497. # *** Write the restart control file
  498. # -------------------------------------------------------------------------
  499. # Compute CPMIP performance
  500. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  501. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1)) $(($ifs_numproc + $amip_numproc)))"
  502. echo "#" | tee -a ${ece_info_file}
  503. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  504. | tee -a ${ece_info_file}
  505. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  506. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  507. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  508. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  509. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  510. force_run_from_scratch=false
  511. done # loop over legs
  512. # -----------------------------------------------------------------------------
  513. # *** Platform dependent finalising of the run
  514. # -----------------------------------------------------------------------------
  515. finalise
  516. exit 0