source: CONFIG/UNIFORM/v6/IPSLCM6.2/GENERAL/DRIVER/opa9.driver @ 4721

Last change on this file since 4721 was 4721, checked in by cetlod, 5 years ago

Right correction of bugfix in opa.driver ; the previous one was mistaken

File size: 12.8 KB
RevLine 
[583]1#!/bin/ksh
2#-----------------------------------------------------------------
3function OCE_Initialize
4{
5    IGCM_debug_PushStack "OCE_Initialize"
6
7    JOB_NAME=${config_UserChoices_JobName}
[2117]8
[4616]9    if [ X$ResolOce != X ]; then 
10        #ResolOce is set in config.card
11        RESOL_OCE=${ResolOce}
12        IGCM_debug_Print 1 "RESOL_OCE      : ${RESOL_OCE}"
[583]13
[4616]14    elif [ -f ${SUBMIT_DIR}/../.resol ] ; then
15        RESOL_OCE_ICE=$( echo ${RESOL} | awk "-Fx" '{print $1}' )
16        case ${RESOL_OCE_ICE} in
17            ( *LIM2* ) SEAICE_MODEL=LIM2 ;      LIM_VERSION=2 ;;
18            ( *LIM3* ) SEAICE_MODEL=LIM3 ;      LIM_VERSION=3 ;;
19            ( *CICE* ) SEAICE_MODEL=CICE                  ;;
20            ( *      ) SEAICE_MODEL=UNKNOWN               ;;
21        esac
22        RESOL_OCE=$( echo ${RESOL_OCE_ICE} | sed "s/${SEAICE_MODEL}//" )
23        IGCM_debug_Print 1 "RESOL_OCE_ICE  : ${RESOL_OCE_ICE}"
24        IGCM_debug_Print 1 "RESOL          : ${RESOL}"
25        IGCM_debug_Print 1 "SEAICE_MODEL   : ${SEAICE_MODEL}"
26        IGCM_debug_Print 1 "LIM_VERSION    : ${LIM_VERSION}"
27        IGCM_debug_Print 1 "RESOL_OCE      : ${RESOL_OCE}"
28    else
29        IGCM_debug_Exit "ResolAtm is not set in config.card and the .resol file does not exist."
30        IGCM_debug_Verif_Exit
31    fi
[2109]32
[653]33    # Local function to find namelists parameters
[2540]34    #supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" ; }
35    supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" -e "s%^ *$1 *=%%" ; }
[583]36    ##--Variables used by OPA --
[2198]37    NAMELIST_OPA_CFG=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg
[2379]38    IGCM_debug_Print 1 "namelist_cfg : ${NAMELIST_OPA_CFG}"
[2198]39    if [ ! -r ${NAMELIST_OPA_CFG} ] ; then
[2540]40        IGCM_debug_Exit "${NAMELIST_OPA_CFG} not found"
41        IGCM_debug_Verif_Exit
[2198]42    fi
[2540]43    OPA_RDT=$(       supergrep rn_rdt        ${NAMELIST_OPA_CFG} )
44    OPA_NN_FSBC=$(   supergrep nn_fsbc       ${NAMELIST_OPA_CFG} )
45    #
46    # OPA_RDT=$(       supergrep rn_rdt        namelist_cfg )
47    # OPA_NN_FSBC=$(   supergrep nn_fsbc       namelist_cfg )
[2861]48    (( OPA_NPDT_DAY   =  86400 / OPA_RDT        ))
49    (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 365     ))
[2540]50    (( OPA_RDT_SBC    =  OPA_RDT * OPA_NN_FSBC ))
[2267]51 
[583]52    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
53    # /!\ Needed by OPA namelist to compute file names /!\
54    (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 ))
55
[2379]56    IGCM_debug_Print 1 " "
[2540]57    IGCM_debug_Print 1 "OPA_RDT        ${OPA_RDT}"
58    IGCM_debug_Print 1 "OPA_NN_FSBC    ${OPA_NN_FSBC}"
59    IGCM_debug_Print 1 "OPA_RDT_SBC    ${OPA_RDT_SBC}"
[2861]60    IGCM_debug_Print 1 "OPA_NPDT_DAY   ${OPA_NPDT_DAY}"
61    IGCM_debug_Print 1 "OPA_NPDT_YEAR  ${OPA_NPDT_YEAR}"
[2540]62    IGCM_debug_Print 1 "DaysSinceJC    ${DaysSinceJC}"
63
64    ## Check that nn_fsbc is correct compare to coupling frequency
65    FreqCoupling=${oasis_UserChoices_FreqCoupling:-86400}
[2267]66   
[2540]67    ## This informations are used for diaptr, trends and diagap files
68    ## only the first frequency is used for this files
69   
70    IGCM_debug_Print 1 "FreqCoupling    ${FreqCoupling}"
71    IGCM_debug_Print 1 "OPA_NN_FSBC    ${OPA_NN_FSBC}"
72    IGCM_debug_Print 1 "OPA_RDT        ${OPA_RDT}"
73    IGCM_debug_Print 1 "OPA_RDT_SBC    ${OPA_RDT_SBC}"
74   
75    if [[ ${OPA_RDT_SBC} -gt ${FreqCoupling} ]] ; then
76        IGCM_debug_Exit "OPA_RDT_SBC=${OPA_RDT_SBC} is greater than FreqCoupling=${FreqCoupling}"
77        IGCM_debug_Verif_Exit
78    fi
[3735]79
[583]80    IGCM_debug_PopStack "OCE_Initialize"
[2379]81   
[583]82}
83
84#-----------------------------------------------------------------
85function OCE_Update
86{
87    IGCM_debug_PushStack "OCE_Update"
[2540]88 
[777]89    ##--Write Frequency for iomput
[3434]90    ## Differents frequencies are allowed for OCE files
[777]91
92    V1D_ENABLE=".FALSE."
[2999]93    V5D_ENABLE=".FALSE."
[777]94    V1M_ENABLE=".FALSE."
95    V1Y_ENABLE=".FALSE."
96
97    for frequency in ${config_OCE_WriteFrequency} ; do
98        case ${frequency} in
[2540]99            ( 1D|1d ) V1D_ENABLE=".TRUE." ;;
[2999]100            ( 5D|5d ) V5D_ENABLE=".TRUE." ;;
[2540]101            ( 1M|1m ) V1M_ENABLE=".TRUE." ;;
102            ( *[yY] ) V1Y_ENABLE=".TRUE." ;;
[777]103        esac
104    done
105
[583]106    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
107    # Needed by OPA namelist to compute correct file names
108    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
109
110    ##-- Number of time steps updated : the first, the last and the number of time steps
[2861]111    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NPDT_DAY + 1 ))
112    (( OPA_NPDT   = PeriodLengthInDays * OPA_NPDT_DAY ))
[2540]113    (( OPA_NITEND = OPA_NIT000 + OPA_NPDT - 1))
[583]114
115    ##-- We force one restart file at the end of the trunk
[2540]116    OPA_NSTOCK="${OPA_NITEND}"
[583]117
[3193]118
119    ##-- Additionnal Restart Option to force reproducibility ; force kt to kt red in restart file
120    ## ${opa9_UserChoices_Reproducibility_after_restart}
121
122    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices Reproducibility_after_restart
123
124   ##-- Restart configuration
[4480]125    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
[3193]126      OPA_LRSTAR=.TRUE.
127      OPA_NRSTDT=2
128      #echo "OPA RESTART"
[3786]129      IGCM_debug_Print 1 'WARNING : dangerous option for NEMO opa9 pisces lim3'
[3193]130      IGCM_debug_Print 1 'Reproducibility_after_Restart forced ie kt forced to kt red in restart file : ' ${opa9_UserChoices_Reproducibility_after_restart}
[3786]131
[3193]132    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
133      OPA_LRSTAR=.FALSE.
134      OPA_NRSTDT=0
135      #echo "NO OPA RESTART"
[583]136    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
[3193]137      OPA_LRSTAR=.TRUE.
138      OPA_NRSTDT=0
139      #echo "OPA RESTART"
[583]140    else
[3193]141      OPA_LRSTAR=.TRUE.
142      OPA_NRSTDT=2
143      #echo "OPA RESTART"
[583]144    fi
145
[3523]146    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${opa9_UserChoices_Restart_TS_only}" = "y" ] ) ; then
[3518]147      OPA_LRSTAR_TS=.TRUE.
148    else
149      OPA_LRSTAR_TS=.FALSE.
150    fi
[3193]151
[4720]152    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${opa9_UserChoices_Dynamics_on_ClosedSeas}" = "n" ] ) ; then
[4721]153      OPA_CLODYN=.TRUE.
154    else
[4446]155      OPA_CLODYN=.FALSE.
156    fi
157
[3121]158    ##-- Meshmask option. Forced only once.
[902]159    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask
[819]160
[3121]161    OPA_NMSH=0
[819]162    if [ "${opa9_UserChoices_mesh_mask}" = "y" ]; then
[2540]163        OPA_NMSH=1
[902]164        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask "n"
[819]165    fi
166
[583]167    # nleapy configuration
168    case ${config_UserChoices_CalendarType} in
[2540]169        ( leap|gregorian) OPA_NLEAPY=1  ;;
170        ( noleap        ) OPA_NLEAPY=0  ;;
171        ( 360d          ) OPA_NLEAPY=30 ;;
172        ( *             ) OPA_NLEAPY=30 ;;
[583]173    esac
174
[3786]175    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] ) ; then
[3785]176      ##-- choose the right restart file
177      NEMO_RESTART_FILE=restartopa.nc
178      [ -f restartopa_0000.nc ] && NEMO_RESTART_FILE=restartopa_0000.nc
[3775]179      ##-- Getting from restart file the last time step of the run at which we want to re-start
[3785]180      NEMO_KT_FROM_RESTART=$(ncdump -v kt ${NEMO_RESTART_FILE}|grep 'kt ='|awk '{print $3}' )
[3798]181
182      if ( [ "${CumulPeriod}" -eq 1 ] ) ; then
183        ## Force the date in the restart file to be the last day before the begining of the new run
[3908]184        dateendprevious=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} -1 )
185        IGCM_debug_Print 1 "Previous Date  ${dateendprevious}"
186        IGCM_debug_Print 1 "cmd done to modify NEMO restartfile:   ncap2 -s ndastp=${dateendprevious} ${NEMO_RESTART_FILE}  tmp.nc"
[3835]187        if [ -f restartopa_0000.nc ] ; then
188           typeset -Z4 ncpu=0
189           while [ $ncpu -lt ${OCE_PROC_MPI} ] ; do
[3908]190              ncap2 -s "ndastp=${dateendprevious}" restartopa_${ncpu}.nc  tmp.nc
[3835]191              mv tmp.nc restartopa_${ncpu}.nc
192              (( ncpu = ncpu + 1 ))
193           done
194        else
[3908]195           ncap2 -s "ndastp=${dateendprevious}" ${NEMO_RESTART_FILE}  tmp.nc
[3835]196           mv tmp.nc ${NEMO_RESTART_FILE}
197        fi
[3798]198        ##-- Getting from restart file the "new" restart date of run at which we want to re-start
199        NEMO_NDASTP_FROM_RESTART=$(ncdump -v ndastp ${NEMO_RESTART_FILE}|grep 'ndastp ='|awk '{print $3}' )
200        IGCM_debug_Print 1 "NEMO_NDASTP (from Restart) for 1st Period       : ${NEMO_NDASTP_FROM_RESTART}"
201
202      fi
203
[3193]204      (( NEMO_NIT000 = NEMO_KT_FROM_RESTART + 1 ))
205      (( NEMO_NITEND = NEMO_KT_FROM_RESTART + OPA_NITEND - OPA_NIT000 + 1 ))
206      IGCM_debug_Print 1 "NEMO_NIT000 (from Restart)        : ${NEMO_NIT000}"
207      IGCM_debug_Print 1 "NEMO_NITEND (from Restart + ... ) : ${NEMO_NITEND}"
208      ##-- We force one restart file at the end of the trunk
209      OPA_NSTOCK="${NEMO_NITEND}"
210      OPA_NIT000="${NEMO_NIT000}"
211      OPA_NITEND="${NEMO_NITEND}"
212    fi
213
[583]214    typeset -r PRECIS=8
[2540]215    NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
[583]216
[3518]217    IGCM_comp_modifyNamelist blocker    namelist_cfg cn_exp       ${config_UserChoices_JobName}
218    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_it000     ${OPA_NIT000}
219    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_itend     ${OPA_NITEND}
220    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart    ${OPA_LRSTAR}
221    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart_ts ${OPA_LRSTAR_TS}
[4446]222    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_clodyn    ${OPA_CLODYN}
[3518]223    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_stock     ${OPA_NSTOCK}
224    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_rstctl    ${OPA_NRSTDT}
225    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_date0     ${PeriodDateBegin}
226    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_msh       ${OPA_NMSH}
[2625]227    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_rnf_depth_file  ${OPA_NMSH}
[3518]228    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_leapy     ${OPA_NLEAPY}
[2540]229   
230    # Update iodef.xml
[583]231
[2999]232    IGCM_debug_Print 1 'Informations into iodef.xml : V1D_ENABLE V5D_ENABLE V1M_ENABLE V1Y_ENABLE '
233    IGCM_debug_Print 1 ${V1D_ENABLE}  ${V5D_ENABLE} ${V1M_ENABLE} ${V1Y_ENABLE}
[1021]234
[3491]235    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1d_opa enabled ${V1D_ENABLE}
236    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 5d_opa enabled ${V5D_ENABLE}
237    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1m_opa enabled ${V1M_ENABLE}
238    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1y_opa enabled ${V1Y_ENABLE}
[3490]239
[3634]240    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1d_opa output_level ${opa9_UserChoices_OutputLevel}
241    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 5d_opa output_level ${opa9_UserChoices_OutputLevel}
242    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1m_opa output_level ${opa9_UserChoices_OutputLevel}
243    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1y_opa output_level ${opa9_UserChoices_OutputLevel}
244
245
[4295]246    # Update reference year/month/day
247    IGCM_date_GetYearMonthDay ${DateBegin} iyear imonth iday
248    IGCM_comp_modifyXmlFile force context_nemo.xml ref_year  NONE ${iyear} 
249    IGCM_comp_modifyXmlFile force context_nemo.xml ref_month NONE ${imonth} 
250    IGCM_comp_modifyXmlFile force context_nemo.xml ref_day   NONE ${iday} 
251   
252   
[3785]253    # for MPP and switch to different number of procs for NEMO.  We need to suppres restartopa the second period, if restartopa_0000 exist
[1436]254    # same thing for restart_trc and restart_ice_in
255
256    for restartfilenemo in restartopa restart_trc restart_ice_in ; do
257      [ -f ${restartfilenemo}.nc ] && [ -f ${restartfilenemo}_0000.nc ] && IGCM_sys_Rm -f ${restartfilenemo}.nc
258    done
259
[2270]260    # Add include of nemo context in iodef.xml
261    # In iodef.xml add on next line after "COMPONENT CONTEXT"
262    #  <context id="nemo" src="./context_nemo.xml"/>
263    echo '<context id="nemo" src="./context_nemo.xml"/>' > add.tmp
[3476]264    if [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] ; then
265        echo '<context id="nemo" src="./ping_nemo.xml"/>' >> add.tmp
266        echo '<context id="nemo" src="./dr2xml_opa9.xml"/>' >> add.tmp
267    fi
[2270]268    cp iodef.xml iodef.xml.tmp
269    sed -e "/COMPONENT CONTEXT/r add.tmp" \
270        iodef.xml.tmp > iodef.xml
271    rm iodef.xml.tmp add.tmp
272
[2833]273    #Long Name as global attribute (if LongName is not empty)
274    if [ ! "X${config_UserChoices_LongName}" = "X" ] ; then
[2876]275        listfile=$(ls file_def_nemo*.xml)
[2833]276        echo "<variable id=\"LongName\" type=\"string\">${config_UserChoices_LongName}</variable>" > add.tmp
277        for file in ${listfile}
278        do
279            cp ${file} ${file}.tmp
280            sed -e "/<file id/r add.tmp" \
281                ${file}.tmp > ${file}
282            rm ${file}.tmp
283        done
284        rm add.tmp
285    fi
286
[4296]287    #Compression level (if CompressionLevel is not empty)
288    if [ ! "X${config_UserChoices_CompressionLevel}" = "X" ] ; then
[4297]289        echo "NetCDF output files compression level is " ${config_UserChoices_CompressionLevel}
290        listfile=$(ls file_def_nemo*.xml)
291        for file in ${listfile}
292        do
293            sed -i -e "s/\(compression_level=\"\)[^\"]*\(\"\)/\1${config_UserChoices_CompressionLevel}\2/" ${file}
294        done
[4296]295    fi
296
297
[583]298    IGCM_debug_PopStack "OCE_Update"
299}
300
301#-----------------------------------
302function OCE_Finalize
303{
304    IGCM_debug_PushStack "OCE_Finalize"
305
[2379]306    IGCM_debug_Print 1 FINALIZE OCE !!!
[583]307
308    IGCM_debug_PopStack "OCE_Finalize"
309}
Note: See TracBrowser for help on using the repository browser.