ece-nemo.sh.tmpl 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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
  13. # (for syntax of the $config variable, see librunscript.sh)
  14. # get config from autosubmit variables
  15. [[ "%OCEAN_ini%" = *[!\ ]* ]] && start_nemo_from_restart=":start_from_restart" || start_nemo_from_restart=""
  16. [[ "%PISCES_ini%" = *[!\ ]* ]] && start_pisces_from_restart=":start_from_restart" || start_pisces_from_restart=""
  17. [ "%OCE_NUDG%" = TRUE ] && ocenudg=":ocenudg" || ocenudg=""
  18. [ "%SURF_RESTO%" = TRUE ] && surfresto=":surfresto" || surfresto=""
  19. [ "%PISCES%" = TRUE ] && [ "%PISCES_OFF%" = FALSE ] && pisces="pisces" || pisces=""
  20. [ "%PISCES_OFF%" = TRUE ] && pisces="pisces:offline"
  21. [ "%NEMO_remove_land%" = TRUE ] && elpin=":elpin" || elpin=""
  22. if [[ "%SAVE_IC%" = FALSE ]] || [[ "%SAVE_IC%" = "" ]]; then save_ic="" ; else save_ic="save_ic:%SAVE_IC%" ; fi
  23. config="nemo${start_nemo_from_restart}${ocenudg}${surfresto}${elpin} ${pisces}${start_pisces_from_restart} lim3 xios:detached ${save_ic}"
  24. nem_forcing_set=%NEM_FORCING_SET%
  25. nem_fixed_forcing_year=%NEM_FIXED_FORCING_YEAR%
  26. if [ -z ${nem_forcing_set-} ] ; then nem_forcing_set=CoreII ; fi
  27. # Experiment name (exactly 4 letters!)
  28. export exp_name=[[[MOD:GENERAL:EXP_NAME]]]
  29. # Simulation start and end date. Use any (reasonable) syntax you want.
  30. run_start_date="[[[MOD:GENERAL:RUN_START_DATE]]]"
  31. # define run_start_date_as with proper format e.g. 19900101
  32. export run_start_date_as=$(date -u -d "${run_start_date}" +%Y%m%d)
  33. run_end_date="[[[MOD:GENERAL:RUN_END_DATE]]]"
  34. # Simulation member. Use any (reasonable) syntax you want.
  35. export member="%MEMBER%"
  36. # Set $force_run_from_scratch to 'true' if you want to force this run to start
  37. # from scratch, possibly ignoring any restart files present in the run
  38. # directory. Leave set to 'false' otherwise.
  39. # NOTE: If set to 'true' the run directory $run_dir is cleaned!
  40. CHUNK=%CHUNK%
  41. force_run_from_scratch=[[[MOD:GENERAL:FORCE_RUN_FROM_SCRATCH]]]
  42. force_run_from_scratch=${force_run_from_scratch:-false}
  43. force_run_from_scratch=$(echo ${force_run_from_scratch} | tr '[:upper:]' '[:lower:]')
  44. # we only apply this for the first chunk
  45. if ${force_run_from_scratch} && [[ "${CHUNK}" != "1" ]] ; then
  46. force_run_from_scratch=false
  47. fi
  48. # Resolution
  49. nem_grid=[[[MOD:NEM:GRID]]]
  50. # Restart frequency. Use any (reasonable) number and time unit you want.
  51. # For runs without restart, leave this variable empty
  52. rst_freq="[[[MOD:GENERAL:RST_FREQ]]]"
  53. # Number of restart legs to be run in one go
  54. run_num_legs=[[[MOD:GENERAL:RUN_NUM_LEGS]]]
  55. # Directories
  56. start_dir=${PWD}
  57. ctrl_file_dir=${start_dir}/ctrl
  58. output_control_files_dir=${start_dir}/[[[MOD:GENERAL:OUTPUT_CONTROL_FILES_DIR]]]
  59. # Architecture
  60. build_arch=[[[PLT:ACTIVE:BUILD_ARCH]]]
  61. use_machinefile=[[[PLT:ACTIVE:USE_MACHINEFILE]]]
  62. # This file is used to store information about restarts
  63. ece_info_file="ece.info"
  64. # -----------------------------------------------------------------------------
  65. # *** Read platform dependent configuration
  66. # -----------------------------------------------------------------------------
  67. source ./ecconf.cfg
  68. configure
  69. # -----------------------------------------------------------------------------
  70. # *** Time step settings
  71. # -----------------------------------------------------------------------------
  72. case "${nem_grid}" in
  73. ORCA1L*) nem_time_step_sec=2700; lim_time_step_sec=2700 ;;
  74. ORCA025L*) nem_time_step_sec=900 ; lim_time_step_sec=900 ;;
  75. *) error "Can't set time steps for unknown horizontal grid: ${nem_grid}"
  76. ;;
  77. esac
  78. # -----------------------------------------------------------------------------
  79. # *** NEMO/LIM configuration
  80. # -----------------------------------------------------------------------------
  81. # This is only needed if the experiment is started from an existing set of NEMO
  82. # restart files
  83. nem_restart_file_path=${ini_data_dir}
  84. nem_restart_offset=0
  85. nem_res_hor=$(echo ${nem_grid} | sed 's:ORCA\([0-9]\+\)L[0-9]\+:\1:')
  86. # Pick correct NEMO configuration, which is one of:
  87. # NEMO standalone, NEMO+PISCES-standaone, PISCES-offline
  88. nem_config_name=${nem_grid}_LIM3_standalone
  89. has_config pisces && nem_config_name=${nem_grid}_LIM3_PISCES_standalone
  90. has_config pisces:offline && nem_config_name=${nem_grid}_OFF_PISCES_standalone
  91. nem_exe_file=${ecearth_src_dir}/nemo-3.6/CONFIG/${nem_config_name}/BLD/bin/nemo.exe
  92. nem_numproc=[[[MOD:NEM:NUMPROC]]]
  93. # Thermal conductivity of snow, see comment in ctrl/namelist.lim3.ref.sh
  94. nem_rn_cdsn=0.27
  95. # -----------------------------------------------------------------------------
  96. # *** XIOS configuration
  97. # -----------------------------------------------------------------------------
  98. xio_exe_file=${ecearth_src_dir}/xios-2.5/bin/xios_server.exe
  99. xio_numproc=[[[MOD:XIO:NUMPROC]]]
  100. # -----------------------------------------------------------------------------
  101. # *** Extra initial conditions saved during the run
  102. # -----------------------------------------------------------------------------
  103. if has_config save_ic
  104. then
  105. source ./libsave_ic.sh
  106. declare -a save_ic_date save_ic_date1 save_ic_sec save_ic_day save_ic_ppt_file save_ic_nemo_ts
  107. fi
  108. # =============================================================================
  109. # *** END of User configuration
  110. # =============================================================================
  111. # =============================================================================
  112. # *** This is where the code begins ...
  113. # =============================================================================
  114. # -----------------------------------------------------------------------------
  115. # *** Create the run dir if necessary and go there
  116. # Everything is done from here.
  117. # -----------------------------------------------------------------------------
  118. if [ ! -d ${run_dir} ]
  119. then
  120. mkdir -p ${run_dir}
  121. fi
  122. cd ${run_dir}
  123. # -----------------------------------------------------------------------------
  124. # *** Determine the time span of this run and whether it's a restart leg
  125. # -----------------------------------------------------------------------------
  126. # Regularise the format of the start and end date of the simulation
  127. run_start_date=$(absolute_date_noleap "${run_start_date}")
  128. run_end_date=$(absolute_date_noleap "${run_end_date}")
  129. # Loop over the number of legs
  130. for (( ; run_num_legs>0 ; run_num_legs-- ))
  131. do
  132. # Check for restart information file and set the current leg start date
  133. # Ignore restart information file if force_run_from_scratch is true
  134. if ${force_run_from_scratch} || ! [ -r ${ece_info_file} ]
  135. then
  136. leg_is_restart=false
  137. leg_start_date=${run_start_date}
  138. leg_number=1
  139. else
  140. leg_is_restart=true
  141. . ./${ece_info_file}
  142. leg_start_date=${leg_end_date}
  143. leg_number=$((leg_number+1))
  144. fi
  145. # Compute the end date of the current leg
  146. if [ -n "${rst_freq}" ]
  147. then
  148. leg_end_date=$(absolute_date_noleap "${leg_start_date} + ${rst_freq}")
  149. else
  150. leg_end_date=${run_end_date}
  151. fi
  152. if [ $(date -d "${leg_end_date}" +%s) -gt $(date -d "${run_end_date}" +%s) ]
  153. then
  154. leg_end_date=${run_end_date}
  155. fi
  156. # Some time variables needed later
  157. leg_length_sec=$(( $(date -d "${leg_end_date}" +%s) - $(date -d "${leg_start_date}" +%s) ))
  158. leg_start_sec=$(( $(date -d "${leg_start_date}" +%s) - $(date -d "${run_start_date}" +%s) ))
  159. leg_end_sec=$(( $(date -d "${leg_end_date}" +%s) - $(date -d "${run_start_date}" +%s) ))
  160. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d)
  161. leg_start_date_yyyy=$(date -u -d "${leg_start_date}" +%Y)
  162. leg_end_date_yyyy=$(date -u -d "${leg_end_date}" +%Y)
  163. # Correct for leap days because NEMO standalone uses no-leap calendar
  164. leg_length_sec=$(( leg_length_sec - $(leap_days "${leg_start_date}" "${leg_end_date}")*24*3600 ))
  165. leg_start_sec=$(( leg_start_sec - $(leap_days "${run_start_date}" "${leg_start_date}")*24*3600 ))
  166. leg_end_sec=$(( leg_end_sec - $(leap_days "${run_start_date}" "${leg_end_date}")*24*3600 ))
  167. # Check whether there's actually time left to simulate - exit otherwise
  168. if [ ${leg_length_sec} -le 0 ]
  169. then
  170. info "Leg start date equal to or after end of simulation."
  171. info "Nothing left to do. Exiting."
  172. exit 0
  173. fi
  174. # Initial conditions saved during the run
  175. do_save_ic=false
  176. save_ic_custom=false
  177. has_config save_ic && save_ic_get_config
  178. # if you do not use an option with save_ic, you must define 'do_save_ic' and
  179. # 'save_ic_date_offset' here or in ../libsave_ic.sh/save_ic_get_config()
  180. # with AS runtime, no need to edit the script, set SAVE_IC_OFFSET (and optionally SAVE_IC_COND)
  181. if $save_ic_custom
  182. then
  183. [[ "%SAVE_IC_COND%" = "" ]] && save_ic_cond=true || save_ic_cond='%SAVE_IC_COND%'
  184. if eval $save_ic_cond ; then do_save_ic=true ; else do_save_ic=false ; fi
  185. save_ic_date_offset=( %SAVE_IC_OFFSET% )
  186. fi
  187. ${do_save_ic} && save_ic_define_vars
  188. # -------------------------------------------------------------------------
  189. # *** Prepare the run directory for a run from scratch
  190. # -------------------------------------------------------------------------
  191. if ! $leg_is_restart
  192. then
  193. # ---------------------------------------------------------------------
  194. # *** Check if run dir is empty. If not, and if we are allowed to do so
  195. # by ${force_run_from_scratch}, remove everything
  196. # ---------------------------------------------------------------------
  197. if $(ls * >& /dev/null)
  198. then
  199. if ${force_run_from_scratch}
  200. then
  201. rm -fr ${run_dir}/*
  202. else
  203. error "Run directory not empty and \$force_run_from_scratch not set."
  204. fi
  205. fi
  206. # ---------------------------------------------------------------------
  207. # *** Copy executables of model components
  208. # *** Additionally, create symlinks to the original place for reference
  209. # ---------------------------------------------------------------------
  210. cp ${nem_exe_file} .
  211. ln -s ${nem_exe_file} $(basename ${nem_exe_file}).lnk
  212. cp ${xio_exe_file} .
  213. ln -s ${xio_exe_file} $(basename ${xio_exe_file}).lnk
  214. # ---------------------------------------------------------------------
  215. # *** Files needed for NEMO (linked)
  216. # ---------------------------------------------------------------------
  217. # Link initialisation files for matching ORCA grid
  218. for f in \
  219. bathy_meter.nc coordinates.nc \
  220. ahmcoef.nc \
  221. K1rowdrg.nc M2rowdrg.nc mask_itf.nc \
  222. decay_scale_bot.nc decay_scale_cri.nc \
  223. mixing_power_bot.nc mixing_power_cri.nc mixing_power_pyc.nc \
  224. runoff_depth.nc subbasins.nc
  225. do
  226. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && ln -s ${ini_data_dir}/nemo/initial/${nem_grid}/$f
  227. done
  228. # Copying the time independent NEMO files for the matching ORCA grid in order to facilitate cmorisation:
  229. for f in \
  230. bathy_meter.nc subbasins.nc
  231. do
  232. mkdir -p output/nemo/ofx-data
  233. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && cp -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f output/nemo/ofx-data/
  234. done
  235. # Link geothermal heating file (independent of grid) and matching weight file
  236. ln -s ${ini_data_dir}/nemo/initial/Goutorbe_ghflux.nc
  237. ln -s ${ini_data_dir}/nemo/initial/weights_Goutorbe1_2_orca${nem_res_hor}_bilinear.nc
  238. # Link either restart files or climatology files for the initial state
  239. if $(has_config nemo:start_from_restart)
  240. then
  241. # When linking restart files, we accept three options:
  242. # (1) Merged files for ocean and ice, i.e.
  243. # restart_oce.nc and restart_ice.nc
  244. # (2) One-file-per-MPI-rank, i.e.
  245. # restart_oce_????.nc and restart_ice_????.nc
  246. # No check is done whether the number of restart files agrees
  247. # with the number of MPI ranks for NEMO!
  248. # (3) One-file-per-MPI-rank with a prefix, i.e.
  249. # <exp_name>_<time_step>_restart_oce_????.nc (similar for the ice)
  250. # The prefix is ignored.
  251. # The code assumes that one of the options can be applied! If more
  252. # options are applicable, the first is chosen. If none of the
  253. # options apply, NEMO will crash with missing restart file.
  254. if ls -U ${nem_restart_file_path}/restart_[oi]ce.nc > /dev/null 2>&1
  255. then
  256. ln -s ${nem_restart_file_path}/restart_[oi]ce.nc ./
  257. elif ls -U ${nem_restart_file_path}/restart_[oi]ce_????.nc > /dev/null 2>&1
  258. then
  259. ln -s ${nem_restart_file_path}/restart_[oi]ce_????.nc ./
  260. else
  261. for f in ${nem_restart_file_path}/????_????????_restart_[oi]ce_????.nc
  262. do
  263. ln -s $f $(echo $f | sed 's/.*_\(restart_[oi]ce_....\.nc\)/\1/')
  264. done
  265. fi
  266. else
  267. # Temperature and salinity files for initialisation
  268. ln -s ${ini_data_dir}/nemo/climatology/absolute_salinity_WOA13_decav_Reg1L75_clim.nc
  269. ln -s ${ini_data_dir}/nemo/climatology/conservative_temperature_WOA13_decav_Reg1L75_clim.nc
  270. ln -s ${ini_data_dir}/nemo/climatology/weights_WOA13d1_2_orca${nem_res_hor}_bilinear.nc
  271. fi
  272. # Grid dependent runoff files
  273. case ${nem_grid} in
  274. ORCA1*)
  275. ln -s ${ini_data_dir}/nemo/climatology/runoff-icb_DaiTrenberth_Depoorter_ORCA1_JD.nc
  276. if [[ "${nem_forcing_set}" == "JRA55_1.4" ]] ; then
  277. ln -s ${ini_data_dir}/nemo/forcing/JRA55_1.4/runoff_depth_JRA.nc
  278. fi
  279. ;;
  280. ORCA025*)
  281. ln -s ${ini_data_dir}/nemo/climatology/ORCA_R025_runoff_v1.1.nc
  282. ;;
  283. esac
  284. #for ocean_nudging
  285. if $(has_config nemo:ocenudg) ; then
  286. ln -fs ${ini_data_dir}/nemo/oce_nudg/resto.nc ./
  287. fi
  288. # Salinity file (needed for diagnostics)
  289. [ -f ${ini_data_dir}/nemo/climatology/${nem_grid}/sali_ref_clim_monthly.nc ] && ln -s ${ini_data_dir}/nemo/climatology/${nem_grid}/sali_ref_clim_monthly.nc
  290. # Write fake file for previous fresh water budget adjustment (nn_fwb==2 in namelist)
  291. echo " 0 0.0000000000000000E+00 0.0000000000000000E+00" > EMPave_old.dat
  292. # XIOS files
  293. . ${ctrl_file_dir}/iodef.xml.sh > iodef.xml
  294. ln -s ${ctrl_file_dir}/context_nemo.xml
  295. . ${ctrl_file_dir}/domain_def_nemo.xml.sh > domain_def_nemo.xml
  296. ln -s ${ctrl_file_dir}/axis_def_nemo.xml
  297. ln -s ${ctrl_file_dir}/grids_def_nemo.xml
  298. ln -s ${ctrl_file_dir}/field_def_nemo-lim.xml
  299. ln -s ${ctrl_file_dir}/field_def_nemo-opa.xml
  300. ln -s ${ctrl_file_dir}/field_def_nemo-pisces.xml
  301. ln -s ${ctrl_file_dir}/field_def_nemo-inerttrc.xml
  302. ln -s ${output_control_files_dir}/file_def_nemo-lim3.xml file_def_nemo-lim.xml
  303. ln -s ${output_control_files_dir}/file_def_nemo-opa.xml
  304. ln -s ${output_control_files_dir}/file_def_nemo-pisces.xml
  305. if [ -f ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ]
  306. then
  307. cp ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ./
  308. else
  309. info "File 'coordinates_xios.nc' not found. NEMO can not be run with land domain removal!"
  310. fi
  311. # ---------------------------------------------------------------------
  312. # *** Files needed for TOP/PISCES (linked)
  313. # ---------------------------------------------------------------------
  314. if $(has_config pisces)
  315. then
  316. ln -fs ${ini_data_dir}/nemo/pisces/dust_INCA_ORCA_R1.nc
  317. ln -fs ${ini_data_dir}/nemo/pisces/ndeposition_Duce_ORCA_R1.nc
  318. ln -fs ${ini_data_dir}/nemo/pisces/pmarge_etopo_ORCA_R1.nc
  319. ln -fs ${ini_data_dir}/nemo/pisces/river_global_news_ORCA_R1.nc
  320. ln -fs ${ini_data_dir}/nemo/pisces/Solubility_T62_Mahowald_ORCA_R1.nc
  321. ln -fs ${ini_data_dir}/nemo/pisces/par_fraction_gewex_clim90s00s_ORCA_R1.nc
  322. ln -fs ${ini_data_dir}/nemo/pisces/DIC_GLODAP_annual_ORCA_R1.nc
  323. ln -fs ${ini_data_dir}/nemo/pisces/Alkalini_GLODAP_annual_ORCA_R1.nc
  324. ln -fs ${ini_data_dir}/nemo/pisces/O2_WOA2009_monthly_ORCA_R1.nc
  325. ln -fs ${ini_data_dir}/nemo/pisces/PO4_WOA2009_monthly_ORCA_R1.nc
  326. ln -fs ${ini_data_dir}/nemo/pisces/Si_WOA2009_monthly_ORCA_R1.nc
  327. ln -fs ${ini_data_dir}/nemo/pisces/DOC_PISCES_monthly_ORCA_R1.nc
  328. ln -fs ${ini_data_dir}/nemo/pisces/Fer_PISCES_monthly_ORCA_R1.nc
  329. ln -fs ${ini_data_dir}/nemo/pisces/NO3_WOA2009_monthly_ORCA_R1.nc
  330. ln -fs ${ini_data_dir}/nemo/pisces/mole-fraction-of-carbon-dioxide-in-air_input4MIPs_GHGConcentrations_CMIP_UoM-CMIP-1-2-0_gr1-GMNHSH_1637-2019.txt atcco2.txt
  331. fi
  332. #linking surface boundary conditions for CFCs (even if CFCs are not included)
  333. ln -fs ${ini_data_dir}/nemo/cfc/CFCs_CDIAC_extension_1637_2019.dat CFCs_CDIAC.dat
  334. if $(has_config pisces:start_from_restart)
  335. then
  336. # Same three options as for nemo:start_from_restart
  337. if ls -U ${nem_restart_file_path}/restart_trc.nc > /dev/null 2>&1
  338. then
  339. ln -s ${nem_restart_file_path}/restart_trc.nc ./
  340. elif ls -U ${nem_restart_file_path}/restart_trc_????.nc > /dev/null 2>&1
  341. then
  342. ln -s ${nem_restart_file_path}/restart_trc_????.nc ./
  343. else
  344. for f in ${nem_restart_file_path}/????_????????_restart_trc_????.nc
  345. do
  346. ln -s $f $(echo $f | sed 's/.*_\(restart_trc_....\.nc\)/\1/')
  347. done
  348. fi
  349. fi
  350. # ---------------------------------------------------------------------
  351. # *** Files needed for TOP/PISCES (linked) ADDED FOR PISCES OFFLINE
  352. # ---------------------------------------------------------------------
  353. if $(has_config pisces:offline)
  354. then
  355. ln -fs ${ini_data_dir}/nemo/pisces/pisces_dyn/OfflineForcing_grid_U.nc OfflineForcing_grid_U.nc
  356. ln -fs ${ini_data_dir}/nemo/pisces/pisces_dyn/OfflineForcing_grid_V.nc OfflineForcing_grid_V.nc
  357. ln -fs ${ini_data_dir}/nemo/pisces/pisces_dyn/OfflineForcing_grid_W.nc OfflineForcing_grid_W.nc
  358. ln -fs ${ini_data_dir}/nemo/pisces/pisces_dyn/OfflineForcing_grid_T.nc OfflineForcing_grid_T.nc
  359. ln -fs ${ctrl_file_dir}/context_nemo_offline.xml context_nemo.xml
  360. fi
  361. else # i.e. $leg_is_restart == true
  362. # ---------------------------------------------------------------------
  363. # *** Remove all leftover output files from previous legs
  364. # ---------------------------------------------------------------------
  365. # NEMO output files
  366. rm -f ${exp_name}_??_????????_????????_{grid_U,grid_V,grid_W,grid_T,icemod,SBC,scalar,SBC_scalar,diad_T}.nc
  367. restart_dir="restart/nemo/$(printf %03d $((leg_number)))"
  368. if ! $(has_config pisces:offline) ; then
  369. [ -f ${restart_dir}/EMPave_old.dat ] && cp ${restart_dir}/EMPave_old.dat .
  370. fi
  371. fi # ! $leg_is_restart
  372. #--------------------------------------------------------------------------
  373. # *** Surface restoring and ocean nudging options
  374. #--------------------------------------------------------------------------
  375. #for ocean_nudging
  376. if $(has_config nemo:ocenudg) ; then
  377. ln -fs ${ini_data_dir}/nemo/oce_nudg/temp_sal_*.nc ./
  378. fi
  379. #for surface restoring
  380. if $(has_config nemo:surfresto) ; then
  381. ln -fs ${ini_data_dir}/nemo/surface_restoring/sss_restore_data*.nc ./
  382. ln -fs ${ini_data_dir}/nemo/surface_restoring/sst_restore_data*.nc ./
  383. ln -fs ${ini_data_dir}/nemo/surface_restoring/mask_restore*.nc ./
  384. fi
  385. # -------------------------------------------------------------------------
  386. # *** Remove land grid-points
  387. # -------------------------------------------------------------------------
  388. if $(has_config nemo:elpin)
  389. then
  390. if [ ! -f coordinates_xios.nc ]
  391. then
  392. error "ELpIN requested, but file 'coordinates_xios.nc' was not found"
  393. fi
  394. jpns=($(${ecearth_src_dir}/util/ELPiN/ELPiNv2.cmd ${nem_numproc}))
  395. info "nemo domain decompostion from ELpIN: ${jpns[@]}"
  396. nem_numproc=${jpns[0]}
  397. nem_jpni=${jpns[1]}
  398. nem_jpnj=${jpns[2]}
  399. else
  400. info "nemo original domain decomposition (not using ELPiN)"
  401. fi
  402. # -------------------------------------------------------------------------
  403. # *** Initial conditions saved during the run
  404. # -------------------------------------------------------------------------
  405. ${do_save_ic} && save_ic_prepare_output
  406. # -------------------------------------------------------------------------
  407. # *** Create some control files
  408. # -------------------------------------------------------------------------
  409. # used in namelist.nemo
  410. is_climatology=".true."
  411. if [[ "${nem_forcing_set}" == "JRA55_1.4" || "${nem_forcing_set}" == "era5" || "${nem_forcing_set}" == "ERA5_HRES" || "${nem_forcing_set}" == "ERA5_ENDA" ]] ; then
  412. ln_dm2dc=".false."
  413. else
  414. ln_dm2dc=".true."
  415. fi
  416. if [[ ${nem_fixed_forcing_year-} == -1 ]] && ! [[ "${nem_forcing_set}" == "CoreII" ]] ; then is_climatology=".false." ; fi
  417. if [[ "${nem_forcing_set}" == "JRA55_1.4" ]] ; then
  418. forcing_runoff="namelist.nemo-runoff-JRA55_1.4"
  419. else
  420. forcing_runoff="namelist.nemo-runoff-default"
  421. fi
  422. # NEMO and LIM namelists
  423. . ${ctrl_file_dir}/namelist.nemo.ref.sh > namelist_ref
  424. . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-standalone.cfg.sh > namelist_cfg
  425. . ${ctrl_file_dir}/namelist.lim3.ref.sh > namelist_ice_ref
  426. . ${ctrl_file_dir}/namelist.lim3-${nem_grid}.cfg.sh > namelist_ice_cfg
  427. # NEMO/TOP+PISCES namelists
  428. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.top.ref.sh > namelist_top_ref
  429. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.top.cfg.sh > namelist_top_cfg
  430. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.pisces.ref.sh > namelist_pisces_ref
  431. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.pisces.cfg.sh > namelist_pisces_cfg
  432. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.age.ref.sh > namelist_age_ref
  433. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.age.cfg.sh > namelist_age_cfg
  434. #include CFCs namelist even if CFCs are not included
  435. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.cfc.ref.sh > namelist_cfc_ref
  436. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.cfc.cfg.sh > namelist_cfc_cfg
  437. # -------------------------------------------------------------------------
  438. # *** Link the appropriate NEMO restart files of the previous leg
  439. # -------------------------------------------------------------------------
  440. if $leg_is_restart
  441. then
  442. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  443. for (( n=0 ; n<nem_numproc ; n++ ))
  444. do
  445. np=$(printf %04d ${n})
  446. ln -fs ${exp_name}_${ns}_restart_oce_${np}.nc restart_oce_${np}.nc
  447. ln -fs ${exp_name}_${ns}_restart_ice_${np}.nc restart_ice_${np}.nc
  448. has_config pisces && \
  449. ln -fs ${exp_name}_${ns}_restart_trc_${np}.nc restart_trc_${np}.nc
  450. done
  451. # Make sure there are no global restart files
  452. # If links are found, they will be removed. We are cautious and do
  453. # _not_ remove real files! However, if real global restart files are
  454. # present, NEMO/LIM will stop because time stamps will not match.
  455. [ -h restart_oce.nc ] && rm restart_oce.nc
  456. [ -h restart_ice.nc ] && rm restart_ice.nc
  457. [ -h restart_trc.nc ] && rm restart_trc.nc
  458. fi
  459. # -------------------------------------------------------------------------
  460. # *** Start the run
  461. # -------------------------------------------------------------------------
  462. # Link NEMO forcing files
  463. if ! [[ "${nem_forcing_set}" == "CoreII" ]] && \
  464. ! [[ "${nem_forcing_set}" == "DFS5.2" ]] && \
  465. ! [[ "${nem_forcing_set}" == "eraint" ]] && \
  466. ! [[ "${nem_forcing_set}" == "CoreII_interannual" ]]&& \
  467. ! [[ "${nem_forcing_set}" == "era5" ]] && \
  468. ! [[ "${nem_forcing_set}" == "ERA5_HRES" ]] && \
  469. ! [[ "${nem_forcing_set}" == "ERA5_ENDA" ]] && \
  470. ! [[ "${nem_forcing_set}" == "JRA55_1.4" ]]
  471. then
  472. echo "${nem_forcing_set}" not supported;
  473. exit 1
  474. fi
  475. case "${nem_forcing_set}" in
  476. CoreII)
  477. for variable in u_10 v_10 t_10 q_10 ncar_precip ncar_rad ; do
  478. [ -f "${ini_data_dir}/nemo/forcing/CoreII/${variable}.15JUNE2009_fill.nc" ] && ln -sf "${ini_data_dir}/nemo/forcing/CoreII/${variable}.15JUNE2009_fill.nc"
  479. done
  480. # Weight files for forcing
  481. ln -fs ${ini_data_dir}/nemo/forcing/CoreII/weights_coreII_2_orca${nem_res_hor}_bilinear.nc
  482. ln -fs ${ini_data_dir}/nemo/forcing/CoreII/weights_coreII_2_orca${nem_res_hor}_bicubic.nc
  483. ;;
  484. * )
  485. for forcing_file in ${ini_data_dir}/nemo/forcing/${nem_forcing_set}/* ; do
  486. [ -f ${forcing_file} ] && ln -fs ${forcing_file} ./$(basename ${forcing_file})
  487. done
  488. #Weight files for forcing
  489. ln -sf ${ini_data_dir}/nemo/forcing/weights/* .
  490. ;;
  491. esac
  492. # Use the launch function from the platform configuration file
  493. t1=$(date +%s)
  494. launch \
  495. ${xio_numproc} ${xio_exe_file} -- \
  496. ${nem_numproc} ${nem_exe_file}
  497. t2=$(date +%s)
  498. tr=$(date -d "0 -$t1 sec + $t2 sec" +%T)
  499. # -------------------------------------------------------------------------
  500. # *** Check for signs of success
  501. # Note the tests provide no guarantee that things went fine! They are
  502. # just based on the IFS and NEMO log files. More tests (e.g. checking
  503. # restart files) could be implemented.
  504. # -------------------------------------------------------------------------
  505. # Check for NEMO success
  506. if [ -f ocean.output ]
  507. then
  508. if [ "$(sed -n '/New day/h; ${g;s:.*\([0-9/]\{10\}\).*:\1:;p;}' ocean.output)" == "$(date -u -d "$(absolute_date_noleap "${leg_end_date} - 1 day")" +%Y/%m/%d)" ]
  509. then
  510. info "Leg successfully completed according to NEMO log file 'ocean.output'."
  511. else
  512. error "Leg not completed according to NEMO log file 'ocean.output'."
  513. fi
  514. else
  515. error "NEMO log file 'ocean.output' not found after run."
  516. fi
  517. # -------------------------------------------------------------------------
  518. # *** Post-process initial conditions saved during the run if requested
  519. # -------------------------------------------------------------------------
  520. ${do_save_ic} && save_ic_postproc
  521. # -------------------------------------------------------------------------
  522. # *** Move NEMO output files to archive directory
  523. # -------------------------------------------------------------------------
  524. outdir="output/nemo/$(printf %03d $((leg_number)))"
  525. mkdir -p ${outdir}
  526. for v in grid_U grid_V grid_W grid_T icemod SBC scalar SBC_scalar diad_T ptrc_T bioscalar \
  527. grid_T_2D grid_U_2D grid_V_2D grid_W_2D grid_T_3D grid_U_3D grid_V_3D grid_W_3D \
  528. grid_T_SFC grid_1point grid_T_3D_ncatice vert_sum \
  529. grid_ptr_W_3basin_3D grid_ptr_T_3basin_2D grid_ptr_T_2D \
  530. zoom_700_sum zoom_300_sum zoom_2000_sum
  531. do
  532. for f in ${exp_name}_*_????????_????????_*${v}.nc
  533. do
  534. test -f $f && mv $f $outdir/
  535. done
  536. done
  537. # -------------------------------------------------------------------------
  538. # *** Move NEMO restart files to archive directory
  539. # -------------------------------------------------------------------------
  540. if $leg_is_restart
  541. then
  542. outdir="restart/nemo/$(printf %03d $((leg_number)))"
  543. mkdir -p ${outdir}
  544. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  545. for f in oce ice trc
  546. do
  547. test -f ${exp_name}_${ns}_restart_${f}_0000.nc && \
  548. mv ${exp_name}_${ns}_restart_${f}_????.nc ${outdir}
  549. done
  550. if ! $(has_config pisces:offline)
  551. then
  552. cp EMPave_old.dat ${outdir}/EMPave_old.dat
  553. fi
  554. fi
  555. if ! $(has_config pisces:offline)
  556. then
  557. cp EMPave.dat EMPave_old.dat
  558. fi
  559. # -------------------------------------------------------------------------
  560. # *** Move log files to archive directory
  561. # -------------------------------------------------------------------------
  562. outdir="log/$(printf %03d $((leg_number)))"
  563. mkdir -p ${outdir}
  564. for f in \
  565. ocean.output time.step solver.stat
  566. do
  567. test -f ${f} && mv ${f} ${outdir}
  568. done
  569. # -------------------------------------------------------------------------
  570. # *** Write the restart control file
  571. # -------------------------------------------------------------------------
  572. # Compute CPMIP performance
  573. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  574. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1)) $(($nem_numproc + $xio_numproc)))"
  575. echo "#" | tee -a ${ece_info_file}
  576. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  577. | tee -a ${ece_info_file}
  578. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  579. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  580. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  581. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  582. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  583. force_run_from_scratch=false
  584. done # loop over legs
  585. # -----------------------------------------------------------------------------
  586. # *** Platform dependent finalising of the run
  587. # -----------------------------------------------------------------------------
  588. finalise