[7911] | 1 | #!/bin/ksh |
---|
| 2 | ## Driver for the component SBG corresponding to the stomate part of ORCHIDEE |
---|
| 3 | |
---|
| 4 | #----------------------------------------------------------------- |
---|
| 5 | function SBG_Initialize |
---|
| 6 | { |
---|
| 7 | IGCM_debug_PushStack "SBG_Initialize" |
---|
| 8 | |
---|
| 9 | IGCM_debug_PopStack "SBG_Initialize" |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | #----------------------------------------------------------------- |
---|
| 13 | function SBG_Update |
---|
| 14 | { |
---|
| 15 | IGCM_debug_PushStack "SBG_Update" |
---|
| 16 | |
---|
| 17 | # For IOIPSL: get frequency from config.card |
---|
| 18 | # Set default values for stomate output files. |
---|
| 19 | # These variables are used only to modify file_def_orchidee.xml if XIOS=y |
---|
| 20 | stomate_enabled=.FALSE. |
---|
| 21 | stomate_freq=0s |
---|
| 22 | |
---|
| 23 | # Read WriteFrequency set in config.card section SBG. |
---|
| 24 | # Only one choice can be set as WriteFrequency. The same choice will be used for |
---|
| 25 | # both stomate_history and stomate_ipcc_history files. |
---|
| 26 | case ${config_SBG_WriteFrequency} in |
---|
| 27 | *Y|*y) |
---|
| 28 | NbYears=$( echo ${config_SBG_WriteFrequency} | awk -F '[yY]' '{print $1}' ) |
---|
| 29 | NbDaysYear=$( IGCM_date_DaysInYear ${year} ) |
---|
| 30 | stomate_enabled=.TRUE. |
---|
| 31 | stomate_freq=${NbYears}y |
---|
| 32 | (( STOMATE_WRITE_STEP = NbYears * NbDaysYear )) |
---|
| 33 | ;; |
---|
| 34 | *M|*m) |
---|
| 35 | NbMonths=$( echo ${config_SBG_WriteFrequency} | awk -F '[mM]' '{print $1}' ) |
---|
| 36 | stomate_enabled=.TRUE. |
---|
| 37 | stomate_freq=${NbMonths}mo |
---|
| 38 | # Note only 1M possible with IOIPSL! |
---|
| 39 | STOMATE_WRITE_STEP=-1. ;; |
---|
| 40 | *D|*d) |
---|
| 41 | NbDays=$( echo ${config_SBG_WriteFrequency} | awk -F '[dD]' '{print $1}' ) |
---|
| 42 | stomate_enabled=.TRUE. |
---|
| 43 | stomate_freq=${NbDays}d |
---|
| 44 | STOMATE_WRITE_STEP=${NbDays} ;; |
---|
| 45 | esac |
---|
| 46 | |
---|
| 47 | # Modify file_def_orchidee.def if XIOS is activated using information in stomate.card |
---|
| 48 | # Settings in config.card WriteFrequency are not used any more. |
---|
| 49 | if [ X${orchideedriver_UserChoices_XIOS} = Xy ] ; then |
---|
| 50 | |
---|
| 51 | # Modify file_def_orchidee.xml file using settings from stomate.card |
---|
| 52 | # We here suppose that for each file, in stomate.card UserChoices section, if the parameter |
---|
| 53 | # output_level_filename is set, then also output_freq_filename must be set. The existance of output_freq_filename will not be checked. |
---|
| 54 | # If output_level_filename=NONE or if it is not set, the corresponding file will be deactivated. |
---|
| 55 | |
---|
| 56 | if [ X${stomate_UserChoices_output_level_stomate_history} = X ] || [ X${stomate_UserChoices_output_level_stomate_history} = XNONE ] ; then |
---|
| 57 | # output_level_stomate_history is not set in stomate.card or it is set to NONE. |
---|
| 58 | # Deactivate the file. |
---|
| 59 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 enabled .FALSE. |
---|
| 60 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 output_level 0 |
---|
| 61 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 output_freq 1mo |
---|
| 62 | else |
---|
| 63 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 enabled .TRUE. |
---|
| 64 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 output_level ${stomate_UserChoices_output_level_stomate_history} |
---|
| 65 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 output_freq ${stomate_UserChoices_output_freq_stomate_history} |
---|
| 66 | fi |
---|
| 67 | |
---|
| 68 | if [ X${stomate_UserChoices_output_level_stomate_ipcc_history} = X ] || [ X${stomate_UserChoices_output_level_stomate_ipcc_history} = XNONE ] ; then |
---|
| 69 | # output_level_stomate_ipcc_history is not set in stomate.card or it is set to NONE. |
---|
| 70 | # Deactivate the file. |
---|
| 71 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 enabled .FALSE. |
---|
| 72 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 output_level 0 |
---|
| 73 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 output_freq 1mo |
---|
| 74 | else |
---|
| 75 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 enabled .TRUE. |
---|
| 76 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 output_level ${stomate_UserChoices_output_level_stomate_ipcc_history} |
---|
| 77 | IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 output_freq ${stomate_UserChoices_output_freq_stomate_ipcc_history} |
---|
| 78 | fi |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | # Deactivate stomate IOIPSL output |
---|
| 83 | (( STOMATE_WRITE_STEP = 0 )) |
---|
| 84 | fi |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | if [ X${stomate_UserChoices_SPINUP_ANALYTIC} = Xy ] ; then |
---|
| 88 | IGCM_comp_modifyDefFile nonblocker run.def SPINUP_ANALYTIC y |
---|
| 89 | |
---|
| 90 | # Test if CyclicBegin and CyclicEnd is set in config.card |
---|
| 91 | if ( [ X${config_UserChoices_CyclicBegin} = X ] || [ X${config_UserChoices_CyclicEnd} = X ] ) ; then |
---|
| 92 | IGCM_debug_Exit "CyclicBegin and CyclicEnd must be set in config.card to run option spinup_analytic." |
---|
| 93 | fi |
---|
| 94 | # Calculate and set number of years of forcing data |
---|
| 95 | CycleNb=$(( ${config_UserChoices_CyclicEnd} - ${config_UserChoices_CyclicBegin} + 1 )) |
---|
| 96 | IGCM_comp_modifyDefFile nonblocker run.def SPINUP_PERIOD ${CycleNb} |
---|
| 97 | else |
---|
| 98 | IGCM_comp_modifyDefFile nonblocker run.def SPINUP_ANALYTIC n |
---|
| 99 | IGCM_comp_modifyDefFile nonblocker run.def SPINUP_PERIOD -1 |
---|
| 100 | fi |
---|
| 101 | |
---|
| 102 | IGCM_comp_modifyDefFile nonblocker run.def STOMATE_HIST_DT ${STOMATE_WRITE_STEP} |
---|
| 103 | IGCM_comp_modifyDefFile nonblocker run.def STOMATE_IPCC_HIST_DT ${STOMATE_WRITE_STEP} |
---|
| 104 | |
---|
| 105 | if ( [ ${CumulPeriod} -eq 1 ] && [ "${config_SBG_Restart}" = "n" ] ) ; then |
---|
| 106 | echo "STOMATE : without restart" |
---|
| 107 | IGCM_comp_modifyDefFile blocker run.def STOMATE_RESTART_FILEIN NONE |
---|
| 108 | else |
---|
| 109 | IGCM_comp_modifyDefFile blocker run.def STOMATE_RESTART_FILEIN stomate_rest_in.nc |
---|
| 110 | fi |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | # Special case using forcesoil executable |
---|
| 114 | if [ -f forcesoil ] ; then |
---|
| 115 | # Set STOMATE_CFORCING_NAME |
---|
| 116 | IGCM_comp_modifyDefFile nonblocker run.def STOMATE_CFORCING_NAME stomate_Cforcing.nc |
---|
| 117 | |
---|
| 118 | # Check if restart file is missing |
---|
| 119 | if ( [ ${CumulPeriod} -eq 1 ] && [ "${config_SBG_Restart}" = "n" ] ) ; then |
---|
| 120 | IGCM_debug_Exit "YOU MUST USE OLD STOMATE RESTART FILE WITH THE JOB FORCESOIL." |
---|
| 121 | IGCM_debug_Verif_Exit |
---|
| 122 | fi |
---|
| 123 | else |
---|
| 124 | IGCM_comp_modifyDefFile nonblocker run.def STOMATE_CFORCING_NAME NONE |
---|
| 125 | fi |
---|
| 126 | |
---|
| 127 | IGCM_debug_PopStack "SBG_Update" |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | #----------------------------------------------------------------- |
---|
| 131 | function SBG_Finalize |
---|
| 132 | { |
---|
| 133 | IGCM_debug_PushStack "SBG_Finalize" |
---|
| 134 | |
---|
| 135 | # Check if equilibrium is reached for spinup analytic |
---|
| 136 | # and if true stop the simulation in the end of this period. |
---|
| 137 | if [ X${stomate_UserChoices_SPINUP_ANALYTIC} = Xy ] ; then |
---|
| 138 | CondSpinup=$(grep -a "Equilibrium for carbon pools is reached" out_*) |
---|
| 139 | if [ X"${CondSpinup}" != X ] ; then |
---|
| 140 | IGCM_debug_Print 1 "SPINUP ANALYTIC : your spinup is successful :" |
---|
| 141 | IGCM_debug_Print 1 ${CondSpinup} |
---|
| 142 | IGCM_debug_Print 1 "You can now stop the simulation if you want." |
---|
| 143 | fi |
---|
| 144 | fi |
---|
| 145 | |
---|
| 146 | IGCM_debug_PopStack "SBG_Finalize" |
---|
| 147 | } |
---|