EC00.sh 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  1. #!/bin/bash
  2. #
  3. # Job options
  4. #
  5. #SBATCH --job-name=EC00
  6. #SBATCH --time=01:59:00
  7. #SBATCH --account=ecearth
  8. #
  9. #SBATCH --nodes=4
  10. #SBATCH --exclusive
  11. #SBATCH --ntasks-per-node=123
  12. #SBATCH --partition=debug
  13. #
  14. set -ueo pipefail
  15. #
  16. LOCAL_NODES=4
  17. LOCAL_TASKS=492
  18. #
  19. stdout_file=${SLURM_SUBMIT_DIR-$PWD}/${SLURM_JOB_NAME-"local"}_${SLURM_JOB_ID-"id"}.log
  20. exec > ${stdout_file}
  21. echo "------------------ Job Info --------------------"
  22. echo "jobid : ${SLURM_JOB_ID-"id"}"
  23. echo "jobname : ${SLURM_JOB_NAME-"local"}"
  24. echo "nodename : ${SLURMD_NODENAME-"local"}"
  25. echo "# nodes : ${SLURM_JOB_NUM_NODES-$LOCAL_NODES}"
  26. echo "# tasks : ${SLURM_NTASKS-$LOCAL_TASKS}"
  27. echo "submit dir : ${SLURM_SUBMIT_DIR-$PWD}"
  28. set -ue
  29. #
  30. # Cluster variables
  31. #
  32. NB_CORES_PER_NODES=128
  33. MAX_CORES_PER_NODES=123
  34. LIST_CORES_SOCKET=`seq -s',' 0 $((NB_CORES_PER_NODES-1))`
  35. #
  36. # Directories
  37. start_dir=${SLURM_SUBMIT_DIR-$PWD}
  38. # librunscript defines some helper functions
  39. . ${start_dir}/librunscript.sh
  40. # =============================================================================
  41. # *** BEGIN User configuration
  42. # =============================================================================
  43. # -----------------------------------------------------------------------------
  44. # *** General configuration
  45. # -----------------------------------------------------------------------------
  46. # Component configuration (for syntax of the $config variable, see librunscript.sh)
  47. #
  48. # Currently maintained:
  49. # config="ifs amip oasis" # "GCM forced-SST" : IFS + AMIP
  50. # config="ifs amip oasis lpjg:fdbck" # "Veg" : forced-GCM + LPJ-Guess
  51. # config="ifs amip oasis tm5:chem,o3fb,ch4fb,aerfb" # "AerChem" : forced-GCM + TM5
  52. #
  53. # config="ifs nemo lim3 rnfmapper xios:detached oasis" # "GCM" : IFS+NEMO
  54. # config="ifs nemo lim3 rnfmapper xios:detached oasis lpjg:fdbck" # "Veg" : GCM+LPJ-Guess
  55. # config="ifs nemo lim3 rnfmapper xios:detached oasis pisces lpjg:fdbck tm5:co2,co2fb" # "C-cycle" : GCM+LPJG+TM5
  56. # config="ifs nemo lim3 rnfmapper xios:detached oasis tm5:chem,o3fb,ch4fb,aerfb" # "AerChem" : GCM+TM5
  57. #
  58. # config="ifs nemo pisces lim3 rnfmapper xios:detached oasis" # "GCM" : IFS+NEMO+PISCES
  59. #
  60. config="ifs nemo lim3 rnfmapper xios:detached oasis"
  61. # minimum sanity
  62. has_config amip nemo && error "Cannot have both nemo and amip in config!!"
  63. ! has_config ifs && error "The ESM script requires ifs in config"
  64. # Experiment name (exactly 4 letters!)
  65. export exp_name=EC00
  66. # Simulation start and end date. Use any (reasonable) syntax you want.
  67. run_start_date="1850-01-01"
  68. run_end_date="${run_start_date} + 10 years"
  69. # Set $force_run_from_scratch to 'true' if you want to force this run to start
  70. # from scratch, possibly ignoring any restart files present in the run
  71. # directory. Leave set to 'false' otherwise.
  72. # NOTE: If set to 'true' the run directory $run_dir is cleaned!
  73. force_run_from_scratch=true
  74. special_restart=false
  75. special_restart_from=ECE3
  76. special_restart_date="1995-01-01"
  77. # Resolution (TM5 resolution is set at compilation)
  78. ifs_grid=T255L91
  79. nem_grid=ORCA1L75
  80. # Restart frequency. Use any (reasonable) number and time unit you want.
  81. # For runs without restart, leave this variable empty
  82. rst_freq="6 months"
  83. # Number of restart legs to be run in one go
  84. run_num_legs=1
  85. # Coupling frequencies
  86. has_config ifs tm5 && cpl_freq_atm_ctm_hrs=6
  87. has_config ifs lpjg && cpl_freq_atm_lpjg_hrs=24
  88. # Don't change the coupling frequency because UPDCLIE (where SST and SIC
  89. # are updated) is called every 24 hours (hardcoded in ifs-36r4/src/ifs/utility/updtim.F90)
  90. has_config amip && cpl_freq_amip_sec=86400
  91. # Directories
  92. #start_dir=${PWD}
  93. ctrl_file_dir=${start_dir}/ctrl
  94. output_control_files_dir=${start_dir}/ctrl
  95. # Architecture
  96. build_arch=ecconf
  97. use_machinefile=%USE_MACHINEFILE%
  98. # This file is used to store information about restarts
  99. ece_info_file="ece.info"
  100. # -----------------------------------------------------------------------------
  101. # *** Read platform dependent configuration
  102. # -----------------------------------------------------------------------------
  103. . ${start_dir}/ecconf.cfg
  104. # This function should configure all settings/modules needed to
  105. # later prepare the EC-Earth run directory and set variables used
  106. # in the run script
  107. # SCRATCH is not defined in MN3, define it here
  108. # and also make sure it is defined when compiling
  109. export SCRATCH=/gpfs/scratch/acad/ecearth/${USER}
  110. # Configure paths for building/running EC-Earth
  111. ecearth_src_dir=${HOME}/models/ecearth_3.3.3.2/sources
  112. run_dir=/gpfs/scratch/acad/ecearth/${USER}/ecearth/run/${exp_name}
  113. ini_data_dir=/gpfs/scratch/acad/ecearth/data/bsc32/v3.3.3.2/inidata
  114. archive_dir=/gpfs/scratch/acad/ecearth/${USER}/ecearth/archive/${exp_name}
  115. # File for standard output.
  116. # NOTE: This will be modified for restart jobs!
  117. stdout_file=${SLURM_SUBMIT_DIR-$PWD}/${SLURM_JOB_NAME-"local"}_${SLURM_JOB_ID-"id"}.log
  118. # Resubmit this job for automatic restarts? [true/false]
  119. # Also, add options for the resubmit command here.
  120. resubmit_job=true
  121. resubmit_opt=""
  122. module purge
  123. module load EasyBuild/2023a
  124. MODULEPATH=$MODULEPATH:/gpfs/projects/acad/ecearth/softs/easybuild/modules/all
  125. module load netCDF-Fortran/4.6.1-iompi-2023a
  126. module load imkl/2023.1.0
  127. module load grib_api/1.24.0-iompi-2023a
  128. module load CDO/1.9.10-iompi-2023a
  129. # Configure grib api paths
  130. export GRIB_DEFINITION_PATH=${HOME}/models/ecearth_3.3.3.2/sources/util/grib_table_126:${EBROOTGRIB_API}/share/grib_api/definitions
  131. export GRIB_SAMPLES_PATH=${EBROOTGRIB_API}/share/grib_api/ifs_samples/grib1
  132. export GRIB_BIN_PATH=${EBROOTGRIB_API}/bin
  133. # Configure number of processors per node
  134. proc_per_node=128
  135. # Use machinefiles or not
  136. [[ `echo "$use_machinefile" | tr '[:upper:]' '[:lower:]'` == true ]] && use_machinefile=true || use_machinefile=false
  137. ulimit -s unlimited
  138. # -----------------------------------------------------------------------------
  139. # *** Time step settings
  140. # -----------------------------------------------------------------------------
  141. if has_config ifs
  142. then
  143. case "${ifs_grid}" in
  144. T159L*) ifs_time_step_sec=3600 ;;
  145. T255L*) ifs_time_step_sec=2700 ;;
  146. T511L*) ifs_time_step_sec=900 ;;
  147. *) error "Can't set time steps for unknown horizontal grid: ${ifs_grid}"
  148. ;;
  149. esac
  150. fi
  151. if has_config nemo
  152. then
  153. case "${nem_grid}" in
  154. ORCA1L*) nem_time_step_sec=2700; lim_time_step_sec=2700 ;;
  155. ORCA025L*) nem_time_step_sec=900 ; lim_time_step_sec=900 ;;
  156. *) error "Can't set time steps for unknown horizontal grid: ${nem_grid}"
  157. ;;
  158. esac
  159. fi
  160. if has_config ifs nemo
  161. then
  162. case "${ifs_grid}--${nem_grid}" in
  163. T159L*--ORCA1L*)
  164. ifs_time_step_sec=3600; nem_time_step_sec=2700; lim_time_step_sec=2700; cpl_freq_atm_oce_sec=10800
  165. ;;
  166. T255L*--ORCA1L*)
  167. ifs_time_step_sec=2700; nem_time_step_sec=2700; lim_time_step_sec=2700; cpl_freq_atm_oce_sec=2700
  168. ;;
  169. T511L*--ORCA025L*)
  170. ifs_time_step_sec=900 ; nem_time_step_sec=900 ; lim_time_step_sec=900 ; cpl_freq_atm_oce_sec=2700
  171. ;;
  172. *) error "Can't set time steps for unknown combination of horizontal grids: ${ifs_grid}-${nem_grid}"
  173. ;;
  174. esac
  175. fi
  176. # -----------------------------------------------------------------------------
  177. # *** IFS configuration
  178. # -----------------------------------------------------------------------------
  179. ifs_version=36r4
  180. ifs_di_freq=$(( 24 * 3600 / ifs_time_step_sec ))
  181. ifs_ddh_freq=$(( 120 * 3600 / ifs_time_step_sec ))
  182. export ifs_res_hor=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\1:')
  183. ifs_res_ver=$(echo ${ifs_grid} | sed 's:T\([0-9]\+\)L\([0-9]\+\):\2:')
  184. ifs_numproc=392
  185. ifs_exe_file=${ecearth_src_dir}/ifs-${ifs_version}/bin/ifsmaster-${build_arch}
  186. ifs_lastout=false
  187. # USE FORCING FROM CMIP5 (SOLAR, GHG, AEROSOL, O3)
  188. ifs_cmip5=TRUE
  189. # SWITCH FOR RCP AND HISTORICAL RUNS FOR CMIP5 (0=HISTO 1=RCP 3-PD, 2=RCP 4.5, 3=RCP 6.0, 4=RCP 8.5)
  190. ifs_cmip5_rcp=0
  191. # 1PCTCO2 and A4XCO2 should operate together with ifs_cmip_fixyear years, ie., the baseline GHGs level will use that for year ifs_cmip_fixyear
  192. export ifs_cmip_fixyear=1850
  193. export ifs_cmip_fixyear_ch4=1850
  194. # Repeat trap from ifs/suecrad.F90 for early catch
  195. if ! has_config tm5:ch4fb && (( $ifs_cmip_fixyear != $ifs_cmip_fixyear_ch4 ))
  196. then
  197. error 'CH4 in IFS is not provided by TM5, NCMIPFIXYR_CH4 should be set equal to NCMIPFIXYR'
  198. fi
  199. # USE FORCING FROM CMIP6 (HAS PRIORITY OVER LCMIP5)
  200. ifs_cmip6=TRUE
  201. # MAC-SP anthropogenic simple plume model (parameterization of anthropogenic aerosol optical properties)
  202. ifs_mac2sp=TRUE
  203. # Use CMIP6 prescribed preindustrial aerosol
  204. ifs_cmip6piaer=TRUE
  205. # !! scenario 'historical' max 2014
  206. # 1850 (o3_pi)
  207. # 1850 --> 2014 (o3_histo)
  208. # !! other scenarios (> 2014), default: SSP3-7.0
  209. # SSP1-1.9, SSP1-2.6, SSP1-2.6-Ext, SSP2-4.5, SSP3-7.0, SSP3-LowNTCF, SSP4-3.4, SSP5-3.4-OS, SSP4-6.0, SSP5-3.4-OS-Ext, SSP5-8.5, SSP5-8.5-Ext
  210. ifs_cmip6_scenario=historical
  211. # Enable optional COVID-19 scenarios, will enforce ifs_cmip6_scenario=SSP2-4.5
  212. ifs_covid19=FALSE
  213. # Choose one scenario : Base TwoYearBlip ModerateGreen StrongGreen FossilFuel
  214. ifs_covid19scen=Base
  215. # Basic sanity checks
  216. if [ ${ifs_covid19} == TRUE ] ; then
  217. [ ${ifs_cmip6_scenario} != SSP2-4.5 ] && echo "*WARNING* with ifs_covid19=TRUE IFS uses ifs_cmip6_scenario=SSP2-4.5 not ${ifs_cmip6_scenario}"
  218. has_config any lpjg pisces tm5 && error "ifs_covid19=TRUE is not supported with LPJ-GUESS, PISCES nor TM5"
  219. fi
  220. # Read CMIP6 stratospheric aerosol data file, vertically integrated version
  221. lcmip6_strataer_simp=FALSE
  222. lcmip6_strataer_full=TRUE
  223. lcmip6_strataer_bckgd=FALSE
  224. # for an abrupt increase of CO2 to 4x the starting year (ifs_cmip_fixyear)
  225. export ifs_A4xCO2=FALSE
  226. # for an 1% per year increase of CO2 until reaching 4x the starting year (ifs_cmip_fixyear)
  227. export ifs_1PCTCO2=FALSE
  228. export bgc_1PCTCO2=FALSE
  229. # Time-varying orbital forcing (Qiong Zhang, SU-2013-09)
  230. # https://dev.ec-earth.org/projects/ecearth3/wiki/Orbital_forcing_in_EC-Earth_3
  231. #
  232. # ifs_orb_switch=false, no orbital calculations applied
  233. # ifs_orb_switch=true, use orbital calculations according to ifs_orb_mode
  234. # ifs_orb_mode="fixed_year", or "variable_year", or "fixed_parameters"
  235. # fixed_year: calculate the orbital parameters at ifs_orb_iyear, e.g.,1850
  236. # variable_year: calculate orbital parameters annually start from ifs_orb_iyear
  237. # fixed_parameters: prescribe orbital parameters for given year
  238. case "${ifs_grid}" in
  239. T159*) ifs_orb_switch=true ;;
  240. *) ifs_orb_switch=false ;;
  241. esac
  242. ifs_orb_mode="variable_year"
  243. ifs_orb_iyear=$(date -u -d "${run_start_date}" +%Y)
  244. # Relaxation of soil moisture (Wilhelm May, LU; October 2017)
  245. #
  246. # LRXSM: Parameter indicating the levels to be nudged
  247. #
  248. # LRXSM = 0: no nudging
  249. # LRXSM = 12: 4xdaily data and 3 levels (excluding level 1)
  250. # LRXSM = 13: 4xdaily data and 4 levels
  251. #
  252. # LRXSMTx: time scale of the relaxation for level X (in hours)
  253. #
  254. # LRXSMTx = 0: actual values relpaced by external ones
  255. # LRXSMTx = 24: 1 day
  256. # LRXSMTx = 120: 5 days
  257. #
  258. # LRXSMS: indicates when the relaxation is done
  259. #
  260. # LRXSMS = 0: before the time step
  261. # LRXSMS = 1: after the time step
  262. #
  263. has_config soilnudg && ifs_lrxsm=13 || ifs_lrxsm=0
  264. ifs_lrxsmt1=96
  265. ifs_lrxsmt2=72
  266. ifs_lrxsmt3=48
  267. ifs_lrxsmt4=24
  268. ifs_lrxsms=1
  269. # IFS tuning parameters
  270. variant=
  271. has_config tm5:chem && variant=-AerChem
  272. ifs_tuning_parameter_file=${ctrl_file_dir}/ifs-tuning-parameters-${ifs_grid}${variant}.sh
  273. if [ -f ${ifs_tuning_parameter_file} ]
  274. then
  275. source ${ifs_tuning_parameter_file}
  276. else
  277. error "Sorry, ${ifs_tuning_parameter_file} not found, exiting."
  278. fi
  279. # Select source of vegetation data:
  280. # ifs climatology from IFS
  281. # era20c vegetation from an off-line LPJ-Guess run forced with ERA20C
  282. # (currently available only for T255 and T159)
  283. # cmip6 vegetation from an EC-Earth3-Veg (interactive LPJ-Guess) run
  284. # (currently available only for T255)
  285. # custom_exp vegetation from any EC-Earth3-Veg run exp
  286. # (must contain same variables as era20c & cmip6 and located in icmcl_exp folder)
  287. # none don't create an ICMCL file with vegetation data (this is set
  288. # automatically if LPJG is used with feedback)
  289. #
  290. ifs_veg_source="cmip6"
  291. has_config lpjg:fdbck && ifs_veg_source="none"
  292. case ${ifs_veg_source} in
  293. "ifs" )
  294. # Use Lambert-Beer to compute effective vegetation cover
  295. n_compute_eff_veg_fraction=2
  296. ;;
  297. "era20c" )
  298. # LPJG vegetation is provided as effective cover
  299. # Don't use Lambert-Beer
  300. n_compute_eff_veg_fraction=0
  301. case "${ifs_grid}" in
  302. T159L*) veg_version=v29 ;;
  303. T255L*) veg_version=v16 ;;
  304. *) error "Vegetation from off-line LPJ-Guess not available for ${ifs_grid}" ;;
  305. esac
  306. ;;
  307. "cmip6" )
  308. # LPJG vegetation is provided as effective cover
  309. # Don't use Lambert-Beer
  310. n_compute_eff_veg_fraction=0
  311. case "${ifs_grid}" in
  312. T255L*) veg_version=v32 ;;
  313. *) error "Vegetation from CMIP6 EC-Earth3-Veg not available for ${ifs_grid}" ;;
  314. esac
  315. ;;
  316. "custom_"* )
  317. # LPJG vegetation is provided as effective cover
  318. # Don't use Lambert-Beer
  319. n_compute_eff_veg_fraction=0
  320. veg_version=${ifs_veg_source:7}
  321. if [ ! -d ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version} ]
  322. then
  323. error "requested IFS_VEG_SOURCE = ${ifs_veg_source} but not found in ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version}"
  324. fi
  325. ;;
  326. "none" )
  327. # LPJG with feedback
  328. n_compute_eff_veg_fraction=0
  329. ! has_config lpjg:fdbck && error "IFS requires an offline source of vegetation"
  330. ;;
  331. * )
  332. error "Vegetation from ${ifs_veg_source} not implemented"
  333. ;;
  334. esac
  335. # use DMI land ice physics and varying snow albedo
  336. case "${ifs_grid}" in
  337. T159*) ifs_landice=true ;;
  338. *) ifs_landice=false ;;
  339. esac
  340. # -----------------------------------------------------------------------------
  341. # *** NEMO/LIM configuration
  342. # -----------------------------------------------------------------------------
  343. # This is only needed if the experiment is started from an existing set of NEMO
  344. # restart files
  345. nem_restart_file_path=${start_dir}/nemo-rst
  346. nem_restart_offset=0
  347. nem_res_hor=$(echo ${nem_grid} | sed 's:ORCA\([0-9]\+\)L[0-9]\+:\1:')
  348. nem_config=${nem_grid}
  349. has_config lim3 && nem_config=${nem_config}_LIM3
  350. if has_config pisces tm5:co2
  351. then
  352. nem_config=${nem_config}_CarbonCycle
  353. elif has_config pisces
  354. then
  355. nem_config=${nem_config}_PISCES
  356. fi
  357. # TODO - nemo standalone configs are not accounted for in this script, but this would set the required nem_config
  358. ! has_config ifs && nem_config=${nem_config}_standalone
  359. nem_exe_file=${ecearth_src_dir}/nemo-3.6/CONFIG/${nem_config}/BLD/bin/nemo.exe
  360. nem_numproc=98
  361. # Thermal conductivity of snow, see comment in ctrl/namelist.lim3.ref.sh
  362. case "${ifs_grid}" in
  363. T159L* ) nem_rn_cdsn=0.25 ;;
  364. * ) nem_rn_cdsn=0.27 ;;
  365. esac
  366. # -----------------------------------------------------------------------------
  367. # *** Runoff mapper configuration
  368. # -----------------------------------------------------------------------------
  369. rnf_exe_file=${ecearth_src_dir}/runoff-mapper/bin/runoff-mapper.exe
  370. rnf_numproc=1
  371. # -----------------------------------------------------------------------------
  372. # *** LPJ-GUESS configuration
  373. # -----------------------------------------------------------------------------
  374. lpjg_time_step_sec=86400
  375. lpjg_numproc=32
  376. has_config lpjg && lpjg_on=1
  377. has_config lpjg:fdbck && lpjg_fdbck=1
  378. has_config tm5:co2 && lpjg_fdbck_tm5=1 || lpjg_fdbck_tm5=0
  379. export lpjg_fixNdepafter=-1
  380. export lpjg_fixLUafter=-1
  381. info '!!!! CMIP FIX YEAR SETTINGS:'
  382. info "ifs_cmip_fixyear: $ifs_cmip_fixyear"
  383. info "lpjg_fixNDepAfter: $lpjg_fixNdepafter"
  384. info "lpjg_fixLUAfter: $lpjg_fixLUafter"
  385. info '!!!!'
  386. lpjg_res=T${ifs_res_hor}
  387. lpjg_exe_file=${ecearth_src_dir}/lpjg/build/guess_${lpjg_res}
  388. # -----------------------------------------------------------------------------
  389. # *** AMIP-reader configuration
  390. # -----------------------------------------------------------------------------
  391. amip_exe_file=${ecearth_src_dir}/amip-forcing/bin/amip-forcing.exe
  392. amip_numproc=1
  393. # -----------------------------------------------------------------------------
  394. # *** TM5 configuration
  395. # -----------------------------------------------------------------------------
  396. if $(has_config tm5)
  397. then
  398. # With TM5, NPRTRV is set to 1 in the namelist. To avoid some out-of-bound
  399. # arrays in IFS, we must limit the number of cores for IFS
  400. if (( ifs_numproc > (ifs_res_hor+1) ))
  401. then
  402. error "too much cores requested for IFS, max is $((ifs_res_hor+1))"
  403. fi
  404. # TM5 settings
  405. has_config tm5:co2 && tmversion="co2" || tmversion="cb05"
  406. has_config tm5:co2 && export tm5_co2=1 || export tm5_co2=0
  407. export tm5_exch_nlevs=10
  408. tm5_time_step_sec=3600
  409. export tm5_numproc_x=2
  410. export tm5_numproc_y=45
  411. tm5_numproc=$(( tm5_numproc_x * tm5_numproc_y ))
  412. export tm5_emiss_fixyear=0
  413. # limited number of levels for feedback (aerosols, currently set to lmax_conv in TM5)
  414. case ${tm5_exch_nlevs} in
  415. 34) export tm5_exch_nlevs_cutoff=23 ;;
  416. 10) export tm5_exch_nlevs_cutoff=10 ;;
  417. 4) export tm5_exch_nlevs_cutoff=4 ;;
  418. *) error "not supported number of levels for TM5"
  419. esac
  420. # executable
  421. tm5_exe_file=${ecearth_src_dir}/tm5mp/build-${tmversion}-ml${tm5_exch_nlevs}/appl-tm5-${tmversion}.x
  422. # path to initial conditions, modify as needed
  423. tm5_restart_file_path=${ini_data_dir}/tm5/restart/${tmversion}-ml${tm5_exch_nlevs}
  424. # fields sent back to IFS
  425. has_config tm5:o3fb && tm5_to_ifs=O3 || tm5_to_ifs=
  426. has_config tm5:ch4fb && tm5_to_ifs=${tm5_to_ifs},CH4
  427. has_config tm5:aerfb && tm5_to_ifs=${tm5_to_ifs},"\
  428. N2,SU2,BC2,OC2,N3,SU3,BC3,OC3,SS3,DU3,\
  429. N4,SU4,BC4,OC4,SS4,DU4,N5,BC5,OC5,N6,DU6,N7,DU7,\
  430. NO3,MSA,\
  431. AOD_01,AOD_02,AOD_03,AOD_04,AOD_05,AOD_06,AOD_07,AOD_08,AOD_09,AOD_10,AOD_11,AOD_12,AOD_13,AOD_14,\
  432. SSA_01,SSA_02,SSA_03,SSA_04,SSA_05,SSA_06,SSA_07,SSA_08,SSA_09,SSA_10,SSA_11,SSA_12,SSA_13,SSA_14,\
  433. ASF_01,ASF_02,ASF_03,ASF_04,ASF_05,ASF_06,ASF_07,ASF_08,ASF_09,ASF_10,ASF_11,ASF_12,ASF_13,ASF_14"
  434. has_config tm5:co2fb && tm5_to_ifs=${tm5_to_ifs},CO2
  435. export tm5_to_ifs=$(echo ${tm5_to_ifs} | sed "s/^,//")
  436. # coupled to LPJ-Guess and/or PISCES?
  437. has_config tm5:co2 lpjg && export cpl_tm_guess=T || export cpl_tm_guess=F
  438. has_config tm5:co2 pisces && export cpl_tm_pisces=T || export cpl_tm_pisces=F
  439. fi
  440. # -----------------------------------------------------------------------------
  441. # *** OASIS configuration
  442. # -----------------------------------------------------------------------------
  443. # Restart files for the coupling fields (note 8 character limit in OASIS)
  444. # rstas.nc : atmosphere single-category fields
  445. # rstam.nc : atmosphere multi-category fields
  446. # rstos.nc : ocean single-category fields
  447. # rstom.nc : ocean multi-category fields
  448. oas_rst_ifs_nemo="rstas.nc rstos.nc"
  449. oas_rst_ifs_lpjg="vegin.nc lpjgv.nc"
  450. # Met fields from IFS to TM (always required)
  451. oas_rst_ifs_tm5="r_hum.nc r_g2d.nc r_udr.nc r_div.nc r_vor.nc \
  452. r_ddr.nc r_tmp.nc r_dmf.nc r_s2d.nc r_umf.nc"
  453. has_config tm5:chem && \
  454. oas_rst_ifs_tm5=${oas_rst_ifs_tm5}' r_cc_.nc r_clw.nc r_cco.nc r_ciw.nc r_ccu.nc'
  455. has_config tm5:o3fb || has_config tm5:ch4fb && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' o3ch4.nc'
  456. has_config tm5:aerfb && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' C???????'
  457. # C-cycle configuration
  458. has_config tm5:co2 lpjg && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' l_co2.nc rlpjg.nc'
  459. has_config tm5:co2 pisces && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' o_co2.nc pisce.nc'
  460. has_config tm5:co2fb && oas_rst_ifs_tm5=$oas_rst_ifs_tm5' co2mx.nc'
  461. # final list of files depends on the activated components - this is used in save_ic as well
  462. #oas_rst_files="${oas_rst_ifs_nemo} ${oas_rst_ifs_tm5} vegin.nc lpjgv.nc"
  463. oas_rst_files=""
  464. has_config ifs nemo && oas_rst_files+=" ${oas_rst_ifs_nemo}"
  465. has_config ifs lpjg && oas_rst_files+=" ${oas_rst_ifs_lpjg}"
  466. has_config ifs tm5 && oas_rst_files+=" ${oas_rst_ifs_tm5}"
  467. # Decide whether the OASIS weight files for interpolation should be linked from
  468. # the setup directory (true) or not (false). In the latter case, the weights
  469. # are re-computed at the start of the run.
  470. oas_link_weights=true
  471. # Flux correction for runoff (not calving) sent from Oasis to ocean.
  472. # 1.07945 is computed to compensate for a P-E=-0.016 mm/day (valid for std res)
  473. case "${ifs_grid}" in
  474. T159L* ) has_config nemo && oas_mb_fluxcorr=1.08652 ;;
  475. * ) has_config nemo && oas_mb_fluxcorr=1.07945 ;;
  476. esac
  477. # -----------------------------------------------------------------------------
  478. # *** XIOS configuration
  479. # -----------------------------------------------------------------------------
  480. xio_exe_file=${ecearth_src_dir}/xios-2.5/bin/xios_server.exe
  481. xio_numproc=1
  482. # -----------------------------------------------------------------------------
  483. # *** Extra initial conditions saved during the run
  484. # -----------------------------------------------------------------------------
  485. if has_config save_ic
  486. then
  487. source ./libsave_ic.sh
  488. declare -a save_ic_date save_ic_date1 save_ic_sec save_ic_day save_ic_ppt_file save_ic_nemo_ts
  489. oas_rst_files="${oas_rst_ifs_nemo} ${oas_rst_ifs_tm5} vegin.nc lpjgv.nc"
  490. fi
  491. # -----------------------------------------------------------------------------
  492. # *** Carbon cycle configuration
  493. # -----------------------------------------------------------------------------
  494. # set to true to write co2 fluxes sent to TM5
  495. ccycle_debug_fluxes=true
  496. # =============================================================================
  497. # *** END of User configuration
  498. # =============================================================================
  499. # =============================================================================
  500. # *** This is where the code begins ...
  501. # =============================================================================
  502. # -----------------------------------------------------------------------------
  503. # *** Create the run dir if necessary and go there
  504. # Everything is done from here.
  505. # -----------------------------------------------------------------------------
  506. if [ ! -d ${run_dir} ]
  507. then
  508. mkdir -p ${run_dir}
  509. if $special_restart
  510. then
  511. force_run_from_scratch=false
  512. echo 'rsync -av --delete ${run_dir}/../${special_restart_from}/ --exclude log --exclude output --exclude restart --exclude="${special_restart_from}_*" --exclude="srf*" --exclude="restart_*" --exclude="debug.*" --ex clude="output.*" ${run_dir}'
  513. 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}
  514. cp -f ${nem_exe_file} ${run_dir}
  515. cp -f ${ifs_exe_file} ${run_dir}
  516. cp -f ${rnf_exe_file} ${run_dir}
  517. cp -f ${xio_exe_file} ${run_dir}
  518. special_year=${special_restart_date:0:4}
  519. sed -i "/$special_year/q" ${run_dir}/ece.info
  520. . ${run_dir}/ece.info
  521. special_restart_leg=$(printf %03d $((leg_number+1)))
  522. special_restart_leg_oasis=$(printf %03d $((leg_number+2)))
  523. # PUT HERE THE INSTRUCTIONS TO COPY THE restart files
  524. rsync -av ${run_dir}/../../archive/${special_restart_from}/restart/ifs/${special_restart_leg}/ ${run_dir}
  525. rsync -av ${run_dir}/../../archive/${special_restart_from}/restart/oasis/${special_restart_leg_oasis}/ ${run_dir}
  526. cd ${run_dir}/../../archive/${special_restart_from}/restart/nemo/${special_restart_leg}
  527. for f in *.nc; do
  528. nf=${exp_name}${f:4}
  529. cp $f ${run_dir}/$nf
  530. done
  531. cd -
  532. cd ${run_dir}
  533. for f in ${exp_name}_????????_restart_???_????.nc; do
  534. nf=${f:14}
  535. ln -s $f $nf
  536. done
  537. cd -
  538. rm -f ${run_dir}/ICMCL${special_restart_from}INIT
  539. mv ${run_dir}/ICMGG${special_restart_from}INIUA ${run_dir}/ICMGG${exp_name}INIUA
  540. mv ${run_dir}/ICMGG${special_restart_from}INIT ${run_dir}/ICMGG${exp_name}INIT
  541. mv ${run_dir}/ICMSH${special_restart_from}INIT ${run_dir}/ICMSH${exp_name}INIT
  542. fi
  543. else
  544. force_run_from_scratch=false
  545. special_restart=false
  546. fi
  547. cd ${run_dir}
  548. # -----------------------------------------------------------------------------
  549. # *** Determine the time span of this run and whether it's a restart leg
  550. # -----------------------------------------------------------------------------
  551. # Regularise the format of the start and end date of the simulation
  552. run_start_date=$(date -uR -d "${run_start_date}")
  553. run_end_date=$(date -uR -d "${run_end_date}")
  554. # -----------------------------------------------------------------------------
  555. # *** Set path to grib_set
  556. # -----------------------------------------------------------------------------
  557. grib_set=${GRIB_BIN_PATH}${GRIB_BIN_PATH:+/}grib_set
  558. # Loop over the number of legs
  559. for (( ; run_num_legs>0 ; run_num_legs-- ))
  560. do
  561. # Check for restart information file and set the current leg start date
  562. # Ignore restart information file if force_run_from_scratch is true
  563. if ${force_run_from_scratch} || ! [ -r ${ece_info_file} ]
  564. then
  565. leg_is_restart=false
  566. leg_start_date=${run_start_date}
  567. leg_number=1
  568. else
  569. leg_is_restart=true
  570. . ./${ece_info_file}
  571. leg_start_date=${leg_end_date}
  572. leg_number=$((leg_number+1))
  573. fi
  574. # Compute the end date of the current leg
  575. if [ -n "${rst_freq}" ]
  576. then
  577. leg_end_date=$(date -uR -d "${leg_start_date} + ${rst_freq}")
  578. else
  579. leg_end_date=${run_end_date}
  580. fi
  581. # Check if legs are integer multiples of full years if LPJG is used
  582. if has_config lpjg
  583. then
  584. if [[ $(date +%m%d%T -u -d "${leg_start_date}") != "010100:00:00" || \
  585. $(date +%m%d%T -u -d "${leg_start_date} + ${rst_freq}") != "010100:00:00" ]]
  586. then
  587. error "LPJ-GUESS runs must start on Jan 1 and end on Dec 31. Multi-year legs are allowed."
  588. fi
  589. fi
  590. if [ $(date -u -d "${leg_end_date}" +%s) -ge $(date -u -d "${run_end_date}" +%s) ]
  591. then
  592. leg_end_date=${run_end_date}
  593. ifs_lastout=true
  594. fi
  595. # Some time variables needed later
  596. leg_length_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${leg_start_date}" +%s) ))
  597. leg_start_sec=$(( $(date -u -d "${leg_start_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  598. leg_end_sec=$(( $(date -u -d "${leg_end_date}" +%s) - $(date -u -d "${run_start_date}" +%s) ))
  599. leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d)
  600. leg_start_date_yyyymm=$(date -u -d "${leg_start_date}" +%Y%m)
  601. leg_start_date_yyyy=$(date -u -d "${leg_start_date}" +%Y)
  602. leg_end_date_yyyy=$(date -u -d "${leg_end_date}" +%Y)
  603. # Check whether there's actually time left to simulate - exit otherwise
  604. if [ ${leg_length_sec} -le 0 ]
  605. then
  606. info "Leg start date equal to or after end of simulation."
  607. info "Nothing left to do. Exiting."
  608. exit 0
  609. fi
  610. # Initial conditions saved during the run
  611. do_save_ic=false
  612. has_config save_ic && save_ic_get_config
  613. # if you do not use an option with save_ic, you must define 'do_save_ic' and
  614. # 'save_ic_date_offset' here or in ../libsave_ic.sh/save_ic_get_config()
  615. ${do_save_ic} && save_ic_define_vars
  616. # -------------------------------------------------------------------------
  617. # *** Prepare the run directory for a run from scratch
  618. # -------------------------------------------------------------------------
  619. if ! $leg_is_restart
  620. then
  621. # ---------------------------------------------------------------------
  622. # *** Check if run dir is empty. If not, and if we are allowed to do so
  623. # by ${force_run_from_scratch}, remove everything
  624. # ---------------------------------------------------------------------
  625. if $(ls * >& /dev/null)
  626. then
  627. if ${force_run_from_scratch}
  628. then
  629. rm -fr ${run_dir}/*
  630. else
  631. error "Run directory ${run_dir} not empty and \$force_run_from_scratch not set."
  632. fi
  633. fi
  634. # ---------------------------------------------------------------------
  635. # *** Copy executables of model components
  636. # *** Additionally, create symlinks to the original place for reference
  637. # ---------------------------------------------------------------------
  638. cp ${ifs_exe_file} .
  639. ln -s ${ifs_exe_file} $(basename ${ifs_exe_file}).lnk
  640. if $(has_config amip)
  641. then
  642. cp ${amip_exe_file} .
  643. ln -s ${amip_exe_file} $(basename ${amip_exe_file}).lnk
  644. fi
  645. if $(has_config nemo)
  646. then
  647. cp ${nem_exe_file} .
  648. ln -s ${nem_exe_file} $(basename ${nem_exe_file}).lnk
  649. cp ${rnf_exe_file} .
  650. ln -s ${rnf_exe_file} $(basename ${rnf_exe_file}).lnk
  651. cp ${xio_exe_file} .
  652. ln -s ${xio_exe_file} $(basename ${xio_exe_file}).lnk
  653. fi
  654. if $(has_config lpjg)
  655. then
  656. cp ${lpjg_exe_file} .
  657. ln -s ${lpjg_exe_file} $(basename ${lpjg_exe_file}).lnk
  658. fi
  659. if $(has_config tm5)
  660. then
  661. cp ${tm5_exe_file} .
  662. ln -s ${tm5_exe_file} $(basename ${tm5_exe_file}).lnk
  663. fi
  664. # ---------------------------------------------------------------------
  665. # *** Files needed for IFS (linked)
  666. # ---------------------------------------------------------------------
  667. # Initial data
  668. ln -s \
  669. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIUA \
  670. ICMGG${exp_name}INIUA
  671. ln -s \
  672. ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMSHECE3INIT \
  673. ICMSH${exp_name}INIT
  674. rm -f ICMGG${exp_name}INIT
  675. cp ${ini_data_dir}/ifs/${ifs_grid}/${leg_start_date_yyyymmdd}/ICMGGECE3INIT \
  676. ICMGG${exp_name}INIT
  677. # add bare_soil_albedo to ICMGG*INIT
  678. tempfile=tmp.$$
  679. ${grib_set} -s dataDate=$(date -u -d "$run_start_date" +%Y%m%d) \
  680. ${ini_data_dir}/ifs/${ifs_grid}/climate/bare_soil_albedos.grb \
  681. ${tempfile}
  682. cat ${tempfile} >> ICMGG${exp_name}INIT
  683. rm -f ${tempfile}
  684. # add land ice mask if needed
  685. if ${ifs_landice}
  686. then
  687. tempfile=tmp.$$
  688. cdo divc,10 -setcode,82 -selcode,141 ICMGG${exp_name}INIT ${tempfile}
  689. ${grib_set} -s gridType=reduced_gg ${tempfile} ${tempfile}
  690. cat ${tempfile} >> ICMGG${exp_name}INIT
  691. rm -f ${tempfile}
  692. fi
  693. # Other stuff
  694. ln -s ${ini_data_dir}/ifs/rtables/* .
  695. # Output control (ppt files)
  696. if [ ! -f ${output_control_files_dir}/pptdddddd0600 ] && [ ! -f ${output_control_files_dir}/pptdddddd0300 ];then
  697. echo "Error from ece-esm.sh: Neither the file pptdddddd0600 or pptdddddd0300 exists in the directory:"
  698. echo " " ${output_control_files_dir}
  699. exit -1
  700. fi
  701. mkdir postins
  702. cp ${output_control_files_dir}/ppt* postins/
  703. if [ -f postins/pptdddddd0600 ];then
  704. ln -s pptdddddd0600 postins/pptdddddd0000
  705. ln -s pptdddddd0600 postins/pptdddddd1200
  706. ln -s pptdddddd0600 postins/pptdddddd1800
  707. fi
  708. if [ -f postins/pptdddddd0300 ];then
  709. ln -s pptdddddd0300 postins/pptdddddd0900
  710. ln -s pptdddddd0300 postins/pptdddddd1500
  711. ln -s pptdddddd0300 postins/pptdddddd2100
  712. if [ ! -f postins/pptdddddd0600 ];then
  713. ln -s pptdddddd0300 postins/pptdddddd0000
  714. ln -s pptdddddd0300 postins/pptdddddd0600
  715. ln -s pptdddddd0300 postins/pptdddddd1200
  716. ln -s pptdddddd0300 postins/pptdddddd1800
  717. fi
  718. fi
  719. /bin/ls -1 postins/* > dirlist
  720. # ---------------------------------------------------------------------
  721. # *** Files needed for LPJ-GUESS
  722. # ---------------------------------------------------------------------
  723. if $(has_config lpjg)
  724. then
  725. # Check for valid grid
  726. if [ $lpjg_res != "T255" -a $lpjg_res != "T159" ]
  727. then
  728. error "LPJG-gridlist doesn't exist for ifs-grid: ${ifs_grid}"
  729. fi
  730. # Initial data - saved state for LPJ-GUESS (.bin format)
  731. lpjgstartdir=$(printf "lpjg_state_%04d" $leg_start_date_yyyy)
  732. ln -sf ${ini_data_dir}/lpjg/ini_state/${lpjg_res}/${lpjgstartdir} ${run_dir}/${lpjgstartdir}
  733. # Control files (i.e. .ins, landuse, N deposition, soil type files etc.)
  734. cp -f ${ecearth_src_dir}/lpjg/data/ins/*.ins .
  735. # activate the new litterfall scheme for C4MIP - for the coupled model this is done when both pisces and lpjg are activated
  736. has_config pisces lpjg && echo -e "!override for EC-Earth-CC in runscript\nifpftlitterfall 1\ncalc_phen_after_restart 0" >> global.ins
  737. mkdir -p ${run_dir}/landuse
  738. fi
  739. # ---------------------------------------------------------------------
  740. # *** Files needed for NEMO (linked)
  741. # ---------------------------------------------------------------------
  742. if $(has_config nemo)
  743. then
  744. # Link initialisation files for matching ORCA grid
  745. for f in \
  746. bathy_meter.nc coordinates.nc \
  747. ahmcoef.nc \
  748. K1rowdrg.nc M2rowdrg.nc mask_itf.nc \
  749. decay_scale_bot.nc decay_scale_cri.nc \
  750. mixing_power_bot.nc mixing_power_cri.nc mixing_power_pyc.nc \
  751. runoff_depth.nc subbasins.nc
  752. do
  753. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && ln -s ${ini_data_dir}/nemo/initial/${nem_grid}/$f
  754. done
  755. # Copying the time independent NEMO files for the matching ORCA grid in order to facilitate cmorisation:
  756. for f in \
  757. bathy_meter.nc subbasins.nc
  758. do
  759. mkdir -p output/nemo/ofx-data
  760. [ -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f ] && cp -f ${ini_data_dir}/nemo/initial/${nem_grid}/$f output/nemo/ofx-data/
  761. done
  762. # Link geothermal heating file (independent of grid) and matching weight file
  763. ln -s ${ini_data_dir}/nemo/initial/Goutorbe_ghflux.nc
  764. ln -s ${ini_data_dir}/nemo/initial/weights_Goutorbe1_2_orca${nem_res_hor}_bilinear.nc
  765. # Link the salinity climatology file (needed for diagnostics)
  766. ln -s ${ini_data_dir}/nemo/climatology/${nem_grid}/sali_ref_clim_monthly.nc
  767. # Link either restart files or climatology files for the initial state
  768. if $(has_config nemo:start_from_restart)
  769. then
  770. # When linking restart files, we accept three options:
  771. # (1) Merged files for ocean and ice, i.e.
  772. # restart_oce.nc and restart_ice.nc
  773. # (2) One-file-per-MPI-rank, i.e.
  774. # restart_oce_????.nc and restart_ice_????.nc
  775. # No check is done whether the number of restart files agrees
  776. # with the number of MPI ranks for NEMO!
  777. # (3) One-file-per-MPI-rank with a prefix, i.e.
  778. # <exp_name>_<time_step>_restart_oce_????.nc (similar for the ice)
  779. # The prefix is ignored.
  780. # The code assumes that one of the options can be applied! If more
  781. # options are applicable, the first is chosen. If none of the
  782. # options apply, NEMO will crash with missing restart file.
  783. if ls -U ${nem_restart_file_path}/restart_[oi]ce.nc > /dev/null 2>&1
  784. then
  785. ln -s ${nem_restart_file_path}/restart_[oi]ce.nc ./
  786. elif ls -U ${nem_restart_file_path}/restart_[oi]ce_????.nc > /dev/null 2>&1
  787. then
  788. ln -s ${nem_restart_file_path}/restart_[oi]ce_????.nc ./
  789. else
  790. for f in ${nem_restart_file_path}/????_????????_restart_[oi]ce_????.nc
  791. do
  792. ln -s $f $(echo $f | sed 's/.*_\(restart_[oi]ce_....\.nc\)/\1/')
  793. done
  794. fi
  795. else
  796. # Temperature and salinity files for initialisation
  797. ln -s ${ini_data_dir}/nemo/climatology/absolute_salinity_WOA13_decav_Reg1L75_clim.nc
  798. ln -s ${ini_data_dir}/nemo/climatology/conservative_temperature_WOA13_decav_Reg1L75_clim.nc
  799. ln -s ${ini_data_dir}/nemo/climatology/weights_WOA13d1_2_orca${nem_res_hor}_bilinear.nc
  800. # Grid dependent runoff files
  801. case ${nem_grid} in
  802. ORCA1*) ln -s ${ini_data_dir}/nemo/climatology/runoff-icb_DaiTrenberth_Depoorter_ORCA1_JD.nc ;;
  803. ORCA025*) ln -s ${ini_data_dir}/nemo/climatology/ORCA_R025_runoff_v1.1.nc ;;
  804. esac
  805. fi
  806. # for ocean_nudging
  807. if $(has_config nemo:ocenudg) ; then
  808. ln -s ${ini_data_dir}/nemo/oce_nudg/resto.nc
  809. fi
  810. # XIOS files
  811. . ${ctrl_file_dir}/iodef.xml.sh > iodef.xml
  812. ln -s ${ctrl_file_dir}/context_nemo.xml
  813. ln -s ${ctrl_file_dir}/domain_def_nemo.xml
  814. ln -s ${ctrl_file_dir}/axis_def_nemo.xml
  815. ln -s ${ctrl_file_dir}/grids_def_nemo.xml
  816. ln -s ${ctrl_file_dir}/field_def_nemo-lim.xml
  817. ln -s ${ctrl_file_dir}/field_def_nemo-opa.xml
  818. ln -s ${ctrl_file_dir}/field_def_nemo-pisces.xml
  819. ln -s ${ctrl_file_dir}/field_def_nemo-inerttrc.xml
  820. ln -s ${output_control_files_dir}/file_def_nemo-lim3.xml file_def_nemo-lim.xml
  821. ln -s ${output_control_files_dir}/file_def_nemo-opa.xml
  822. ln -s ${output_control_files_dir}/file_def_nemo-pisces.xml
  823. if [ -f ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ]
  824. then
  825. cp ${ini_data_dir}/xios/ORCA${nem_res_hor}/coordinates_xios.nc ./
  826. else
  827. info "File 'coordinates_xios.nc' not found. NEMO can not be run with land domain removal!"
  828. fi
  829. # Files needed for TOP/PISCES
  830. if $(has_config pisces)
  831. then
  832. ln -fs ${ini_data_dir}/nemo/pisces/dust_INCA_ORCA_R1.nc
  833. ln -fs ${ini_data_dir}/nemo/pisces/ndeposition_Duce_ORCA_R1.nc
  834. ln -fs ${ini_data_dir}/nemo/pisces/pmarge_etopo_ORCA_R1.nc
  835. ln -fs ${ini_data_dir}/nemo/pisces/river_global_news_ORCA_R1.nc
  836. ln -fs ${ini_data_dir}/nemo/pisces/Solubility_T62_Mahowald_ORCA_R1.nc
  837. ln -fs ${ini_data_dir}/nemo/pisces/par_fraction_gewex_clim90s00s_ORCA_R1.nc
  838. ln -fs ${ini_data_dir}/nemo/pisces/DIC_GLODAP_annual_ORCA_R1.nc
  839. ln -fs ${ini_data_dir}/nemo/pisces/Alkalini_GLODAP_annual_ORCA_R1.nc
  840. ln -fs ${ini_data_dir}/nemo/pisces/O2_WOA2009_monthly_ORCA_R1.nc
  841. ln -fs ${ini_data_dir}/nemo/pisces/PO4_WOA2009_monthly_ORCA_R1.nc
  842. ln -fs ${ini_data_dir}/nemo/pisces/Si_WOA2009_monthly_ORCA_R1.nc
  843. ln -fs ${ini_data_dir}/nemo/pisces/DOC_PISCES_monthly_ORCA_R1.nc
  844. ln -fs ${ini_data_dir}/nemo/pisces/Fer_PISCES_monthly_ORCA_R1.nc
  845. ln -fs ${ini_data_dir}/nemo/pisces/NO3_WOA2009_monthly_ORCA_R1.nc
  846. # create co2 concentration file atcco2.txt if required
  847. if { [ $ifs_cmip_fixyear -gt 0 ] || [[ "${ifs_A4xCO2}" = "TRUE" ]]; } && [[ "${bgc_1PCTCO2}" = "FALSE" ]]
  848. then
  849. rm -f atcco2.txt
  850. elif [[ "${bgc_1PCTCO2}" = "TRUE" ]]
  851. then
  852. cp -f ${ini_data_dir}/nemo/pisces/mole-fraction-of-carbon-dioxide-in-air_1pctCO2_1849-2016.txt atcco2.txt
  853. else
  854. # determine scenario-name and co2-file middle-fix
  855. case $(echo ${ifs_cmip6_scenario} | tr '[:upper:]' '[:lower:]') in
  856. hist*) pis_scen="ssp585"; pis_sco2_mfix="REMIND-MAGPIE-ssp585-1-2-1";;
  857. ssp2-4.5*) pis_scen="ssp245"; pis_sco2_mfix="MESSAGE-GLOBIOM-ssp245-1-2-1";;
  858. ssp5-3.4*) pis_scen="ssp534os"; pis_sco2_mfix="REMIND-MAGPIE-ssp534-over-1-2-1";;
  859. ssp5-8.5*) pis_scen="ssp585"; pis_sco2_mfix="REMIND-MAGPIE-ssp585-1-2-1";;
  860. *) error "Scenario ${ifs_cmip6_scenario} not defined for PISCES" ;;
  861. esac
  862. # concatenate historic and scenario (2015+) co2 concentration file
  863. pis_sco2_pfix="${ini_data_dir}/nemo/pisces/mole-fraction-of-carbon-dioxide-in-air_input4MIPs_GHGConcentrations"
  864. cat ${pis_sco2_pfix}_CMIP_UoM-CMIP-1-2-0_gr1-GMNHSH_1849-2014.txt ${pis_sco2_pfix}_ScenarioMIP_UoM-${pis_sco2_mfix}_gr1-GMNHSH_2015-2500.txt > atcco2.txt
  865. fi
  866. fi
  867. #linking surface boundary conditions for CFCs (even if CFCs are not included)
  868. ln -fs ${ini_data_dir}/nemo/cfc/CFCs_CDIAC_extension_1637_2019.dat CFCs_CDIAC.dat
  869. if $(has_config pisces:start_from_restart)
  870. then
  871. # Same three options as for nemo:start_from_restart
  872. if ls -U ${nem_restart_file_path}/restart_trc.nc > /dev/null 2>&1
  873. then
  874. ln -s ${nem_restart_file_path}/restart_trc.nc ./
  875. elif ls -U ${nem_restart_file_path}/restart_trc_????.nc > /dev/null 2>&1
  876. then
  877. ln -s ${nem_restart_file_path}/restart_trc_????.nc ./
  878. else
  879. for f in ${nem_restart_file_path}/????_????????_restart_trc_????.nc
  880. do
  881. ln -s $f $(echo $f | sed 's/.*_\(restart_trc_....\.nc\)/\1/')
  882. done
  883. fi
  884. fi
  885. fi
  886. # ---------------------------------------------------------------------
  887. # *** Files needed for the Runoff mapper (linked)
  888. # ---------------------------------------------------------------------
  889. has_config rnfmapper && \
  890. ln -s ${ini_data_dir}/runoff-mapper/runoff_maps.nc
  891. # -------------------------------------------------------------------------
  892. # *** File and dir needed for TM5
  893. # -------------------------------------------------------------------------
  894. if $(has_config tm5)
  895. then
  896. tm5_istart=9
  897. case ${tm5_istart} in
  898. 33|32) ln -s \
  899. ${tm5_restart_file_path}/TM5_restart_${leg_start_date_yyyymmdd}_0000_glb300x200.nc
  900. ;;
  901. 31) ln -s ${tm5_restart_file_path}/tm5_save.hdf
  902. ;;
  903. 5) ln -s ${tm5_restart_file_path}/tm5_mmix.hdf
  904. ;;
  905. 2|9)
  906. ;;
  907. *) error "Unsupported initial fields option (TM5): ${tm5_istart}"
  908. ;;
  909. esac
  910. # spectral info
  911. ln -s ${ini_data_dir}/tm5/TM5_INPUT/T${ifs_res_hor}_info.txt
  912. # Profiling dir for TM5
  913. mkdir -p ${run_dir}/tm5_profile
  914. fi
  915. # ---------------------------------------------------------------------
  916. # *** Files needed for OASIS (linked)
  917. # ---------------------------------------------------------------------
  918. # Name table file
  919. ln -s ${ini_data_dir}/oasis/cf_name_table.txt
  920. # -- Get grid definition and weight files for IFS/NEMO or IFS/AMIP coupling
  921. has_config nemo && \
  922. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-ORCA${nem_res_hor} && \
  923. mycp='cp'
  924. has_config amip && \
  925. oas_grid_dir=${ini_data_dir}/oasis/AMIP && \
  926. mycp='cdo -f nc copy' # to enforce nc format, needed for 'cdo merge' to work (have nc4c with Primavera files)
  927. # Grid definition files
  928. if $(has_config tm5)
  929. then
  930. ${mycp} ${oas_grid_dir}/areas.nc gcm_areas.nc
  931. ${mycp} ${oas_grid_dir}/grids.nc gcm_grids.nc
  932. ${mycp} ${oas_grid_dir}/masks.nc gcm_masks.nc
  933. else
  934. ln -s ${oas_grid_dir}/areas.nc
  935. ln -s ${oas_grid_dir}/grids.nc
  936. ln -s ${oas_grid_dir}/masks.nc
  937. fi
  938. # Weight files
  939. case ${ifs_res_hor} in
  940. 159) oas_agrd=080
  941. ;;
  942. 255) oas_agrd=128
  943. ;;
  944. 511) oas_agrd=256
  945. ;;
  946. 799) oas_agrd=400
  947. ;;
  948. *) error "Unsupported horizontal resolution (IFS): ${ifs_res_hor}"
  949. ;;
  950. esac
  951. if $(has_config nemo)
  952. then
  953. case ${nem_res_hor} in
  954. 1) oas_ogrd=O1t0
  955. ;;
  956. 025) oas_ogrd=Ot25
  957. ;;
  958. *) error "Unsupported horizontal resolution (NEMO): ${nem_res_hor}"
  959. ;;
  960. esac
  961. fi
  962. if ${oas_link_weights}
  963. then
  964. for f in ${oas_grid_dir}/rmp_????_to_????_GAUSWGT.nc
  965. do
  966. ln -s $f
  967. done
  968. fi
  969. if $(has_config ifs nemo)
  970. then
  971. for f in ${oas_rst_ifs_nemo}
  972. do
  973. cp ${oas_grid_dir}/rst/$f .
  974. done
  975. fi
  976. # -- Get grid definition, weight and restart files for TM5 coupling
  977. if $(has_config tm5)
  978. then
  979. oas_grid_dir=${ini_data_dir}/oasis/T${ifs_res_hor}-TM5-LPJG
  980. cp ${oas_grid_dir}/tm5_areas.nc .
  981. cp ${oas_grid_dir}/tm5_grids.nc .
  982. cp ${oas_grid_dir}/tm5_masks.nc .
  983. if ${oas_link_weights}
  984. then
  985. for f in ${oas_grid_dir}/rmp_????_to_????_*.nc
  986. do
  987. ln -s $f
  988. done
  989. fi
  990. # -- Get restart files for TM5-IFS/LPJG/PISCES
  991. for f in ${oas_rst_ifs_tm5}
  992. do
  993. cp ${oas_grid_dir}/rst/${tm5_exch_nlevs}-levels/$f .
  994. done
  995. # -- Merge grid definition files
  996. cdo merge gcm_areas.nc tm5_areas.nc areas.nc
  997. cdo merge gcm_grids.nc tm5_grids.nc grids.nc
  998. cdo merge gcm_masks.nc tm5_masks.nc masks.nc
  999. fi
  1000. else # i.e. $leg_is_restart == true
  1001. # ---------------------------------------------------------------------
  1002. # *** Remove all leftover output files from previous legs
  1003. # ---------------------------------------------------------------------
  1004. # IFS files
  1005. rm -f ICM{SH,GG}${exp_name}+??????
  1006. # NEMO files
  1007. rm -f ${exp_name}_??_????????_????????_{grid_U,grid_V,grid_W,grid_T,icemod,SBC,scalar,SBC_scalar,diad_T}.nc
  1008. # TM5 restart file type
  1009. tm5_istart=33
  1010. if [ $tm5_istart -eq 31 ] && $(has_config tm5)
  1011. then
  1012. ln -sf save_${leg_start_date_yyyymmdd}00_glb300x200.hdf tm5_save.hdf
  1013. fi
  1014. fi # ! $leg_is_restart
  1015. #--------------------------------------------------------------------------
  1016. # *** Surface restoring and ocean nudging options
  1017. #--------------------------------------------------------------------------
  1018. if $(has_config nemo:ocenudg) ; then
  1019. ln -fs ${ini_data_dir}/nemo/oce_nudg/temp_sal*.nc ./
  1020. fi
  1021. if $(has_config nemo:surfresto) ; then
  1022. ln -fs ${ini_data_dir}/nemo/surface_restoring/sss_restore_data*.nc ./
  1023. ln -fs ${ini_data_dir}/nemo/surface_restoring/sst_restore_data*.nc ./
  1024. ln -fs ${ini_data_dir}/nemo/surface_restoring/mask_restore*.nc ./
  1025. fi
  1026. # -------------------------------------------------------------------------
  1027. # *** Remove land grid-points
  1028. # -------------------------------------------------------------------------
  1029. if $(has_config nemo:elpin)
  1030. then
  1031. if [ ! -f coordinates_xios.nc ]
  1032. then
  1033. error "ELpIN requested, but file 'coordinates_xios.nc' was not found"
  1034. fi
  1035. jpns=($(${ecearth_src_dir}/util/ELPiN/ELPiNv2.cmd ${nem_numproc}))
  1036. info "nemo domain decompostion from ELpIN: ${jpns[@]}"
  1037. nem_numproc=${jpns[0]}
  1038. nem_jpni=${jpns[1]}
  1039. nem_jpnj=${jpns[2]}
  1040. elif has_config nemo
  1041. then
  1042. info "nemo original domain decomposition (not using ELPiN)"
  1043. fi
  1044. # -------------------------------------------------------------------------
  1045. # *** Initial conditions saved during the run
  1046. # -------------------------------------------------------------------------
  1047. ${do_save_ic} && save_ic_prepare_output
  1048. # -------------------------------------------------------------------------
  1049. # *** Create some control files
  1050. # -------------------------------------------------------------------------
  1051. # Create TM5 runtime rcfile
  1052. tm5_start_date=$(date -u -d "${leg_start_date}" +%F\ %T)
  1053. tm5_end_date=$(date -u -d "${leg_end_date}" +%F\ %T)
  1054. if $(has_config tm5)
  1055. then
  1056. cp -f ${ctrl_file_dir}/tm5-config-run.rc ${run_dir}
  1057. ${ecearth_src_dir}/tm5mp/setup_tm5 --no-compile \
  1058. --time-start="${tm5_start_date}" --time-final="${tm5_end_date}" \
  1059. --istart=${tm5_istart} ${run_dir}/tm5-config-run.rc
  1060. fi
  1061. # IFS frequency output for namelist
  1062. if [ -f postins/pptdddddd0300 ]
  1063. then
  1064. ifs_output_freq=$(( 3 * 3600 / ifs_time_step_sec ))
  1065. elif [ -f postins/pptdddddd0600 ]
  1066. then
  1067. ifs_output_freq=$(( 6 * 3600 / ifs_time_step_sec ))
  1068. else
  1069. error "IFS output frequency undefined."
  1070. fi
  1071. # IFS, NEMO, LIM, AMIP namelist and OASIS namcouple files
  1072. has_config ifs && . ${ctrl_file_dir}/namelist.ifs.sh > fort.4
  1073. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.ref.sh > namelist_ref
  1074. has_config ifs nemo && . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-coupled.cfg.sh > namelist_cfg
  1075. has_config lim3 && . ${ctrl_file_dir}/namelist.lim3.ref.sh > namelist_ice_ref
  1076. has_config lim3 && . ${ctrl_file_dir}/namelist.lim3-${nem_grid}.cfg.sh > namelist_ice_cfg
  1077. has_config rnfmapper && . ${ctrl_file_dir}/namelist.runoffmapper.sh > namelist.runoffmapper
  1078. has_config amip && . ${ctrl_file_dir}/namelist.amip.sh > namelist.amip
  1079. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.top.ref.sh > namelist_top_ref
  1080. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.top.cfg.sh > namelist_top_cfg
  1081. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.pisces.ref.sh > namelist_pisces_ref
  1082. has_config pisces && . ${ctrl_file_dir}/namelist.nemo.pisces.cfg.sh > namelist_pisces_cfg
  1083. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.age.ref.sh > namelist_age_ref
  1084. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.age.cfg.sh > namelist_age_cfg
  1085. #include CFCs namelist even if CFCs are not included
  1086. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.cfc.ref.sh > namelist_cfc_ref
  1087. has_config nemo && . ${ctrl_file_dir}/namelist.nemo.cfc.cfg.sh > namelist_cfc_cfg
  1088. # C-cycle - overwrite coupled nemo namelist
  1089. has_config pisces tm5:co2 && \
  1090. . ${ctrl_file_dir}/namelist.nemo-${nem_grid}-carboncycle.cfg.sh > namelist_cfg
  1091. lucia=0
  1092. . ${ctrl_file_dir}/namcouple.sh > namcouple
  1093. # -------------------------------------------------------------------------
  1094. # *** LPJ-GUESS initial data
  1095. # -------------------------------------------------------------------------
  1096. if $(has_config lpjg)
  1097. then
  1098. # LPJG runtime rcfile - update with leg dates
  1099. . ${ctrl_file_dir}/namelist.lpjg.sh > lpjg_steps.rc
  1100. # determine lpjg scenario-name and co2-file middle-fix
  1101. case $(echo ${ifs_cmip6_scenario} | tr '[:upper:]' '[:lower:]') in
  1102. hist*) lpjg_scen="ssp370"; lu_src="AIM" ; lpjg_sco2_mfix="AIM-ssp370-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  1103. ssp1-1.9*) lpjg_scen="ssp119"; lu_src="IMAGE" ; lpjg_sco2_mfix="IMAGE-ssp119-1-2-1" ; lu_file_posfix="2019_03_13.txt";;
  1104. ssp1-2.6*) lpjg_scen="ssp126"; lu_src="IMAGE" ; lpjg_sco2_mfix="IMAGE-ssp126-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  1105. ssp2-4.5*) lpjg_scen="ssp245"; lu_src="MESSAGE"; lpjg_sco2_mfix="MESSAGE-GLOBIOM-ssp245-1-2-1"; lu_file_posfix="2018_10_08.txt";;
  1106. ssp3-7.0*) lpjg_scen="ssp370"; lu_src="AIM" ; lpjg_sco2_mfix="AIM-ssp370-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  1107. ssp4-3.4*) lpjg_scen="ssp434"; lu_src="GCAM" ; lpjg_sco2_mfix="GCAM4-ssp434-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  1108. ssp5-3.4*) lpjg_scen="ssp534os"; lu_src="MAGPIE"; lpjg_sco2_mfix="REMIND-MAGPIE-ssp534-over-1-2-1" ; lu_file_posfix="2019_05_10.txt";;
  1109. ssp5-8.5*) lpjg_scen="ssp585"; lu_src="MAGPIE" ; lpjg_sco2_mfix="REMIND-MAGPIE-ssp585-1-2-1" ; lu_file_posfix="2018_10_08.txt";;
  1110. *) error "Scenario ${ifs_cmip6_scenario} not defined for LPJ-GUESS" ;;
  1111. esac
  1112. lpjg_scenario_new="historical + $lpjg_sco2_mfix"
  1113. lpjg_scenario_info=${run_dir}/lpjg_scenario.info
  1114. if [ -f $lpjg_scenario_info ]
  1115. then
  1116. source $lpjg_scenario_info
  1117. if [ "$lpjg_scenario_new" = "$lpjg_scenario" ]
  1118. then
  1119. lpjg_copy_rte=false
  1120. else
  1121. lpjg_copy_rte=true
  1122. fi
  1123. else
  1124. lpjg_copy_rte=true
  1125. fi
  1126. # copy RTE only if necessary (at beginning of a run or when scenario changes)
  1127. if $lpjg_copy_rte
  1128. then
  1129. # write info about installed scenarios to file
  1130. echo "lpjg_scenario=\"historical + $lpjg_sco2_mfix\"" > $lpjg_scenario_info
  1131. # set file prefixes depending on scenario
  1132. lu_file_prefix="1850_2100_luh2_Hist_ScenarioMIP_UofMD"
  1133. lu_file_midfix="2_1_f"
  1134. lu_path="${ini_data_dir}/lpjg/landuse/${lpjg_res}/${lpjg_scen}"
  1135. # copy and reference-link landuse, gross transitions, crops, n-fertilisation
  1136. for inp in lu gross crop nfert
  1137. do
  1138. if [ $inp == "crop" -o $inp == "nfert" ]
  1139. then
  1140. lu_src_file="${lu_path}/${inp}_rfirr_${lu_file_prefix}_${lu_src}_${lpjg_scen}_${lu_file_midfix}_${lpjg_res}_${lu_file_posfix}"
  1141. else
  1142. lu_src_file="${lu_path}/${inp}_${lu_file_prefix}_${lu_src}_${lpjg_scen}_${lu_file_midfix}_${lpjg_res}_${lu_file_posfix}"
  1143. fi
  1144. cp -f $lu_src_file ${run_dir}/landuse/${inp}_luh2.txt
  1145. ln -fs $lu_src_file ${run_dir}/landuse/${inp}_luh2.txt.lnk
  1146. done
  1147. # nitrogen deposition files
  1148. mkdir -p ${run_dir}/ndep
  1149. for inp in drynhx2 drynoy2 wetnhx2 wetnoy2
  1150. do
  1151. ndep_src_file="${ini_data_dir}/lpjg/ndep/${lpjg_res}/${lpjg_scen}/${lpjg_scen}_${lpjg_res}_${inp}.nc"
  1152. cp -f $ndep_src_file ${run_dir}/ndep/${inp}.nc
  1153. ln -fs $ndep_src_file ${run_dir}/ndep/${inp}.nc.lnk
  1154. done
  1155. # concatenate historic and scenario (2015+) co2 concentration file
  1156. # hist co2 file
  1157. lpjg_hco2_file="${ini_data_dir}/ifs/cmip6-data/mole-fraction-of-carbon-dioxide-in-air_input4MIPs_GHGConcentrations_CMIP_UoM-CMIP-1-2-0_gr1-GMNHSH_0000-2014.nc"
  1158. # scenario co2 file
  1159. lpjg_sco2_file="${ini_data_dir}/ifs/cmip6-data/mole-fraction-of-carbon-dioxide-in-air_input4MIPs_GHGConcentrations_ScenarioMIP_UoM-${lpjg_sco2_mfix}_gr1-GMNHSH_2015-2500.nc"
  1160. # combined file
  1161. lpjg_co2_file="${run_dir}/mole_fraction_of_carbon_dioxide_in_air_input4MIPs_lpjg.nc"
  1162. rm -f $lpjg_co2_file
  1163. cdo mergetime $lpjg_hco2_file $lpjg_sco2_file $lpjg_co2_file
  1164. fi
  1165. # Populate or update LPJG run directories
  1166. for (( n=1; n<=${lpjg_numproc}; n++ ))
  1167. do
  1168. # if run from scratch or number of procs has been extended
  1169. if ! $leg_is_restart || [ ! -d ${run_dir}/run${n} ]
  1170. then
  1171. # Make output directories
  1172. mkdir -p ${run_dir}/run${n}/output
  1173. # Copy *.ins, lpjg_steps.rc and OASIS-MCT restart files
  1174. cp ${run_dir}/*.ins ${run_dir}/run${n}
  1175. # Copy output control files
  1176. cp ${output_control_files_dir}/lpjg_cmip6_output.ins ${run_dir}/run${n}
  1177. ln -s ${output_control_files_dir}/lpjg_cmip6_output.ins ${run_dir}/run${n}/lpjg_cmip6_output.ins.lnk
  1178. cp ${ini_data_dir}/lpjg/oasismct/ghg*.txt ${run_dir}/run${n}
  1179. cp ${ini_data_dir}/lpjg/oasismct/${lpjg_res}/ece_gridlist_${lpjg_res}.txt ${run_dir}/run${n}/ece_gridlist.txt
  1180. ln -s ${ini_data_dir}/lpjg/oasismct/${lpjg_res}/ece_gridlist_${lpjg_res}.txt ${run_dir}/run${n}/ece_gridlist.txt.lnk
  1181. # Data only needed by master
  1182. if [ $n == 1 ]
  1183. then
  1184. cp ${ini_data_dir}/lpjg/oasismct/${lpjg_res}/*.nc ${run_dir}
  1185. cp ${ini_data_dir}/lpjg/oasismct/lpjgv.txt ${run_dir}/run${n}
  1186. fi
  1187. fi
  1188. # Refresh output-dirs after they hav been removed at end of the last leg
  1189. mkdir -p ${run_dir}/run${n}/output/CMIP6
  1190. mkdir -p ${run_dir}/run${n}/output/CRESCENDO
  1191. done
  1192. if $leg_is_restart
  1193. then
  1194. lpjg_restart_dir="restart/lpjg/$(printf %03d $((leg_number-1)))"
  1195. lpjg_rst_state="${lpjg_restart_dir}/lpjg_state_${leg_start_date_yyyy}"
  1196. if [ -d "$lpjg_rst_state" ]
  1197. then
  1198. ln -sf $lpjg_rst_state
  1199. else
  1200. echo "lpjg restart dir $lpjg_rst_state not available"
  1201. exit -1
  1202. fi
  1203. # get oasis restart files
  1204. oasis_restart_dir="restart/oasis/$(printf %03d $((leg_number)))"
  1205. cp -f ${oasis_restart_dir}/*.nc ${run_dir}/
  1206. fi
  1207. fi
  1208. # -------------------------------------------------------------------------
  1209. # *** Create ICMCL file with vegetation fields
  1210. # not needed if LPJG is used with feedback
  1211. # -------------------------------------------------------------------------
  1212. tempfile=tmp.$$
  1213. case ${ifs_veg_source} in
  1214. "ifs" )
  1215. # Vegetation from IFS (climatology)
  1216. icmclfile=${ini_data_dir}/ifs/${ifs_grid}/climate/ICMCL_ONLY_VEG_PD
  1217. # Create data for december, the year before the leg starts
  1218. ${grib_set} \
  1219. -s dataDate=$(printf "%04d" $((leg_start_date_yyyy-1)))1215 \
  1220. ${icmclfile}-12 ICMCL${exp_name}INIT
  1221. # Create data for all month in the years of the leg
  1222. for (( y=${leg_start_date_yyyy} ; y<=${leg_end_date_yyyy} ; y++ ))
  1223. do
  1224. yy=$(printf "%04d" $y)
  1225. for m in {1..12}
  1226. do
  1227. mm=$(printf "%02d" $m)
  1228. ${grib_set} -s dataDate=${yy}${mm}15 ${icmclfile}-${mm} ${tempfile}
  1229. cat ${tempfile} >> ICMCL${exp_name}INIT
  1230. done
  1231. done
  1232. # Create data for january, the year after the leg ends
  1233. ${grib_set} \
  1234. -s dataDate=$(printf "%04d" $((leg_end_date_yyyy+1)))0115 \
  1235. ${icmclfile}-01 ${tempfile}
  1236. cat ${tempfile} >> ICMCL${exp_name}INIT
  1237. ;;
  1238. "era20c"|"cmip6"|"custom_"* )
  1239. # Vegetation from a LPJG run (off-line or EC-Earth3-Veg)
  1240. rm -f ICMCL${exp_name}INIT
  1241. # Create data for all years of the leg, including one year
  1242. # before and one year after
  1243. for (( yr=leg_start_date_yyyy-1 ; yr<=leg_end_date_yyyy+1 ; yr+=1 ))
  1244. do
  1245. case ${ifs_veg_source} in
  1246. 'era20c' )
  1247. # no scenario needed with era20c
  1248. icmcl_scenario="" ;;
  1249. 'custom_'* )
  1250. # no scenario implemented yet with custom_dir
  1251. icmcl_scenario="" ;;
  1252. 'cmip6' )
  1253. # select scenario, use SSP3-7.0 as default
  1254. # if not otherwise specified
  1255. icmcl_scenario="historical"
  1256. if ( [ $ifs_cmip_fixyear -le 0 ] && [ $yr -ge 2015 ] ) || \
  1257. [ $ifs_cmip_fixyear -ge 2015 ]
  1258. then
  1259. [[ ${ifs_cmip6_scenario} =~ ^SSP ]] \
  1260. && icmcl_scenario=${ifs_cmip6_scenario} \
  1261. || if [ ${ifs_covid19^^} == TRUE ]
  1262. then
  1263. icmcl_scenario='SSP2-4.5'
  1264. else
  1265. icmcl_scenario='SSP3-7.0'
  1266. fi
  1267. fi ;;
  1268. esac
  1269. if [ $ifs_cmip_fixyear -le 0 ] || [[ ${ifs_veg_source} == custom_* ]]
  1270. then
  1271. cat ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version}/${icmcl_scenario}/icmcl_$yr.grb >> ICMCL${exp_name}INIT
  1272. else
  1273. # Fixed year forcing, requires cdo! (only when not using ifs_veg_source=custom_exp*)
  1274. # If cdo is not available at runtime you need to fix proper
  1275. # icmcl files beforehand and use them here
  1276. cdo setyear,$yr ${ini_data_dir}/ifs/${ifs_grid}/icmcl_${veg_version}/${icmcl_scenario}/icmcl_${ifs_cmip_fixyear}.grb ${tempfile}
  1277. cat ${tempfile} >> ICMCL${exp_name}INIT
  1278. fi
  1279. done
  1280. ;;
  1281. "none" )
  1282. info "no ICMCL file is created"
  1283. ;;
  1284. * )
  1285. error "Vegetation from ${ifs_veg_source} not implemented"
  1286. ;;
  1287. esac
  1288. # Clean up
  1289. rm -f ${tempfile}
  1290. # -------------------------------------------------------------------------
  1291. # *** Link the appropriate NEMO restart files of the previous leg
  1292. # -------------------------------------------------------------------------
  1293. if $leg_is_restart && $(has_config nemo) && ! $special_restart
  1294. then
  1295. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  1296. for (( n=0 ; n<nem_numproc ; n++ ))
  1297. do
  1298. np=$(printf %04d ${n})
  1299. ln -fs ${exp_name}_${ns}_restart_oce_${np}.nc restart_oce_${np}.nc
  1300. ln -fs ${exp_name}_${ns}_restart_ice_${np}.nc restart_ice_${np}.nc
  1301. has_config pisces && \
  1302. ln -fs ${exp_name}_${ns}_restart_trc_${np}.nc restart_trc_${np}.nc
  1303. done
  1304. # Make sure there are no global restart files
  1305. # If links are found, they will be removed. We are cautious and do
  1306. # _not_ remove real files! However, if real global restart files are
  1307. # present, NEMO/LIM will stop because time stamps will not match.
  1308. [ -h restart_oce.nc ] && rm restart_oce.nc
  1309. [ -h restart_ice.nc ] && rm restart_ice.nc
  1310. [ -h restart_trc.nc ] && rm restart_trc.nc
  1311. fi
  1312. # -------------------------------------------------------------------------
  1313. # *** Remove some OASIS files of the previous leg
  1314. # -------------------------------------------------------------------------
  1315. if $leg_is_restart
  1316. then
  1317. rm -f anaisout_*
  1318. fi
  1319. # -------------------------------------------------------------------------
  1320. # *** Remove any ccycle debug output files
  1321. # -------------------------------------------------------------------------
  1322. if ${ccycle_debug_fluxes} && $leg_is_restart && $(has_config tm5:co2)
  1323. then
  1324. if $(has_config lpjg)
  1325. then
  1326. rm -f GUE_{CNAT,CANT,CNPP}_*.nc run1/GUE_{CNAT,CANT,CNPP}_*.nc
  1327. rm -f TM5_Land{CNAT,CANT,CNPP}_*.nc
  1328. fi
  1329. if $(has_config pisces)
  1330. then
  1331. rm -f O_CO2FLX_*.nc
  1332. rm -f TM5_OceCFLX_*.nc
  1333. fi
  1334. fi
  1335. # -------------------------------------------------------------------------
  1336. # *** Check consistency of OASIS restarts and IFS rcf with ece_info_file
  1337. # -------------------------------------------------------------------------
  1338. if $leg_is_restart
  1339. then
  1340. info "Check OASIS restarts and IFS rcf before launch"
  1341. leg_nb_3d=$(printf %03d $((leg_number)))
  1342. for oasis_restart_file in restart/oasis/${leg_nb_3d}/*
  1343. do
  1344. [ ! -f "${oasis_restart_file}" ] && break
  1345. if ! diff -q $(basename ${oasis_restart_file}) ${oasis_restart_file} >/dev/null
  1346. then
  1347. echo "*WARNING* Overwriting OASIS restart (${oasis_restart_file})"
  1348. cp -f ${oasis_restart_file} .
  1349. fi
  1350. done
  1351. rcf_restart_file=restart/ifs/${leg_nb_3d}/rcf
  1352. if [ -f "${rcf_restart_file}" ]
  1353. then
  1354. if ! diff -q rcf ${rcf_restart_file} >/dev/null
  1355. then
  1356. echo "*WARNING* Overwriting IFS rcf file (${rcf_restart_file})"
  1357. cp -f ${rcf_restart_file} .
  1358. fi
  1359. fi
  1360. fi
  1361. # -------------------------------------------------------------------------
  1362. # *** Start the run
  1363. # -------------------------------------------------------------------------
  1364. export DR_HOOK_IGNORE_SIGNALS='-1'
  1365. export CPLNG='active'
  1366. # Use the launch function from the platform configuration file
  1367. has_config nemo && \
  1368. cmd="${xio_numproc} ${xio_exe_file} -- \
  1369. ${nem_numproc} ${nem_exe_file} -- \
  1370. ${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name}" || \
  1371. cmd="${ifs_numproc} ${ifs_exe_file} -v ecmwf -e ${exp_name}"
  1372. has_config lpjg && cmd=${cmd}" -- ${lpjg_numproc} ${lpjg_exe_file} guess.ins -parallel"
  1373. has_config tm5 && cmd=${cmd}" -- ${tm5_numproc} ${tm5_exe_file} tm5-run.rc"
  1374. has_config amip && cmd=${cmd}" -- ${amip_numproc} ${amip_exe_file}"
  1375. has_config nemo && cmd=${cmd}" -- ${rnf_numproc} ${rnf_exe_file}"
  1376. t1=$(date +%s)
  1377. launch $cmd
  1378. t2=$(date +%s)
  1379. tr=$(date -d "0 -$t1 sec + $t2 sec" +%T)
  1380. # -------------------------------------------------------------------------
  1381. # *** Check for signs of success
  1382. # Note the tests provide no guarantee that things went fine! They are
  1383. # just based on the IFS, NEMO and TM5 log files. More tests (e.g. checking
  1384. # restart files) could be implemented.
  1385. # -------------------------------------------------------------------------
  1386. # Checking for IFS success
  1387. if [ -f ifs.stat ]
  1388. then
  1389. if [ "$(awk 'END{print $3}' ifs.stat)" == "CNT0" ]
  1390. then
  1391. info "Leg successfully completed according to IFS log file 'ifs.stat'."
  1392. else
  1393. error "Leg not completed according to IFS log file 'ifs.stat'."
  1394. fi
  1395. else
  1396. error "IFS log file 'ifs.stat' not found after run."
  1397. fi
  1398. # Check for NEMO success
  1399. if $(has_config nemo)
  1400. then
  1401. if [ -f ocean.output ]
  1402. then
  1403. if [ "$(sed -n '/New day/h; ${g;s:.*\([0-9/]\{10\}\).*:\1:;p;}' ocean.output)" == "$(date -u -d "${leg_end_date} - 1 day" +%Y/%m/%d)" ]
  1404. then
  1405. info "Leg successfully completed according to NEMO log file 'ocean.output'."
  1406. else
  1407. error "Leg not completed according to NEMO log file 'ocean.output'."
  1408. fi
  1409. else
  1410. error "NEMO log file 'ocean.output' not found after run."
  1411. fi
  1412. fi
  1413. # Check for TM5 success
  1414. if $(has_config tm5)
  1415. then
  1416. if [ -f tm5.ok ]
  1417. then
  1418. info "Leg successfully completed according to existing TM5 file 'tm5.ok'."
  1419. else
  1420. error "Leg not completed according to non-existing TM5 file 'tm5.ok'."
  1421. fi
  1422. fi
  1423. # -------------------------------------------------------------------------
  1424. # *** Post-process initial conditions saved during the run if requested
  1425. # -------------------------------------------------------------------------
  1426. ${do_save_ic} && save_ic_postproc
  1427. # -------------------------------------------------------------------------
  1428. # *** Move IFS output files to archive directory
  1429. # -------------------------------------------------------------------------
  1430. outdir="${archive_dir}/output/ifs/$(printf %03d $((leg_number)))"
  1431. mkdir -p ${outdir}
  1432. prv_leg=$(printf %03d $((leg_number-1)))
  1433. # This takes care of a special IFS feature: The output for the last time
  1434. # step of each leg is written at the first time step of the new leg. The
  1435. # following code makes sure that the output is appended to the appropriate
  1436. # file. Since GRIB files are just streams, its done with a simple cat
  1437. # command.
  1438. for f in ICMSH${exp_name}+?????? ICMGG${exp_name}+??????
  1439. do
  1440. if [ -f output/ifs/${prv_leg}/${f} ]
  1441. then
  1442. cat ${f} >> output/ifs/${prv_leg}/${f}
  1443. rm -f ${f}
  1444. else
  1445. mv ${f} ${outdir}
  1446. fi
  1447. done
  1448. # -------------------------------------------------------------------------
  1449. # *** Move NEMO output files to archive directory
  1450. # -------------------------------------------------------------------------
  1451. if $(has_config nemo)
  1452. then
  1453. outdir="${archive_dir}/output/nemo/$(printf %03d $((leg_number)))"
  1454. mkdir -p ${outdir}
  1455. for v in grid_U grid_V grid_W grid_T icemod SBC scalar SBC_scalar diad_T ptrc_T bioscalar \
  1456. grid_T_2D grid_U_2D grid_V_2D grid_W_2D grid_T_3D grid_U_3D grid_V_3D grid_W_3D \
  1457. grid_T_SFC grid_1point grid_T_3D_ncatice vert_sum \
  1458. grid_ptr_W_3basin_3D grid_ptr_T_3basin_2D grid_ptr_T_2D \
  1459. zoom_700_sum zoom_300_sum zoom_2000_sum
  1460. do
  1461. for f in ${exp_name}_*_????????_????????_*${v}.nc
  1462. do
  1463. test -f $f && mv $f $outdir/
  1464. done
  1465. done
  1466. fi
  1467. # -------------------------------------------------------------------------
  1468. # *** Move LPJ-GUESS output files to archive directory
  1469. # -------------------------------------------------------------------------
  1470. if $(has_config lpjg)
  1471. then
  1472. outdir="output/lpjg/$(printf %03d $((leg_number)))"
  1473. if [ -d ${outdir} ]
  1474. then
  1475. rm -rf ${outdir}
  1476. fi
  1477. mkdir -p ${outdir}
  1478. # LPJG run directories
  1479. # concatenate *.out (or compressed *.out.gz) files from each run* into output dir
  1480. flist=$(cd ${run_dir}/run1/output && find *.out.gz -type f 2>/dev/null || true)
  1481. if [ "$flist" = "" ]
  1482. then
  1483. lpjg_compress_output=false
  1484. flist=$(cd ${run_dir}/run1/output && find *.out -type f 2>/dev/null)
  1485. else
  1486. lpjg_compress_output=true
  1487. fi
  1488. mkdir ${outdir}/CMIP6
  1489. for (( n=1; n<=${lpjg_numproc}; n++ ))
  1490. do
  1491. for ofile in $flist
  1492. do
  1493. if $lpjg_compress_output
  1494. then
  1495. [ $n == 1 ] && gzip -c ${run_dir}/run${n}/output/`basename ${ofile} .gz`.hdr > ${outdir}/$ofile
  1496. cat ${run_dir}/run${n}/output/${ofile} >> ${outdir}/$ofile
  1497. else
  1498. if (( n == 1 ))
  1499. then
  1500. cat ${run_dir}/run${n}/output/${ofile} > ${outdir}/$ofile
  1501. else
  1502. awk '(FNR!=1){print $0}' ${run_dir}/run${n}/output/${ofile} >> ${outdir}/$ofile
  1503. fi
  1504. fi
  1505. done
  1506. rm -rf ${run_dir}/run${n}/output
  1507. done
  1508. # move monthly file if available
  1509. if [ -f ${run_dir}/LPJ-GUESS_monthlyoutput.txt ]
  1510. then
  1511. mv ${run_dir}/LPJ-GUESS_monthlyoutput.txt ${outdir}
  1512. fi
  1513. fi
  1514. # -------------------------------------------------------------------------
  1515. # *** Move TM5 output files to archive directory
  1516. # -------------------------------------------------------------------------
  1517. if $(has_config tm5)
  1518. then
  1519. outdir="output/tm5/$(printf %03d $((leg_number)))"
  1520. mkdir -p ${outdir}
  1521. set +e
  1522. mv budget_??????????_??????????_global.hdf ${outdir}
  1523. mv j_statistics_??????????_??????????.hdf ${outdir}
  1524. mv mmix_??????????_??????????_glb???x???.hdf ${outdir}
  1525. mv aerocom?_TM5_*_????????_daily.nc ${outdir}
  1526. mv aerocom?_TM5_*_??????_monthly.nc ${outdir}
  1527. mv AOD_????_??_??.nc ${outdir}
  1528. mv -f TM5MP_${exp_name}_griddef.nc ${outdir}
  1529. mv TM5MP_${exp_name}_TP_????_??_??.nc ${outdir}
  1530. mv TM5MP_${exp_name}_vmr3_????_??_??.nc ${outdir}
  1531. mv general_TM5_${exp_name}_??????????_hourly.nc ${outdir}
  1532. mv general_TM5_${exp_name}_??????_monthly.nc ${outdir}
  1533. mv *EC-Earth3-*_${exp_name}_*.nc ${outdir}
  1534. set -e
  1535. # move profiling files if any
  1536. if [ "$(ls -A ${run_dir}/tm5_profile)" ]
  1537. then
  1538. outdir="output/tm5/profile_$(printf %03d $((leg_number)))"
  1539. mkdir -p ${outdir}
  1540. for f in ${run_dir}/tm5_profile/*
  1541. do
  1542. test -f ${f} && mv $f ${outdir}
  1543. done
  1544. fi
  1545. fi
  1546. # -------------------------------------------------------------------------
  1547. # *** Move IFS restart files to archive directory
  1548. # -------------------------------------------------------------------------
  1549. if $leg_is_restart
  1550. then
  1551. outdir="${archive_dir}/restart/ifs/$(printf %03d $((leg_number)))"
  1552. mkdir -p ${outdir}
  1553. # Figure out the time part of the restart files (cf. CTIME on rcf files)
  1554. # NOTE: Assuming that restarts are at full days (time=0000) only!
  1555. nd="$(printf %06d $((leg_start_sec/(24*3600))))0000"
  1556. mv srf${nd}.???? ${outdir}
  1557. fi
  1558. # -------------------------------------------------------------------------
  1559. # *** Move ccycle debug output files to archive directory
  1560. # -------------------------------------------------------------------------
  1561. if ${ccycle_debug_fluxes} && $(has_config tm5:co2)
  1562. then
  1563. outdir="output/tm5/$(printf %03d $((leg_number)))"
  1564. mkdir -p ${outdir}
  1565. if $(has_config lpjg)
  1566. then
  1567. for f in CNAT CANT CNPP ; do
  1568. mv TM5_Land${f}_*.nc ${outdir}
  1569. rm -f GUE_${f}_*.nc run1/GUE_${f}_*.nc
  1570. #gf=`ls -1 GUE_${f}_*.nc | head -n 1`
  1571. #cdo mergetime ${gf} run1/${gf} ${outdir}/${gf}
  1572. done
  1573. fi
  1574. if $(has_config pisces)
  1575. then
  1576. mv TM5_OceCFLX_*.nc ${outdir}
  1577. rm -f O_CO2FLX_*.nc
  1578. #mv O_CO2FLX_*.nc ${outdir}
  1579. fi
  1580. fi
  1581. # -------------------------------------------------------------------------
  1582. # *** Move LPJ-GUESS restart files to archive directory
  1583. # -------------------------------------------------------------------------
  1584. if $(has_config lpjg)
  1585. then
  1586. outdir="restart/lpjg/$(printf %03d $((leg_number)))"
  1587. if [ -d ${outdir} ]
  1588. then
  1589. rm -rf ${outdir}
  1590. fi
  1591. mkdir -p ${outdir}
  1592. state_dir="./lpjg_state_$(printf %04d $((leg_end_date_yyyy)))"
  1593. mv ${state_dir} ${outdir}
  1594. # LPJG writes into run1 dir, so mv to main rundir
  1595. mv -f run1/lpjgv.nc .
  1596. has_config tm5:co2 lpjg && mv -f run1/rlpjg.nc .
  1597. # remove restart link
  1598. if $leg_is_restart
  1599. then
  1600. old_state_dir="./lpjg_state_$(printf %04d $((leg_start_date_yyyy)))"
  1601. if [ -L $old_state_dir ]
  1602. then
  1603. rm -f "$old_state_dir"
  1604. fi
  1605. fi
  1606. fi
  1607. # -------------------------------------------------------------------------
  1608. # *** Move NEMO restart files to archive directory
  1609. # -------------------------------------------------------------------------
  1610. if $leg_is_restart && $(has_config nemo)
  1611. then
  1612. outdir="${archive_dir}/restart/nemo/$(printf %03d $((leg_number)))"
  1613. mkdir -p ${outdir}
  1614. ns=$(printf %08d $(( leg_start_sec / nem_time_step_sec - nem_restart_offset )))
  1615. for f in oce ice
  1616. do
  1617. mv ${exp_name}_${ns}_restart_${f}_????.nc ${outdir}
  1618. done
  1619. if has_config pisces
  1620. then
  1621. mv ${exp_name}_${ns}_restart_trc_????.nc ${outdir}
  1622. fi
  1623. fi
  1624. # -------------------------------------------------------------------------
  1625. # *** Move TM5 restart file to archive directory
  1626. # -------------------------------------------------------------------------
  1627. if $leg_is_restart && $(has_config tm5)
  1628. then
  1629. outdir="restart/tm5/$(printf %03d $((leg_number)))"
  1630. mkdir -p ${outdir}
  1631. case ${tm5_istart} in
  1632. 33|32) f=TM5_restart_${leg_start_date_yyyymmdd}_0000_glb300x200.nc
  1633. ;;
  1634. 31) f=save_${leg_start_date_yyyymmdd}00_glb300x200.hdf
  1635. ;;
  1636. esac
  1637. mv $f ${outdir}
  1638. fi
  1639. # -------------------------------------------------------------------------
  1640. # *** Copy OASIS restart files to archive directory
  1641. # NOTE: These files are copied and not moved as they are used in the
  1642. # next leg!
  1643. # Note also that the OASIS restart files present at the end of
  1644. # the leg correspond to the start of the next leg!
  1645. # -------------------------------------------------------------------------
  1646. outdir="${archive_dir}/restart/oasis/$(printf %03d $((leg_number+1)))"
  1647. mkdir -p ${outdir}
  1648. for f in ${oas_rst_files}
  1649. do
  1650. test -f ${f} && cp ${f} ${outdir}
  1651. done
  1652. # -------------------------------------------------------------------------
  1653. # *** Copy rcf files to the archive directory (of the next leg!)
  1654. # -------------------------------------------------------------------------
  1655. outdir="${archive_dir}/restart/ifs/$(printf %03d $((leg_number+1)))"
  1656. mkdir -p ${outdir}
  1657. for f in rcf
  1658. do
  1659. test -f ${f} && cp ${f} ${outdir}
  1660. done
  1661. # -------------------------------------------------------------------------
  1662. # *** Move log files to archive directory
  1663. # -------------------------------------------------------------------------
  1664. outdir="${archive_dir}/log/$(printf %03d $((leg_number)))"
  1665. mkdir -p ${outdir}
  1666. for f in \
  1667. ifs.log ifs.stat fort.4 ocean.output \
  1668. time.step solver.stat guess.log run1/guess0.log \
  1669. amip.log namelist.amip \
  1670. nout.000000 debug.root.?? \
  1671. ctm.tm5.log.0
  1672. do
  1673. test -f ${f} && mv ${f} ${outdir}
  1674. done
  1675. has_config pisces && cp ocean.carbon ${outdir}
  1676. for f in ctm.tm5.log.*
  1677. do
  1678. if [[ -f ${f} ]]
  1679. then
  1680. [[ -s ${f} ]] && mv ${f} ${outdir} || \rm -f ${f}
  1681. fi
  1682. done
  1683. # -------------------------------------------------------------------------
  1684. # *** Write the restart control file
  1685. # -------------------------------------------------------------------------
  1686. # Compute CPMIP performance
  1687. sypd="$(cpmip_sypd $leg_length_sec $(($t2 - $t1)))"
  1688. ncores=0
  1689. has_config nemo && (( ncores+=${nem_numproc} )) || :
  1690. has_config ifs && (( ncores+=${ifs_numproc} )) || :
  1691. has_config xios && (( ncores+=${xio_numproc} )) || :
  1692. has_config rnfmapper && (( ncores+=${rnf_numproc} )) || :
  1693. has_config lpjg && (( ncores+=${lpjg_numproc} )) || :
  1694. has_config tm5 && (( ncores+=${tm5_numproc} )) || :
  1695. has_config amip && (( ncores+=${amip_numproc} )) || :
  1696. chpsy="$(cpmip_chpsy $leg_length_sec $(($t2 - $t1)) $ncores)"
  1697. echo "#" | tee -a ${ece_info_file}
  1698. echo "# Finished leg at `date '+%F %T'` after ${tr} (hh:mm:ss)" \
  1699. | tee -a ${ece_info_file}
  1700. echo "# CPMIP performance: $sypd SYPD $chpsy CHPSY"| tee -a ${ece_info_file}
  1701. echo "leg_number=${leg_number}" | tee -a ${ece_info_file}
  1702. echo "leg_start_date=\"${leg_start_date}\"" | tee -a ${ece_info_file}
  1703. echo "leg_end_date=\"${leg_end_date}\"" | tee -a ${ece_info_file}
  1704. # Need to reset force_run_from_scratch in order to avoid destroying the next leg
  1705. force_run_from_scratch=false
  1706. special_restart=false
  1707. done # loop over legs
  1708. # -----------------------------------------------------------------------------
  1709. # *** Platform dependent finalising of the run
  1710. # -----------------------------------------------------------------------------
  1711. #finalise
  1712. if ${resubmit_job} && [ $(date -d "${leg_end_date}" +%s) -lt $(date -d "${run_end_date}" +%s) ]
  1713. then
  1714. info "Resubmitting job for leg $((leg_number+1))"
  1715. # Need to go to start_dir to find the run script
  1716. cd ${start_dir}
  1717. # Submit command
  1718. echo "sbatch -N ${SLURM_JOB_NUM_NODES-"1"} -o ${run_dir}/$(basename ${stdout_file}).$(printf %03d $((leg_number+1))) \
  1719. -e ${run_dir}/$(basename ${stdout_file}).$(printf %03d $((leg_number+1))) -d ${SLURM_JOB_ID-"id"} \
  1720. ./${SLURM_JOB_NAME-"run"}.sh"
  1721. # Note: This does not work if you specify a job name with sbatch -J jobname!
  1722. sbatch -N ${SLURM_JOB_NUM_NODES-"1"} \
  1723. -o ${run_dir}/$(basename ${stdout_file}).$(printf %03d $((leg_number+1))) \
  1724. -e ${run_dir}/$(basename ${stdout_file}).$(printf %03d $((leg_number+1))) \
  1725. -d ${SLURM_JOB_ID-"id"} \
  1726. ./${SLURM_JOB_NAME-"run"}.sh
  1727. fi
  1728. exit 0