ece-ifs+nemo.sh.tmpl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. # librunscript defines some helper functions
  2. . ${start_dir}/librunscript.sh
  3. # =============================================================================
  4. # *** BEGIN User configuration
  5. # =============================================================================
  6. # -----------------------------------------------------------------------------
  7. # *** General configuration
  8. # -----------------------------------------------------------------------------
  9. # Component configuration
  10. # (for syntax of the $config variable, see librunscript.sh)
  11. config="ifs nemo lim3 rnfmapper xios:detached oasis"
  12. # Experiment name (exactly 4 letters!)
  13. exp_name=[[[MOD:GENERAL:EXP_NAME]]]
  14. # Simulation start and end date. Use any (reasonable) syntax you want.
  15. run_start_date="[[[MOD:GENERAL:RUN_START_DATE]]]"
  16. run_end_date="[[[MOD:GENERAL:RUN_END_DATE]]]"
  17. # Set $force_run_from_scratch to 'true' if you want to force this run to start
  18. # from scratch, possibly ignoring any restart files present in the run
  19. # directory. Leave set to 'false' otherwise.
  20. # NOTE: If set to 'true' the run directory $run_dir is cleaned!
  21. force_run_from_scratch=[[[MOD:GENERAL:FORCE_RUN_FROM_SCRATCH]]]
  22. special_restart=false
  23. special_restart_from=ECE3
  24. special_restart_date="1995-01-01"
  25. # Resolution
  26. ifs_grid=[[[MOD:IFS:GRID]]]
  27. nem_grid=[[[MOD:NEM:GRID]]]
  28. # Restart frequency. Use any (reasonable) number and time unit you want.
  29. # For runs without restart, leave this variable empty
  30. rst_freq="[[[MOD:GENERAL:RST_FREQ]]]"
  31. # Number of restart legs to be run in one go
  32. run_num_legs=[[[MOD:GENERAL:RUN_NUM_LEGS]]]
  33. # Coupling frequency between atmosphere and ocean (in seconds)
  34. cpl_freq_atm_oce_sec=[[[MOD:OASIS:CPL_FREQ_ATM_OCE_SEC]]]
  35. # Directories
  36. #start_dir=${PWD}
  37. ctrl_file_dir=${start_dir}/ctrl
  38. # Architecture
  39. build_arch=[[[PLT:ACTIVE:BUILD_ARCH]]]
  40. # This file is used to store information about restarts
  41. ece_info_file="ece.info"
  42. # -----------------------------------------------------------------------------
  43. # *** Read platform dependent configuration
  44. # -----------------------------------------------------------------------------
  45. . ${start_dir}/ecconf.cfg
  46. configure
  47. # -----------------------------------------------------------------------------
  48. # *** IFS configuration
  49. # -----------------------------------------------------------------------------
  50. ifs_version=36r4
  51. ifs_time_step_sec=[[[MOD:IFS:TIME_STEP_SEC]]]
  52. ifs_output_freq=$(( 6 * 3600 / ifs_time_step_sec ))
  53. ifs_di_freq=$(( 24 * 3600 / ifs_time_step_sec ))
  54. ifs_ddh_freq=$(( 120 * 3600 / ifs_time_step_sec ))
  55. ifs_res_hor=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\1:')
  56. ifs_res_ver=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\2:')
  57. ifs_numproc=[[[MOD:IFS:NUMPROC]]]
  58. ifs_exe_file=${ecearth_src_dir}/ifs-${ifs_version}/bin/ifsmaster-${build_arch}
  59. ifs_lastout=false
  60. ifs_cmip5=[[[MOD:IFS:CMIP5]]]
  61. ifs_cmip5_rcp=[[[MOD:IFS:CMIP5_RCP]]]
  62. ifs_cmip_fixyear=[[[MOD:IFS:CMIP_FIXYEAR]]]
  63. ifs_mac2sp=[[[MOD:IFS:MAC2SP]]]
  64. ifs_cmip6piaer=[[[MOD:IFS:CMIP6PIAER]]]
  65. ifs_cmip6=[[[MOD:IFS:CMIP6]]]
  66. ifs_A4xCO2=[[[MOD:IFS:CMIP6_A4xCO2]]]
  67. ifs_1PCTCO2=[[[MOD:IFS:CMIP6_1PCTCO2]]]
  68. # Time-varying orbital forcing (Qiong Zhang, SU-2013-09)
  69. # https://dev.ec-earth.org/projects/ecearth3/wiki/Orbital_forcing_in_EC-Earth_3
  70. #
  71. # ifs_orb_switch=FALSE, no orbital calculations applied
  72. # ifs_orb_switch=TRUE, use orbital calculations according to ifs_orb_mode
  73. # ifs_orb_mode="fixed_year", or "variable_year", or "fixed_parameters"
  74. # fixed_year: calculate the orbital parameters at ifs_orb_iyear, e.g.,1850
  75. # variable_year: calculate orbital parameters annually start from ifs_orb_iyear
  76. # fixed_parameters: prescribe orbital parameters for given year
  77. ifs_orb_switch=FALSE
  78. ifs_orb_mode="variable_year"
  79. ifs_orb_iyear=$(date -u -d "${run_start_date}" +%Y)
  80. # -----------------------------------------------------------------------------
  81. # *** IFS tuning (the commented values are EC-Earth 3.2beta and IFS cy36r4)
  82. # -----------------------------------------------------------------------------
  83. # ECE32b IFS cy36r4
  84. RPRCON=1.41E-3 # 1.2E-3 1.4E-3
  85. RVICE=0.125 # 0.13 0.15
  86. RLCRITSNOW=3.9E-5 # 3.0E-5 5.0E-5
  87. RSNOWLIN2=0.035 # 0.035 0.025
  88. ENTRORG=1.49E-4 # 1.5E-4 1.8E-4
  89. DETRPEN=0.7E-4 # 0.75E-4 0.75E-4
  90. ENTRDD=3.6E-4 # 3.0E-4 2.0E-4
  91. RMFDEPS=0.3 # 0.3 0.35
  92. # -----------------------------------------------------------------------------
  93. # *** NEMO/LIM configuration
  94. # -----------------------------------------------------------------------------
  95. nem_time_step_sec=[[[MOD:NEM:NEM_TIME_STEP_SEC]]]
  96. lim_time_step_sec=[[[MOD:NEM:LIM_TIME_STEP_SEC]]]
  97. # This is only needed if the experiment is started from an existing set of NEMO
  98. # restart files
  99. nem_restart_file_path=${start_dir}/nemo-rst
  100. nem_restart_offset=0
  101. nem_res_hor=$(echo ${nem_grid} | sed 's:ORCA\([0-9]\+\)L[0-9]\+:\1:')
  102. nem_exe_file=${ecearth_src_dir}/nemo-3.6/CONFIG/${nem_grid}_LIM3/BLD/bin/nemo.exe
  103. nem_numproc=[[[MOD:NEM:NUMPROC]]]
  104. # -----------------------------------------------------------------------------
  105. # *** Runoff mapper configuration
  106. # -----------------------------------------------------------------------------
  107. rnf_exe_file=${ecearth_src_dir}/runoff-mapper/bin/runoff-mapper.exe
  108. rnf_numproc=1
  109. # -----------------------------------------------------------------------------
  110. # *** OASIS configuration
  111. # -----------------------------------------------------------------------------
  112. # Restart files for the coupling fields (note 8 character limit in OASIS)
  113. # rstas.nc : atmoshpere single-category fields
  114. # rstam.nc : atmoshpere multi-category fields
  115. # rstos.nc : ocean single-category fields
  116. # rstom.nc : ocean multi-category fields
  117. oas_rst_files="rstas.nc rstos.nc"
  118. # Decide whether the OASIS weight files for interpolation should be linked from
  119. # the setup directory (true) or not (false). In the latter case, the weights
  120. # are re-computed at the start of the run.
  121. oas_link_weights=true
  122. # Flux correction for runoff (not calving) sent from Oasis to ocean.
  123. # 1.07945 is computed to compensate for a P-E=-0.016 mm/day
  124. oas_mb_fluxcorr=1.07945
  125. # -----------------------------------------------------------------------------
  126. # *** XIOS configuration
  127. # -----------------------------------------------------------------------------
  128. xio_exe_file=${ecearth_src_dir}/xios-2/bin/xios_server.exe
  129. xio_numproc=[[[MOD:XIO:NUMPROC]]]
  130. # =============================================================================
  131. # *** END of User configuration
  132. # =============================================================================
  133. # =============================================================================
  134. # *** This is where the code begins ...
  135. # =============================================================================
  136. # -----------------------------------------------------------------------------
  137. # *** Create the run dir if necessary and go there
  138. # Everything is done from here.
  139. # -----------------------------------------------------------------------------
  140. if [ ! -d ${run_dir} ]
  141. then
  142. mkdir -p ${run_dir}
  143. if $special_restart
  144. then
  145. force_run_from_scratch=false
  146. rsync -av --delete ${run_dir}/../${special_restart_from}/ --exclude log --exclude output --exclude restart --exclude="${special_restart_from}_*" --exclude="srf*" --exclude="restart_*" --exclude="debug.*" --exclude="output.*" ${run_dir}
  147. cp -f ${nem_exe_file} ${run_dir}
  148. cp -f ${ifs_exe_file} ${run_dir}
  149. cp -f ${rnf_exe_file} ${run_dir}
  150. cp -f ${xio_exe_file} ${run_dir}
  151. special_year=${special_restart_date:0:4}
  152. sed -i "/$special_year/q" ${run_dir}/ece.info
  153. . ${run_dir}/ece.info
  154. special_restart_leg=$(printf %03d $((leg_number+1)))
  155. # PUT HERE THE INSTRUCTIONS TO COPY THE restart files
  156. rsync -av ${run_dir}/../${special_restart_from}/restart/ifs/${special_restart_leg}/ ${run_dir}
  157. rsync -av ${run_dir}/../${special_restart_from}/restart/oasis/${special_restart_leg}/ ${run_dir}
  158. cd ${run_dir}/../${special_restart_from}/restart/nemo/${special_restart_leg}
  159. for f in *.nc; do
  160. nf=${exp_name}${f:4}
  161. cp $f ${run_dir}/$nf
  162. done
  163. cd -
  164. cd ${run_dir}
  165. for f in ${exp_name}_????????_restart_???_????.nc; do
  166. nf=${f:14}
  167. ln -s $f $nf
  168. done
  169. cd -
  170. rm -f ${run_dir}/ICMCL${special_restart_from}INIT
  171. mv ${run_dir}/ICMGG${special_restart_from}INIUA ${run_dir}/ICMGG${exp_name}INIUA
  172. mv ${run_dir}/ICMGG${special_restart_from}INIT ${run_dir}/ICMGG${exp_name}INIT
  173. mv ${run_dir}/ICMSH${special_restart_from}INIT ${run_dir}/ICMSH${exp_name}INIT
  174. fi
  175. else
  176. force_run_from_scratch=false
  177. special_restart=false
  178. fi
  179. cd ${run_dir}
  180. # -----------------------------------------------------------------------------
  181. # *** Determine the time span of this run and whether it's a restart leg
  182. # -----------------------------------------------------------------------------
  183. # Regularise the format of the start and end date of the simulation
  184. run_start_date=$(date -uR -d "${run_start_date}")
  185. run_end_date=$(date -uR -d "${run_end_date}")
  186. # Loop over the number of legs
  187. for (( ; run_num_legs>0 ; run_num_legs-- ))
  188. do
  189. # Check for restart information file and set the current leg start date
  190. # Ignore restart information file if force_run_from_scratch is true
  191. if ${force_run_from_scratch} || ! [ -r ${ece_info_file} ]
  192. then
  193. leg_is_restart=false
  194. leg_start_date=${run_start_date}
  195. leg_number=1
  196. else
  197. leg_is_restart=true
  198. . ./${ece_info_file}
  199. leg_start_date=${leg_end_date}
  200. leg_number=$((leg_number+1))
  201. fi
  202. # Compute the end date of the current leg
  203. if [ -n "${rst_freq}" ]
  204. then
  205. leg_end_date=$(date -uR -d "${leg_start_date} + ${rst_freq}")
  206. else
  207. leg_end_date=${run_end_date}
  208. fi
  209. if [ $(date -d "${leg_end_date}" +%s) -gt $(date -d "${run_end_date}" +%s) ]
  210. then
  211. leg_end_date=${run_end_date}
  212. fi
  213. # Some time variables needed later
  214. leg_length_sec=$(( $(date -d "${leg_end_date}" +%s) - $(date -d "${leg_start_date}" +%s) ))
  215. leg_start_sec=$(( $(date -d "${leg_start_date}" +%s) - $(date -d "${run_start_date}" +%s) ))
  216. leg_end_sec=$(( $(date -d "${leg_end_date}" +%s) - $(date -d "${run_start_date}" +%s) ))
  217. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d)
  218. leg_start_date_yyyy=$(date -u -d "${leg_start_date}" +%Y)
  219. leg_end_date_yyyy=$(date -u -d "${leg_end_date}" +%Y)
  220. # Check whether there's actually time left to simulate - exit otherwise
  221. if [ ${leg_length_sec} -le 0 ]
  222. then
  223. info "Leg start date equal to or after end of simulation."
  224. info "Nothing left to do. Exiting."
  225. exit 0
  226. fi
  227. # -------------------------------------------------------------------------
  228. # *** Prepare the run directory for a run from scratch
  229. # -------------------------------------------------------------------------
  230. if ! $leg_is_restart
  231. then
  232. # ---------------------------------------------------------------------
  233. # *** Check if run dir is empty. If not, and if we are allowed to do so
  234. # by ${force_run_from_scratch}, remove everything
  235. # ---------------------------------------------------------------------
  236. if $(ls * >& /dev/null)
  237. then
  238. if ${force_run_from_scratch}
  239. then
  240. rm -fr ${run_dir}/*
  241. else
  242. error "Run directory not empty and \$force_run_from_scratch not set."
  243. fi
  244. fi
  245. # ---------------------------------------------------------------------
  246. # *** Copy executables of model components
  247. # *** Additionally, create symlinks to the original place for reference
  248. # ---------------------------------------------------------------------
  249. cp ${ifs_exe_file} .
  250. ln -s ${ifs_exe_file} $(basename ${ifs_exe_file}).lnk
  251. cp ${nem_exe_file} .
  252. ln -s ${nem_exe_file} $(basename ${nem_exe_file}).lnk
  253. cp ${rnf_exe_file} .
  254. ln -s ${rnf_exe_file} $(basename ${rnf_exe_file}).lnk
  255. cp ${xio_exe_file} .
  256. ln -s ${xio_exe_file} $(basename ${xio_exe_file}).lnk
  257. # ---------------------------------------------------------------------
  258. # *** Files needed for IFS (linked)
  259. # ---------------------------------------------------------------------
  260. # Initial data
  261. ln -s \
  262. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIUA \
  263. ICMGG${exp_name}INIUA
  264. ln -s \
  265. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIT \
  266. ICMGG${exp_name}INIT
  267. ln -s \
  268. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMSHECE3INIT \
  269. ICMSH${exp_name}INIT
  270. # Other stuff
  271. ln -s ${ini_data_dir}/ifs/rtables/* .
  272. # Output control (ppt files)
  273. mkdir postins
  274. cp ${ctrl_file_dir}/ppt* postins/
  275. f_min=$(( ifs_output_freq * ifs_time_step_sec / 60 ))
  276. for t in $(seq $f_min $f_min 1439)
  277. do
  278. hh=$(printf %02d $((t/60)) )
  279. mm=$(printf %02d $((t%60)) )
  280. ln -s pptdddddd0000 postins/pptdddddd$hh$mm
  281. done
  282. /bin/ls -1 postins/* > dirlist
  283. # ---------------------------------------------------------------------
  284. # *** Files needed for NEMO (linked)
  285. # ---------------------------------------------------------------------
  286. # Link initialisation files for matching ORCA grid
  287. for f in \
  288. bathy_meter.nc coordinates.nc \
  289. ahmcoef.nc \
  290. K1rowdrg.nc M2rowdrg.nc mask_itf.nc \
  291. decay_scale_bot.nc decay_scale_cri.nc \
  292. mixing_power_bot.nc mixing_power_cri.nc mixing_power_pyc.nc \
  293. runoff_depth.nc
  294. do
  295. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && ln -s ${ini_data_dir}/nemo/initial/${nem_grid}/$f
  296. done
  297. # Link geothermal heating file (independent of grid) and matching weight file
  298. ln -s ${ini_data_dir}/nemo/initial/Goutorbe_ghflux.nc
  299. ln -s ${ini_data_dir}/nemo/initial/weights_Goutorbe1_2_orca${nem_res_hor}_bilinear.nc
  300. # Link either restart files or climatology files for the initial state
  301. if $(has_config nemo:start_from_restart)
  302. then
  303. # When linking restart files, we accept three options:
  304. # (1) Merged files for ocean and ice, i.e.
  305. # restart_oce.nc and restart_ice.nc
  306. # (2) One-file-per-MPI-rank, i.e.
  307. # restart_oce_????.nc and restart_ice_????.nc
  308. # No check is done whether the number of restart files agrees
  309. # with the number of MPI ranks for NEMO!
  310. # (3) One-file-per-MPI-rank with a prefix, i.e.
  311. # <exp_name>_<time_step>_restart_oce_????.nc (similar for the ice)
  312. # The prefix is ignored.
  313. # The code assumes that one of the options can be applied! If more
  314. # options are applicable, the first is chosen. If none of the
  315. # options apply, NEMO will crash with missing restart file.
  316. if ls -U ${nem_restart_file_path}/restart_[oi]ce.nc > /dev/null 2>&1
  317. then
  318. ln -s ${nem_restart_file_path}/restart_[oi]ce.nc ./
  319. elif ls -U ${nem_restart_file_path}/restart_[oi]ce_????.nc > /dev/null 2>&1
  320. then
  321. ln -s ${nem_restart_file_path}/restart_[oi]ce_????.nc ./
  322. else
  323. for f in ${nem_restart_file_path}/????_????????_restart_[oi]ce_????.nc
  324. do
  325. ln -s $f $(echo $f | sed 's/.*_\(restart_[oi]ce_....\.nc\)/\1/')
  326. done
  327. fi
  328. else
  329. # Temperature and salinity files for initialisation
  330. ln -s ${ini_data_dir}/nemo/climatology/absolute_salinity_WOA13_decav_Reg1L75_clim.nc
  331. ln -s ${ini_data_dir}/nemo/climatology/conservative_temperature_WOA13_decav_Reg1L75_clim.nc
  332. ln -s ${ini_data_dir}/nemo/climatology/weights_WOA13d1_2_orca${nem_res_hor}_bilinear.nc
  333. # Grid dependent runoff files
  334. case ${nem_grid} in
  335. ORCA1*) ln -s ${ini_data_dir}/nemo/climatology/runoff-icb_DaiTrenberth_Depoorter_ORCA1_JD.nc ;;
  336. ORCA025*) ln -s ${ini_data_dir}/nemo/climatology/ORCA_R025_runoff_v1.1.nc ;;
  337. esac
  338. fi
  339. # XIOS files
  340. . ${ctrl_file_dir}/iodef.xml.sh > iodef.xml
  341. ln -s ${ctrl_file_dir}/context_nemo.xml
  342. ln -s ${ctrl_file_dir}/domain_def_nemo.xml
  343. ln -s ${ctrl_file_dir}/field_def_nemo-lim.xml
  344. ln -s ${ctrl_file_dir}/field_def_nemo-opa.xml
  345. ln -s ${ctrl_file_dir}/field_def_nemo-pisces.xml
  346. ln -s ${ctrl_file_dir}/file_def_nemo-lim3.xml file_def_nemo-lim.xml
  347. ln -s ${ctrl_file_dir}/file_def_nemo-opa.xml
  348. ln -s ${ctrl_file_dir}/file_def_nemo-pisces.xml
  349. # ---------------------------------------------------------------------
  350. # *** Files needed for the Runoff mapper (linked)
  351. # ---------------------------------------------------------------------
  352. ln -s ${ini_data_dir}/runoff-mapper/runoff_maps.nc
  353. # ---------------------------------------------------------------------
  354. # *** Files needed for OASIS (linked)
  355. # ---------------------------------------------------------------------
  356. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-ORCA${nem_res_hor}
  357. # Name table file
  358. ln -s ${ini_data_dir}/oasis/cf_name_table.txt
  359. # Grid definition files
  360. ln -s ${oas_grid_dir}/areas.nc
  361. ln -s ${oas_grid_dir}/grids.nc
  362. ln -s ${oas_grid_dir}/masks.nc
  363. # Weight files
  364. case ${ifs_res_hor} in
  365. 159) oas_agrd=080
  366. ;;
  367. 255) oas_agrd=128
  368. ;;
  369. 511) oas_agrd=256
  370. ;;
  371. 799) oas_agrd=400
  372. ;;
  373. *) error "Unsupported horizontal resolution (IFS): ${ifs_res_hor}"
  374. ;;
  375. esac
  376. case ${nem_res_hor} in
  377. 1) oas_ogrd=O1t0
  378. ;;
  379. 025) oas_ogrd=Ot25
  380. ;;
  381. *) error "Unsupported horizontal resolution (NEMO): ${nem_res_hor}"
  382. ;;
  383. esac
  384. if ${oas_link_weights}
  385. then
  386. for f in ${oas_grid_dir}/rmp_????_to_????_GAUSWGT.nc
  387. do
  388. ln -s $f
  389. done
  390. fi
  391. for f in ${oas_rst_files}
  392. do
  393. cp ${oas_grid_dir}/rst/$f .
  394. done
  395. else # i.e. $leg_is_restart == true
  396. # ---------------------------------------------------------------------
  397. # *** Remove all leftover output files from previous legs
  398. # ---------------------------------------------------------------------
  399. # IFS files
  400. rm -f ICM{SH,GG}${exp_name}+??????
  401. # NEMO files
  402. rm -f ${exp_name}_??_????????_????????_{grid_U,grid_V,grid_W,grid_T,icemod,SBC,scalar,SBC_scalar}.nc
  403. fi # ! $leg_is_restart
  404. # -------------------------------------------------------------------------
  405. # *** Create some control files
  406. # -------------------------------------------------------------------------
  407. # IFS, NEMO, LIM namelist and OASIS namcouple files
  408. . ${ctrl_file_dir}/namelist.ifs.sh > fort.4
  409. . ${ctrl_file_dir}/namelist.nemo.ref.sh > namelist_ref
  410. . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-coupled.cfg.sh > namelist_cfg
  411. . ${ctrl_file_dir}/namelist.lim3.ref.sh > namelist_ice_ref
  412. . ${ctrl_file_dir}/namelist.lim3-${nem_grid}.cfg.sh > namelist_ice_cfg
  413. . ${ctrl_file_dir}/namelist.runoffmapper.sh > namelist.runoffmapper
  414. . ${ctrl_file_dir}/namcouple.sh > namcouple
  415. # -------------------------------------------------------------------------
  416. # *** IFS climatology data
  417. # -------------------------------------------------------------------------
  418. icmclfile=${ini_data_dir}/ifs/${ifs_grid}/climate/ICMCL
  419. tempfile=tmp.$$
  420. grib_set=${GRIB_BIN_PATH}${GRIB_BIN_PATH:+/}grib_set
  421. # Create data for december, the year before the leg starts
  422. ${grib_set} \
  423. -s dataDate=$(printf "%04d" $((leg_start_date_yyyy-1)))1215 ${icmclfile}-12 \
  424. ICMCL${exp_name}INIT
  425. # Create data for all month in the years of the leg
  426. for (( y=${leg_start_date_yyyy} ; y<=${leg_end_date_yyyy} ; y++ ))
  427. do
  428. yy=$(printf "%04d" $y)
  429. for m in {1..12}
  430. do
  431. mm=$(printf "%02d" $m)
  432. ${grib_set} -s dataDate=${yy}${mm}15 ${icmclfile}-${mm} ${tempfile}
  433. cat ${tempfile} >> ICMCL${exp_name}INIT
  434. done
  435. done
  436. # Create data for january, the year after the leg ends
  437. ${grib_set} -s dataDate=$(printf "%04d" $((leg_end_date_yyyy+1)))0115 ${icmclfile}-01 \
  438. ${tempfile}
  439. cat ${tempfile} >> ICMCL${exp_name}INIT
  440. # Clean up
  441. rm -f ${tempfile}
  442. # -------------------------------------------------------------------------
  443. # *** Link the appropriate NEMO restart files of the previous leg
  444. # -------------------------------------------------------------------------
  445. if $leg_is_restart
  446. then
  447. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  448. for (( n=0 ; n<nem_numproc ; n++ ))
  449. do
  450. np=$(printf %04d ${n})
  451. ln -fs ${exp_name}_${ns}_restart_oce_${np}.nc restart_oce_${np}.nc
  452. ln -fs ${exp_name}_${ns}_restart_ice_${np}.nc restart_ice_${np}.nc
  453. done
  454. # Make sure there are no global restart files
  455. # If links are found, they will be removed. We are cautious and do
  456. # _not_ remove real files! However, if real global restart files are
  457. # present, NEMO/LIM will stop because time stamps will not match.
  458. [ -h restart_oce.nc ] && rm restart_oce.nc
  459. [ -h restart_ice.nc ] && rm restart_ice.nc
  460. fi
  461. # -------------------------------------------------------------------------
  462. # *** Remove some OASIS files of the previous leg
  463. # -------------------------------------------------------------------------
  464. if $leg_is_restart
  465. then
  466. rm -f anaisout_*
  467. fi
  468. # -------------------------------------------------------------------------
  469. # *** Start the run
  470. # -------------------------------------------------------------------------
  471. export DR_HOOK_IGNORE_SIGNALS='-1'
  472. export CPLNG='active'
  473. # Use the launch function from the platform configuration file
  474. t1=$(date +%s)
  475. launch \
  476. ${xio_numproc} ${xio_exe_file} -- \
  477. ${nem_numproc} ${nem_exe_file} -- \
  478. ${rnf_numproc} ${rnf_exe_file} -- \
  479. ${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name}
  480. t2=$(date +%s)
  481. tr=$(date -d "0 -$t1 sec + $t2 sec" +%T)
  482. # -------------------------------------------------------------------------
  483. # *** Check for signs of success
  484. # Note the tests provide no guarantee that things went fine! They are
  485. # just based on the IFS and NEMO log files. More tests (e.g. checking
  486. # restart files) could be implemented.
  487. # -------------------------------------------------------------------------
  488. # Checking for IFS success
  489. if [ -f ifs.stat ]
  490. then
  491. if [ "$(awk 'END{print $3}' ifs.stat)" == "CNT0" ]
  492. then
  493. info "Leg successfully completed according to IFS log file 'ifs.stat'."
  494. else
  495. error "Leg not completed according to IFS log file 'ifs.stat'."
  496. fi
  497. else
  498. error "IFS log file 'ifs.stat' not found after run."
  499. fi
  500. # Check for NEMO success
  501. if [ -f ocean.output ]
  502. then
  503. if [ "$(awk '/New day/{d=$10}END{print d}' ocean.output)" == "$(date -d "${leg_end_date} - 1 day" +%Y/%m/%d)" ]
  504. then
  505. info "Leg successfully completed according to NEMO log file 'ocean.output'."
  506. else
  507. error "Leg not completed according to NEMO log file 'ocean.output'."
  508. fi
  509. else
  510. error "NEMO log file 'ocean.output' not found after run."
  511. fi
  512. # -------------------------------------------------------------------------
  513. # *** Move IFS output files to archive directory
  514. # -------------------------------------------------------------------------
  515. outdir="${archive_dir}/output/ifs/$(printf %03d $((leg_number)))"
  516. mkdir -p ${outdir}
  517. prv_leg=$(printf %03d $((leg_number-1)))
  518. # This takes care of a special IFS feature: The output for the last time
  519. # step of each leg is written at the first time step of the new leg. The
  520. # following code makes sure that the output is appended to the appropriate
  521. # file. Since GRIB files are just streams, its done with a simple cat
  522. # command.
  523. for f in ICMSH${exp_name}+?????? ICMGG${exp_name}+??????
  524. do
  525. if [ -f output/ifs/${prv_leg}/${f} ]
  526. then
  527. cat ${f} >> output/ifs/${prv_leg}/${f}
  528. rm -f ${f}
  529. else
  530. mv ${f} ${outdir}
  531. fi
  532. done
  533. # -------------------------------------------------------------------------
  534. # *** Move NEMO output files to archive directory
  535. # -------------------------------------------------------------------------
  536. outdir="${archive_dir}/output/nemo/$(printf %03d $((leg_number)))"
  537. mkdir -p ${outdir}
  538. for f in ${exp_name}_??_????????_????????_*.nc ; do mv $f $outdir/ ; done
  539. #for v in grid_U grid_V grid_W grid_T icemod SBC scalar SBC_scalar
  540. #do
  541. # for f in ${exp_name}_??_????????_????????_${v}.nc
  542. # do
  543. # test -f $f && mv $f $outdir/
  544. # done
  545. #done
  546. # -------------------------------------------------------------------------
  547. # *** Move IFS restart files to archive directory
  548. # -------------------------------------------------------------------------
  549. if $leg_is_restart
  550. then
  551. outdir="${archive_dir}/restart/ifs/$(printf %03d $((leg_number)))"
  552. mkdir -p ${outdir}
  553. # Figure out the time part of the restart files (cf. CTIME on rcf files)
  554. # NOTE: Assuming that restarts are at full days (time=0000) only!
  555. nd="$(printf %06d $((leg_start_sec/(24*3600))))0000"
  556. mv srf${nd}.???? ${outdir}
  557. fi
  558. # -------------------------------------------------------------------------
  559. # *** Move NEMO restart files to archive directory
  560. # -------------------------------------------------------------------------
  561. if $leg_is_restart
  562. then
  563. outdir="${archive_dir}/restart/nemo/$(printf %03d $((leg_number)))"
  564. mkdir -p ${outdir}
  565. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  566. for f in oce ice
  567. do
  568. mv ${exp_name}_${ns}_restart_${f}_????.nc ${outdir}
  569. done
  570. fi
  571. # -------------------------------------------------------------------------
  572. # *** Copy OASIS restart files to archive directory
  573. # NOTE: These files are copied and not moved as they are used in the
  574. # next leg!
  575. # Note also that the OASIS restart files present at the end of
  576. # the leg correspond to the start of the next leg!
  577. # -------------------------------------------------------------------------
  578. outdir="${archive_dir}/restart/oasis/$(printf %03d $((leg_number+1)))"
  579. mkdir -p ${outdir}
  580. for f in ${oas_rst_files}
  581. do
  582. test -f ${f} && cp ${f} ${outdir}
  583. done
  584. # -------------------------------------------------------------------------
  585. # *** Copy rcf files to the archive directory (of the next leg!)
  586. # -------------------------------------------------------------------------
  587. outdir="${archive_dir}/restart/ifs/$(printf %03d $((leg_number+1)))"
  588. mkdir -p ${outdir}
  589. for f in rcf
  590. do
  591. test -f ${f} && cp ${f} ${outdir}
  592. done
  593. # -------------------------------------------------------------------------
  594. # *** Move log files to archive directory
  595. # -------------------------------------------------------------------------
  596. outdir="${archive_dir}/log/$(printf %03d $((leg_number)))"
  597. mkdir -p ${outdir}
  598. for f in \
  599. ifs.log ifs.stat fort.4 ocean.output \
  600. time.step solver.stat \
  601. nout.000000 debug.??.?????? A*_??.nc O*_??.nc
  602. do
  603. test -f ${f} && mv ${f} ${outdir}
  604. done
  605. # -------------------------------------------------------------------------
  606. # *** Write the restart control file
  607. # -------------------------------------------------------------------------
  608. # Compute CPMIP performance
  609. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  610. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1)) $(($ifs_numproc + $nem_numproc + $rnf_numproc + $xio_numproc)))"
  611. echo "#" | tee -a ${ece_info_file}
  612. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  613. | tee -a ${ece_info_file}
  614. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  615. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  616. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  617. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  618. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  619. force_run_from_scratch=false
  620. special_restart=false
  621. done # loop over legs
  622. # -----------------------------------------------------------------------------
  623. # *** Platform dependent finalising of the run
  624. # -----------------------------------------------------------------------------
  625. finalise
  626. exit 0