ece-ifs.sh.tmpl 24 KB

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