source: trunk/libIGCM/libIGCM_post/libIGCM_post.ksh @ 831

Last change on this file since 831 was 804, checked in by sdipsl, 11 years ago
  • Files waiting for rebuild are stored within the relevant simulation tree. see #87

--> /IGCM_OUT/TagName/SpaceName/ExperiementName/JobName/REBUILD

  • Using only 1 proc and having RebuildFrequency? != NONE won't be an issue. see #88
  • Homogenize RUN_DIR PATH during computing and post-processing. see #92
  • Save text files before restarts and outputs. (more chance to have a clue of what went wrong) see #103
  • Remove useless variable BIG_DIR
  • Cosmectics
  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Revision Author Date
File size: 40.9 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=======================================================================
15
16function IGCM_post_Configure
17{
18  IGCM_debug_PushStack "IGCM_post_Configure"
19
20  # Debug Print :
21  echo
22  IGCM_debug_Print 1 "IGCM_post_Configure"
23  #
24  # Initialize
25  #
26  POST=false
27  RebuildFrequency=false
28  PackFrequency=false
29  TimeSeriesFrequency=false
30  SeasonalFrequency=false
31  unset list_post
32  #
33  # ONLY IF SOMETHING NEEDS TO BE DONE (EATHER TIME SERIES OR SEASONAL) COMPUTE THE MODULOS
34  #
35  if [ X${AsynchronousRebuild} = Xtrue ] ; then
36    list_post="RebuildFrequency"
37  fi
38  #
39  if [ X${Pack} = Xtrue ] ; then
40    list_post="${list_post} PackFrequency"
41  fi
42  #
43  if ( [ X${TimeSeries} = Xtrue ] || [ X${TimeSeries2D} = Xtrue ] || [ X${TimeSeries3D} = Xtrue ] || [ X${TimeSeriesChunck2D} = Xtrue ] || [ X${TimeSeriesChunck3D} = Xtrue ] ) ; then
44    list_post="${list_post} TimeSeriesFrequency"
45  fi
46  #
47  if [ X${Seasonal} = Xtrue ] ; then
48    list_post="${list_post} SeasonalFrequency"
49  fi
50
51  # Overrule special cases
52  if ( [ ! X${config_Post_TimeSeriesFrequency} = X${NULL_STR} ] && \
53    [ ! X${config_Post_TimeSeriesFrequency} = XNONE ]           && \
54    [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ) ; then
55    TimeSeriesFrequency=true
56    POST=true
57  fi
58  #
59  if ( [ X${AsynchronousRebuild} = Xtrue ] && [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ) ; then
60    RebuildFrequency=true
61    POST=true
62  fi
63
64  # READ REBUILD OR TIME SERIES OR SEASONAL FREQUENCY
65  # AND TURN ON THE SUBMISSION FLAG WHEN MODULO IS ZERO
66  for post_freq in ${list_post} ; do
67    # Extract frequency from previously defined variable
68    config_Post_post_freq=$( eval echo \${config_Post_${post_freq}} )
69    # Offset for Seasonal Average starting period
70    if [ ${post_freq} = SeasonalFrequency ] ; then
71      if ( [ X${config_Post_SeasonalFrequencyOffset} = X${NULL_STR} ] || [ X${config_Post_SeasonalFrequencyOffset} = XNONE ] || [ X${config_Post_SeasonalFrequencyOffset} = X ] ) ; then
72        PeriodOffset=0
73      else
74        PeriodOffset=${config_Post_SeasonalFrequencyOffset}
75      fi
76    else
77      PeriodOffset=0
78    fi
79    # Compute Modulo between frequencys (/!\second argument will be multiplied by CumuPeriod/!\)
80    # RebuildFrequency needs additionnal information
81    if [ ${post_freq} = RebuildFrequency ] ; then
82      IGCM_post_ModuloRuntimeFrequency config_Post_post_freq config_UserChoices_PeriodLength NbPeriodPerFrequency
83      NbRebuildDir=${NbPeriodPerFrequency}
84    else
85      IGCM_post_ModuloRuntimeFrequency config_Post_post_freq config_UserChoices_PeriodLength
86    fi
87    #
88    eval IGCM_debug_Print 1 \" "${post_freq} flag value : \${${post_freq}}" \"
89  done
90  #
91  IGCM_debug_Print 2 "POST-TREATEMENT flag value : ${POST}"
92  #
93  # Prepare headers for the shell dedicated to post-processing
94  if ( [ ${PackFrequency} = true ] && ( [ ${TimeSeriesFrequency} = true ] || [ ${SeasonalFrequency} = true ] ) ) ; then
95    if [ $DRYRUN -le 1 ]; then
96      echo "#!/bin/ksh                                     " >  ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
97      echo "function IGCM_FlushPost                        " >> ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
98      echo "{                                              " >> ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
99      echo "IGCM_debug_PushStack \"IGCM_FlushPost\"        " >> ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
100      echo "echo                                           " >> ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
101      echo "IGCM_debug_Print 1 \"IGCM_FlushPost\"          " >> ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
102      echo "echo                                           " >> ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
103    fi
104  fi
105  IGCM_debug_PopStack "IGCM_post_Configure"
106}
107
108function IGCM_post_Submit
109{
110  IGCM_debug_PushStack "IGCM_post_Submit"
111
112  typeset listVarEnv DaysTemp
113
114  POST_DIR=${R_BUF_KSH}
115
116  if [ ${POST} = true ]; then
117    echo
118    IGCM_debug_Print 1 "IGCM_post_Submit"
119    echo
120    IGCM_debug_Print 2 "POST_DIR = ${POST_DIR}"
121  fi
122
123  #============ TIME SERIES POST-PROCESSING ===========#
124  if [ ${TimeSeriesFrequency} = true ] ; then
125
126    IGCM_debug_Print 1 "TIME SERIES POST-PROCESSING ACTIVATED"
127    echo
128
129
130
131    # Get information from last execution
132    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted
133    CompletedFlag=${run_PostProcessing_TimeSeriesCompleted}
134    #
135
136
137
138    listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,MASTER,RebuildFrequency,DateBegin,PeriodDateEnd,StandAlone,CompletedFlag,TsTask,CompToRead,FlagToRead,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_SBG"
139    #
140    jLoop=${#ListDimension[*]}
141    j=0
142    until [ $j -ge ${jLoop} ]; do
143      Dimension=${ListDimension[${j}]}
144      #
145      if [ X$( eval echo \${TimeSeries${Dimension}} ) = Xtrue ] ; then
146      #
147        IGCM_debug_Print 1 "TIME SERIES POST-PROCESSING ${Dimension} ACTIVATED"
148        echo
149        #
150        if [ X${Dimension} = X ] ; then
151          TsTask="empty"
152          Script_Post_Output=create_ts.${PeriodDateEnd}
153        else
154          TsTask=${Dimension}
155          Script_Post_Output=create_ts.${PeriodDateEnd}.${TsTask}
156        fi
157        #
158        if [ ${RebuildFrequency} = true ] ; then
159          #
160          if [ ${PackFrequency} = true ] ; then
161            FunctionPath=${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
162          else
163            FunctionPath=${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
164          fi
165          #
166          if [ -f ${FunctionPath} ] ; then
167#           if [ X${MASTER} = Xtitane ] ; then
168#             echo "IGCM_sys_RshPost <<-EOF"                       >> ${FunctionPath}
169#           fi
170            echo "export DEBUG_debug=${DEBUG_debug}              " >> ${FunctionPath}
171            echo "export MODIPSL=${MODIPSL}                      " >> ${FunctionPath}
172            echo "export libIGCM_SX=${libIGCM}                   " >> ${FunctionPath}
173            echo "export libIGCM=${libIGCM_POST}                 " >> ${FunctionPath}
174            echo "export SUBMIT_DIR=${SUBMIT_DIR}                " >> ${FunctionPath}
175            echo "export POST_DIR=${POST_DIR}                    " >> ${FunctionPath}
176            echo "export MASTER=${MASTER}                        " >> ${FunctionPath}
177            echo "export RebuildFrequency=${RebuildFrequency}    " >> ${FunctionPath}
178            echo "export DateBegin=${DateBegin}                  " >> ${FunctionPath}
179            echo "export PeriodDateEnd=${PeriodDateEnd}          " >> ${FunctionPath}
180            echo "export StandAlone=false                        " >> ${FunctionPath}
181            echo "export CompletedFlag=${CompletedFlag}          " >> ${FunctionPath}
182            echo "export TsTask=${TsTask}                        " >> ${FunctionPath}
183            echo "unset  CompToRead                              " >> ${FunctionPath}
184            echo "unset  FlagToRead                              " >> ${FunctionPath}
185            echo "export RESOL_ATM=${RESOL_ATM}                  " >> ${FunctionPath}
186            echo "export RESOL_OCE=${RESOL_OCE}                  " >> ${FunctionPath}
187            echo "export RESOL_ICE=${RESOL_ICE}                  " >> ${FunctionPath}
188            echo "export RESOL_MBG=${RESOL_MBG}                  " >> ${FunctionPath}
189            echo "export RESOL_SRF=${RESOL_SRF}                  " >> ${FunctionPath}
190            echo "export RESOL_SBG=${RESOL_SBG}                  " >> ${FunctionPath}
191            echo "export listVarEnv=${listVarEnv}                " >> ${FunctionPath}
192            echo "export Script_Post_Output=${Script_Post_Output}" >> ${FunctionPath}
193#           if [ X${MASTER} = Xtitane ] ; then
194#             echo ". ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh" >> ${FunctionPath}
195#             echo ". ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh"     >> ${FunctionPath}
196#           fi
197            echo "IGCM_sys_MkdirWork ${POST_DIR}                 " >> ${FunctionPath}
198            echo "IGCM_debug_Verif_Exit_Post                     " >> ${FunctionPath}
199            echo "IGCM_sys_QsubPost create_ts                    " >> ${FunctionPath}
200#           if [ X${MASTER} = Xtitane ] ; then
201#             echo "EOF"                                           >> ${FunctionPath}
202#           fi
203          fi
204        else
205          IGCM_sys_RshPost <<-EOF
206                    export DEBUG_debug=${DEBUG_debug}
207                    export MODIPSL=${MODIPSL}
208                    export libIGCM_SX=${libIGCM}
209                    export libIGCM=${libIGCM_POST}
210                    export SUBMIT_DIR=${SUBMIT_DIR}
211                    export POST_DIR=${POST_DIR}
212                    export MASTER=${MASTER}
213                    export RebuildFrequency=${RebuildFrequency}
214                    export DateBegin=${DateBegin}
215                    export PeriodDateEnd=${PeriodDateEnd}
216                    export StandAlone=false
217                    export CompletedFlag=${CompletedFlag}
218                    export TsTask=${TsTask}
219                    unset  CompToRead
220                    unset  FlagToRead
221                    export RESOL_ATM=${RESOL_ATM}
222                    export RESOL_OCE=${RESOL_OCE}
223                    export RESOL_ICE=${RESOL_ICE}
224                    export RESOL_MBG=${RESOL_MBG}
225                    export RESOL_SRF=${RESOL_SRF}
226                    export RESOL_SBG=${RESOL_SBG}
227                    export listVarEnv=${listVarEnv}
228                    export Script_Post_Output=${Script_Post_Output}
229                    . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
230                    . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
231                    IGCM_sys_MkdirWork ${POST_DIR}
232                    IGCM_debug_Verif_Exit_Post
233                    IGCM_sys_QsubPost create_ts
234EOF
235        fi
236      fi
237      #
238      if [ X$( eval echo \${TimeSeriesChunck${Dimension}} ) = Xtrue ] ; then
239        #
240        IGCM_debug_Print 1 "TIME SERIES POST-PROCESSING ${Dimension} WITH CHUNCK ACTIVATED"
241        echo
242        # Need to Remember This One
243        SavedDateBegin=${DateBegin}
244        # Kind of task create_ts will perform
245        TsTask=Chunck${Dimension}
246        # Number of chunck jobs to configure and submit
247        eval NbJob=\${#CHUNCK${Dimension}_COMP[@]}
248        typeset i
249        i=0
250        until [ $i -ge $NbJob ]; do
251          CompToRead=$( eval echo \${CHUNCK${Dimension}_COMP[\${i}]} )
252          FlagToRead=$( eval echo \${CHUNCK${Dimension}_FLAG[\${i}]} )
253          NameToRead=$( eval echo \${CHUNCK${Dimension}_NAME[\${i}]} )
254          ChunckSize=$( eval echo \${CHUNCK${Dimension}_SIZE[\${i}]} )
255          # Chunck Length (mandatory in Year)
256          YearsChunckLength=$( echo ${ChunckSize} | sed -e "s/[yY]//" )
257          #
258          IGCM_date_GetYearMonth ${DateBegin}     YearBegin MonthBegin
259          #
260          IGCM_date_GetYearMonth ${PeriodDateEnd} YearEnd   MonthEnd
261          # How many chunck in total since simulation began
262          NbYearsChunckLoop=$(( ( ${YearEnd} - ${YearBegin} + 1 ) / ${YearsChunckLength} ))
263          #  Tweak special case
264          [ $(( ( ${YearEnd} - ${YearBegin} + 1 ) % ${YearsChunckLength} )) = 0 ] && NbYearsChunckLoop=$(( ${NbYearsChunckLoop} - 1 ))
265          # Starting Year of the current chunck
266          ChunckTsYearBegin=$(( ${NbYearsChunckLoop} * ${YearsChunckLength} + ${YearBegin} ))
267          # Starting date of the current chunck
268          ChunckTsDateBegin=${ChunckTsYearBegin}${MonthBegin}01
269          #
270          Script_Post_Output=create_ts.${PeriodDateEnd}.${TsTask}.${CompToRead}.${NameToRead}
271          #
272          if [ ${RebuildFrequency} = true ] ; then
273            #
274            if [ ${PackFrequency} = true ] ; then
275              FunctionPath=${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
276            else
277              FunctionPath=${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
278            fi
279            #
280            if [ -f ${FunctionPath} ] ; then
281#             if [ X${MASTER} = Xtitane ] ; then
282#               echo "IGCM_sys_RshPost <<-EOF"                       >> ${FunctionPath}
283#             fi
284              echo "export DEBUG_debug=${DEBUG_debug}              " >> ${FunctionPath}
285              echo "export MODIPSL=${MODIPSL}                      " >> ${FunctionPath}
286              echo "export libIGCM_SX=${libIGCM}                   " >> ${FunctionPath}
287              echo "export libIGCM=${libIGCM_POST}                 " >> ${FunctionPath}
288              echo "export SUBMIT_DIR=${SUBMIT_DIR}                " >> ${FunctionPath}
289              echo "export POST_DIR=${POST_DIR}                    " >> ${FunctionPath}
290              echo "export MASTER=${MASTER}                        " >> ${FunctionPath}
291              echo "export RebuildFrequency=${RebuildFrequency}    " >> ${FunctionPath}
292              echo "export DateBegin=${ChunckTsDateBegin}          " >> ${FunctionPath}
293              echo "export PeriodDateEnd=${PeriodDateEnd}          " >> ${FunctionPath}
294              echo "export StandAlone=false                        " >> ${FunctionPath}
295              echo "export CompletedFlag=${CompletedFlag}          " >> ${FunctionPath}
296              echo "export TsTask=${TsTask}                        " >> ${FunctionPath}
297              echo "export CompToRead=${CompToRead}                " >> ${FunctionPath}
298              echo "export FlagToRead=${FlagToRead}                " >> ${FunctionPath}
299              echo "export RESOL_ATM=${RESOL_ATM}                  " >> ${FunctionPath}
300              echo "export RESOL_OCE=${RESOL_OCE}                  " >> ${FunctionPath}
301              echo "export RESOL_ICE=${RESOL_ICE}                  " >> ${FunctionPath}
302              echo "export RESOL_MBG=${RESOL_MBG}                  " >> ${FunctionPath}
303              echo "export RESOL_SRF=${RESOL_SRF}                  " >> ${FunctionPath}
304              echo "export RESOL_SBG=${RESOL_SBG}                  " >> ${FunctionPath}
305              echo "export listVarEnv=${listVarEnv}                " >> ${FunctionPath}
306              echo "export Script_Post_Output=${Script_Post_Output}" >> ${FunctionPath}
307#             if [ X${MASTER} = Xtitane ] ; then
308#               echo ". ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh" >> ${FunctionPath}
309#               echo ". ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh"     >> ${FunctionPath}
310#             fi
311              echo "IGCM_sys_MkdirWork ${POST_DIR}                 " >> ${FunctionPath}
312              echo "IGCM_debug_Verif_Exit_Post                     " >> ${FunctionPath}
313              echo "IGCM_sys_QsubPost create_ts                    " >> ${FunctionPath}
314#             if [ X${MASTER} = Xtitane ] ; then
315#               echo "EOF"                                           >> ${FunctionPath}
316#             fi
317            fi
318          else
319            IGCM_sys_RshPost <<-EOF
320                        export DEBUG_debug=${DEBUG_debug}
321                        export MODIPSL=${MODIPSL}
322                        export libIGCM_SX=${libIGCM}
323                        export libIGCM=${libIGCM_POST}
324                        export SUBMIT_DIR=${SUBMIT_DIR}
325                        export POST_DIR=${POST_DIR}
326                        export MASTER=${MASTER}
327                        export RebuildFrequency=${RebuildFrequency}
328                        export DateBegin=${ChunckTsDateBegin}
329                        export PeriodDateEnd=${PeriodDateEnd}
330                        export StandAlone=false
331                        export CompletedFlag=${CompletedFlag}
332                        export TsTask=${TsTask}
333                        export CompToRead=${CompToRead}
334                        export FlagToRead=${FlagToRead}
335                        export RESOL_ATM=${RESOL_ATM}
336                        export RESOL_OCE=${RESOL_OCE}
337                        export RESOL_ICE=${RESOL_ICE}
338                        export RESOL_MBG=${RESOL_MBG}
339                        export RESOL_SRF=${RESOL_SRF}
340                        export RESOL_SBG=${RESOL_SBG}
341                        export listVarEnv=${listVarEnv}
342                        export Script_Post_Output=${Script_Post_Output}
343                        . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
344                        . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
345                        IGCM_sys_MkdirWork ${POST_DIR}
346                        IGCM_debug_Verif_Exit_Post
347                        IGCM_sys_QsubPost create_ts
348EOF
349            #
350          fi
351          #
352          export DateBegin=${SavedDateBegin}
353          #
354          (( i=i+1 ))
355          #
356        done
357      fi
358      (( j=j+1 ))
359    done
360  fi
361
362  #=============  SEASONAL POST-PROCESSING ============#
363  if [ ${SeasonalFrequency} = true ] ; then
364    #
365    IGCM_debug_Print 1 "SEASONNAL POST-PROCESSING"
366    echo
367    #
368    Script_Post_Output=create_se.${PeriodDateEnd}
369    #
370    listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,MASTER,RebuildFrequency,DateBegin,PeriodDateEnd,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_SBG"
371
372    if [ ${RebuildFrequency} = true ] ; then
373      #
374      if [ ${PackFrequency} = true ] ; then
375        FunctionPath=${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
376      else
377        FunctionPath=${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
378      fi
379      #
380      if [ -f ${FunctionPath} ] ; then
381      #
382#     if [ X${MASTER} = Xtitane ] ; then
383#       echo "IGCM_sys_RshPost <<-EOF"                     >> ${FunctionPath}
384#     fi
385      echo "export DEBUG_debug=${DEBUG_debug}              " >> ${FunctionPath}
386      echo "export MODIPSL=${MODIPSL}                      " >> ${FunctionPath}
387      echo "export libIGCM_SX=${libIGCM}                   " >> ${FunctionPath}
388      echo "export libIGCM=${libIGCM_POST}                 " >> ${FunctionPath}
389      echo "export SUBMIT_DIR=${SUBMIT_DIR}                " >> ${FunctionPath}
390      echo "export POST_DIR=${POST_DIR}                    " >> ${FunctionPath}
391      echo "export MASTER=${MASTER}                        " >> ${FunctionPath}
392      echo "export RebuildFrequency=${RebuildFrequency}    " >> ${FunctionPath}
393      echo "export DateBegin=${DateBegin}                  " >> ${FunctionPath}
394      echo "export PeriodDateEnd=${PeriodDateEnd}          " >> ${FunctionPath}
395      echo "export StandAlone=false                        " >> ${FunctionPath}
396      echo "export RESOL_ATM=${RESOL_ATM}                  " >> ${FunctionPath}
397      echo "export RESOL_OCE=${RESOL_OCE}                  " >> ${FunctionPath}
398      echo "export RESOL_ICE=${RESOL_ICE}                  " >> ${FunctionPath}
399      echo "export RESOL_MBG=${RESOL_MBG}                  " >> ${FunctionPath}
400      echo "export RESOL_SRF=${RESOL_SRF}                  " >> ${FunctionPath}
401      echo "export RESOL_SBG=${RESOL_SBG}                  " >> ${FunctionPath}
402      echo "export listVarEnv=${listVarEnv}                " >> ${FunctionPath}
403      echo "export Script_Post_Output=${Script_Post_Output}" >> ${FunctionPath}
404#     if [ X${MASTER} = Xtitane ] ; then
405#       echo ". ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh" >> ${FunctionPath}
406#       echo ". ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh"     >> ${FunctionPath}
407#     fi
408      echo "IGCM_sys_MkdirWork ${POST_DIR}                 " >> ${FunctionPath}
409      echo "IGCM_debug_Verif_Exit_Post                     " >> ${FunctionPath}
410      echo "IGCM_sys_QsubPost create_se                    " >> ${FunctionPath}
411#     if [ X${MASTER} = Xtitane ] ; then
412#       echo "EOF"                                         >> ${FunctionPath}
413#     fi
414      fi
415    else
416      IGCM_sys_RshPost <<-EOF
417            export DEBUG_debug=${DEBUG_debug}
418            export MODIPSL=${MODIPSL}
419          export libIGCM_SX=${libIGCM}
420            export libIGCM=${libIGCM_POST}
421            export SUBMIT_DIR=${SUBMIT_DIR}
422            export POST_DIR=${POST_DIR}
423            export MASTER=${MASTER}
424            export RebuildFrequency=${RebuildFrequency}
425            export DateBegin=${DateBegin}
426            export PeriodDateEnd=${PeriodDateEnd}
427            export StandAlone=false
428            export RESOL_ATM=${RESOL_ATM}
429            export RESOL_OCE=${RESOL_OCE}
430            export RESOL_ICE=${RESOL_ICE}
431            export RESOL_MBG=${RESOL_MBG}
432            export RESOL_SRF=${RESOL_SRF}
433            export RESOL_SBG=${RESOL_SBG}
434            export listVarEnv=${listVarEnv}
435            export Script_Post_Output=${Script_Post_Output}
436            . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
437            . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
438            IGCM_sys_MkdirWork ${POST_DIR}
439            IGCM_debug_Verif_Exit_Post
440            IGCM_sys_QsubPost create_se
441EOF
442    fi
443  fi
444
445  #============== PACK PROCESSING FOR RESTART, DEBUG AND OUTPUT FILES =============#
446  if [ ${PackFrequency} = true ] ; then
447    IGCM_debug_Print 1 "PACK POST-PROCESSING"
448    # -----------------------------------------------------------------------------------
449    # Function IGCM_FlushPost called by pack_output.job has not been closed yet. Do it now
450    # Will submit Time Series OR Seasonal Average if needed
451    # -----------------------------------------------------------------------------------
452    if [ -f ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh ] ; then
453      echo "IGCM_debug_PopStack \"IGCM_FlushPost\" " >> ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
454      echo "}                                      " >> ${R_BUFR}/FlushPost_${PeriodDateEnd}.ksh
455    fi
456    echo
457    ## Need to Remember This One
458    SavedDateBegin=${DateBegin}
459    ## Need to Remember This One
460    SavedDateEnd=${DateEnd}
461    #
462    DaysTemp=$(( $( IGCM_date_DaysInPreviousPeriod ${PeriodDateEnd} ${config_Post_PackFrequency} end ) - 1 ))
463    #
464    PackDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} -${DaysTemp} )
465    #
466    script=pack_debug
467    #
468    Script_Post_Output=${script}.${PeriodDateEnd}
469    #
470    listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,MASTER,DateBegin,DateEnd,PeriodPack,StandAlone"
471    IGCM_sys_RshPost <<-EOF
472    export DEBUG_debug=${DEBUG_debug}
473    export MODIPSL=${MODIPSL}
474    export libIGCM_SX=${libIGCM}
475    export libIGCM=${libIGCM_POST}
476    export SUBMIT_DIR=${SUBMIT_DIR}
477    export POST_DIR=${POST_DIR}
478    export MASTER=${MASTER}
479    export DateBegin=${PackDateBegin}
480    export DateEnd=${PeriodDateEnd}
481    export PeriodPack=${config_Post_PackFrequency}
482    export StandAlone=false
483    export listVarEnv=${listVarEnv}
484    export Script_Post_Output=${Script_Post_Output}
485    . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
486    . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
487    IGCM_sys_MkdirWork ${POST_DIR}
488    IGCM_debug_Verif_Exit_Post
489    IGCM_sys_QsubPost ${script}
490EOF
491    #
492    script=pack_restart
493    #
494    Script_Post_Output=${script}.${PeriodDateEnd}
495    #
496      IGCM_sys_RshPost <<-EOF
497      export DEBUG_debug=${DEBUG_debug}
498      export MODIPSL=${MODIPSL}
499      export libIGCM_SX=${libIGCM}
500      export libIGCM=${libIGCM_POST}
501      export SUBMIT_DIR=${SUBMIT_DIR}
502      export POST_DIR=${POST_DIR}
503      export MASTER=${MASTER}
504      export DateBegin=${PackDateBegin}
505      export DateEnd=${PeriodDateEnd}
506      export PeriodPack=${config_Post_PackFrequency}
507      export StandAlone=false
508      export listVarEnv=${listVarEnv}
509      export Script_Post_Output=${Script_Post_Output}
510      . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
511      . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
512      IGCM_sys_MkdirWork ${POST_DIR}
513      IGCM_debug_Verif_Exit_Post
514      IGCM_sys_QsubPost ${script}
515EOF
516    #
517    script=pack_output
518    #
519    Script_Post_Output=${script}.${PeriodDateEnd}
520    #
521    if ( [ ${RebuildFrequency} = true ] && [ -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ) ; then
522#       if [ X${MASTER} = Xtitane ] ; then
523#         echo "IGCM_sys_RshPost <<-EOF"                     >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
524#       fi
525      echo "export DEBUG_debug=${DEBUG_debug}              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
526      echo "export MODIPSL=${MODIPSL}                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
527      echo "export libIGCM_SX=${libIGCM}                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
528      echo "export libIGCM=${libIGCM_POST}                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
529      echo "export SUBMIT_DIR=${SUBMIT_DIR}                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
530      echo "export POST_DIR=${POST_DIR}                    " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
531      echo "export MASTER=${MASTER}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
532      echo "export DateBegin=${PackDateBegin}              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
533      echo "export DateEnd=${PeriodDateEnd}                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
534      echo "export PeriodPack=${config_Post_PackFrequency} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
535      echo "export StandAlone=false                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
536      echo "export listVarEnv=${listVarEnv}                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
537      echo "export Script_Post_Output=${Script_Post_Output}" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
538      echo "export script=${script}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
539#       if [ X${MASTER} = Xtitane ] ; then
540#         echo ". ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
541#         echo ". ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh"     >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
542#       fi
543      echo "IGCM_sys_MkdirWork ${POST_DIR}                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
544      echo "IGCM_debug_Verif_Exit_Post                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
545      echo "IGCM_sys_QsubPost ${script}                    " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
546#       if [ X${MASTER} = Xtitane ] ; then
547#         echo "EOF"                                         >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
548#       fi
549    else
550      IGCM_sys_RshPost <<-EOF
551        export DEBUG_debug=${DEBUG_debug}
552        export MODIPSL=${MODIPSL}
553        export libIGCM_SX=${libIGCM}
554        export libIGCM=${libIGCM_POST}
555        export SUBMIT_DIR=${SUBMIT_DIR}
556        export POST_DIR=${POST_DIR}
557        export MASTER=${MASTER}
558        export DateBegin=${PackDateBegin}
559        export DateEnd=${PeriodDateEnd}
560        export PeriodPack=${config_Post_PackFrequency}
561        export StandAlone=false
562        export listVarEnv=${listVarEnv}
563        export Script_Post_Output=${Script_Post_Output}
564        . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
565        . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
566        IGCM_sys_MkdirWork ${POST_DIR}
567        IGCM_debug_Verif_Exit_Post
568        IGCM_sys_QsubPost ${script}
569EOF
570      export DateBegin=${SavedDateBegin}
571      export DateEnd=${SavedDateEnd}
572    fi
573  fi
574
575  #============== REBUILD POST-PROCESSING =============#
576  if ( [ X${AsynchronousRebuild} = Xtrue ] && [ -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ) ; then
577    # -----------------------------------------------------------------------------------
578    # Function IGCM_FlushRebuild define in rebuild.ksh has not been closed yet. Do it now
579    # -----------------------------------------------------------------------------------
580    if [ ${DRYRUN} -le 1 ] ; then
581      echo "IGCM_debug_PopStack \"IGCM_FlushRebuild\" " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
582      echo "}                                         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
583    fi
584    if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
585      IGCM_sys_Put_Dir REBUILD_${PeriodDateBegin} ${REBUILD_DIR}
586    else
587      IGCM_sys_Mv      REBUILD_${PeriodDateBegin} ${REBUILD_DIR}
588    fi
589  fi
590  #
591  if [ ${RebuildFrequency} = true ] ; then
592    if ( [ X${config_Post_RebuildFromArchive} = Xtrue ] ) ; then
593      IGCM_debug_Print 1 "REBUILD POST-PROCESSING FROM ARCHIVE"
594      echo
595      #
596      script=rebuild_fromArchive
597    else
598      IGCM_debug_Print 1 "REBUILD POST-PROCESSING FROM WORKDIR"
599      echo
600      #
601      script=rebuild_fromWorkdir
602    fi
603    #
604    Script_Post_Output=${script}.${PeriodDateEnd}
605    #
606    listVarEnv="DEBUG_debug,MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,POST_DIR,MASTER,RebuildFromArchive,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_SBG"
607    IGCM_sys_RshPost <<-EOF
608      export DEBUG_debug=${DEBUG_debug}
609      export MODIPSL=${MODIPSL}
610      export libIGCM_SX=${libIGCM}
611      export libIGCM=${libIGCM_POST}
612      export SUBMIT_DIR=${SUBMIT_DIR}
613      export REBUILD_DIR=${REBUILD_DIR}
614      export POST_DIR=${POST_DIR}
615      export MASTER=${MASTER}
616      export RebuildFromArchive=${config_Post_RebuildFromArchive}
617      export DateBegin=${DateBegin}
618      export PeriodDateBegin=${PeriodDateBegin}
619      export PeriodDateEnd=${PeriodDateEnd}
620      export NbRebuildDir=${NbRebuildDir}
621      export StandAlone=false
622      export RESOL_ATM=${RESOL_ATM}
623      export RESOL_OCE=${RESOL_OCE}
624      export RESOL_ICE=${RESOL_ICE}
625      export RESOL_MBG=${RESOL_MBG}
626      export RESOL_SRF=${RESOL_SRF}
627      export RESOL_SBG=${RESOL_SBG}
628      export listVarEnv=${listVarEnv}
629      export Script_Post_Output=${Script_Post_Output}
630      . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
631      . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
632      IGCM_sys_MkdirWork ${POST_DIR}
633      IGCM_debug_Verif_Exit_Post
634      IGCM_sys_QsubPost ${script}
635EOF
636  fi
637  IGCM_debug_PopStack "IGCM_post_Submit"
638}
639
640#===================================
641function IGCM_post_CheckModuloFrequency
642{
643  IGCM_debug_PushStack "IGCM_post_CheckModuloFrequency" $*
644
645  # Used by IGCM_config_Check
646  # from 2 libIGCM compatible frequency (*Y, *M, *D, *y, *m, *d)
647  # Issue an exit instruction IGCM_debug_Exit if there modulo is not zero
648  # Input parameter are the name of the variable, not the frequency value itself
649  # example
650  # IGCM_post_ModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength
651
652  typeset MasterName SlaveName MasterFrequency SlaveFrequency PeriodMasterYear PeriodMasterMonth PeriodMasterDay PeriodSlaveYear PeriodSlaveMonth PeriodSlaveDay
653
654  # Get the name of the variable
655  MasterName=$1
656  SlaveName=$2
657  # Get the value the above name points to
658  MasterFrequency=$( eval echo \${${1}} )
659  SlaveFrequency=$( eval echo \${${2}} )
660
661  IGCM_debug_Print 2 "IGCM_post_CheckModuloFrequency : Master=${MasterFrequency} Slave=${SlaveFrequency}"
662
663  case ${MasterFrequency} in
664  *y|*Y)
665    PeriodMasterYear=$( echo ${MasterFrequency} | sed -e "s/[yY]//" )
666    case ${SlaveFrequency} in
667    *Y|*y)
668      PeriodSlaveYear=$( echo ${SlaveFrequency} | sed -e "s/[yY]//" )
669      if ( [ ${PeriodSlaveYear} -gt ${PeriodMasterYear} ] || \
670      [ $(( ${PeriodMasterYear} % ${PeriodSlaveYear} )) -ne 0 ] )then
671        IGCM_debug_Print 1 "${SlaveName} frequency ${SlaveFrequency} not compatbile with"
672        IGCM_debug_Print 1 "${MasterName} frequency : ${MasterFrequency}"
673        IGCM_debug_Exit "Check your frequency"
674      else
675        [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ${PeriodMasterYear} / ${PeriodSlaveYear} ))
676      fi ;;
677    *M|*m)
678      PeriodSlaveMonth=$( echo ${SlaveFrequency} | sed -e "s/[mM]//" )
679      if ( [ ${PeriodSlaveMonth} -gt $(( ${PeriodMasterYear} * 12 )) ] || \
680        [ $(( ( ${PeriodMasterYear} * 12 ) % ${PeriodSlaveMonth} )) -ne 0 ] ) ; then
681        IGCM_debug_Print 1 "${SlaveName} frequency ${SlaveFrequency} not compatbile with"
682        IGCM_debug_Print 1 "${MasterName} frequency : ${MasterFrequency}"
683        IGCM_debug_Exit "Check your frequency"
684      else
685        [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ( 12 * ${PeriodMasterYear} ) / ${PeriodSlaveMonth} ))
686      fi ;;
687    *D|*d)
688      PeriodSlaveDay=$( echo ${SlaveFrequency} | sed -e "s/[dD]//" )
689      NbDays=$( IGCM_date_DaysInYear ${year} )
690      if [ ${config_UserChoices_CalendarType} = 360d ] || [ ${config_UserChoices_CalendarType} = noleap ] ; then
691        if ( [ ${PeriodSlaveDay} -gt $(( ${PeriodMasterYear} * ${NbDays} )) ] || \
692          [ $(( ( ${PeriodMasterYear} * ${NbDays} ) % ${PeriodSlaveDay} )) -ne 0 ] ; ) then
693          IGCM_debug_Print 1 "${SlaveName} frequency ${SlaveFrequency} not compatbile with"
694          IGCM_debug_Print 1 "${MasterName} frequency : ${MasterFrequency}"
695          IGCM_debug_Exit "Check your frequency"
696        fi
697      else
698        IGCM_debug_Print 1 "For ${MasterName} with leap calendar:"
699        IGCM_debug_Print 1 "We have a daily ${SlaveName} frequency and ${MasterName}=${MasterFrequency}"
700        IGCM_debug_Print 1 "No post-treatment. Case not properly handle at this moment by libIGCM. Sorry"
701        IGCM_debug_Exit    "Check your frequency ${MasterName} and choose a daily frequency for this one too."
702      fi ;;
703    esac ;;
704  *M|*m)
705    PeriodMasterMonth=$( echo ${MasterFrequency} | sed -e "s/[mM]//" )
706    case ${SlaveFrequency} in
707    *Y|*y)
708      PeriodSlaveYear=$( echo ${SlaveFrequency} | sed -e "s/[yY]//" )
709      if ( [ ${PeriodMasterMonth} -gt $(( ${PeriodSlaveYear} * 12 )) ] || \
710        [ $(( ${PeriodMasterMonth} % ( ${PeriodSlaveYear} * 12 ) )) -ne 0 ] ) ; then
711        IGCM_debug_Print 1 "${SlaveName} frequency ${SlaveFrequency} not compatbile with"
712        IGCM_debug_Print 1 "${MasterName} frequency : ${MasterFrequency}"
713        IGCM_debug_Exit "Check your frequency"
714      else
715        [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ${PeriodMasterMonth} / ( 12 * ${PeriodSlaveYear} ) ))
716      fi ;;
717    *M|*m)
718      PeriodSlaveMonth=$( echo ${SlaveFrequency} | sed -e "s/[mM]//" )
719      if ( [ ${PeriodSlaveMonth} -gt ${PeriodMasterMonth} ] || \
720        [ $(( ${PeriodMasterMonth} % ${PeriodSlaveMonth} )) -ne 0 ] ) ;  then         
721        IGCM_debug_Print 1 "${SlaveName} frequency ${SlaveFrequency} not compatbile with"
722        IGCM_debug_Print 1 "${MasterName} frequency : ${MasterFrequency}"
723        IGCM_debug_Exit "Check your frequency"
724      else
725        [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ${PeriodMasterMonth} / ${PeriodSlaveMonth} ))
726      fi ;;
727    *D|*d)
728      IGCM_debug_Print 1 "${SlaveName} frequency ${SlaveFrequency} not compatbile with"
729      IGCM_debug_Print 1 "${MasterName} frequency : ${MasterFrequency}"
730      IGCM_debug_Exit "Check your frequency" ;;
731    esac ;;
732  *D|*d)
733    PeriodMasterDay=$( echo ${MasterFrequency} | sed -e "s/[dD]//" )
734    case ${SlaveFrequency} in
735    *Y|*y)
736      IGCM_debug_Print 1 "${SlaveName} frequency ${SlaveFrequency} not compatbile with"
737      IGCM_debug_Print 1 "${MasterName} frequency ${MasterFrequency}"
738      IGCM_debug_Exit "Check your frequency" ;;
739    *M|*m)
740      IGCM_debug_Print 1 "${SlaveName} frequency ${SlaveFrequency} not compatbile with"
741      IGCM_debug_Print 1 "${MasterName} frequency ${MasterFrequency}"
742      IGCM_debug_Exit "Check your frequency" ;;
743    *D|*d)
744      PeriodSlaveDay=$( echo ${SlaveFrequency} | sed -e "s/[dD]//" )
745      if ( [ ${PeriodSlaveDay} -gt ${PeriodMasterDay} ] || \
746        [ $(( ${PeriodMasterDay} % ${PeriodSlaveDay} )) -ne 0 ] ) ;  then
747        IGCM_debug_Print 1 "${SlaveName} frequency ${SlaveFrequency} not compatbile with"
748        IGCM_debug_Print 1 "${MasterName} frequency : ${MasterFrequency}"
749        IGCM_debug_Exit "Check your frequency"
750      else
751        [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ${PeriodMasterDay} / ${PeriodSlaveDay} ))
752      fi ;;
753    esac ;;
754  NONE|none)
755    ;;
756  *)
757    IGCM_debug_Print 1 "KeyWord ${MasterFrequency} not allowed for ${MasterName} in config.card"
758    IGCM_debug_Exit "Check your ${MasterName} in config.card" ;;
759  esac
760
761  IGCM_debug_PopStack "IGCM_post_CheckModuloFrequency"
762}
763
764#===================================
765function IGCM_post_ModuloRuntimeFrequency
766{
767  IGCM_debug_PushStack "IGCM_post_ModuloRuntimeFrequency" $*
768
769  # Used by IGCM_post_Configure
770  # - from libIGCM (config_UserChoices_PeriodLength frequency * CumulPeriod) and
771  # - post-processing compatible frequency (*Y, *M, *D, *y, *m, *d)
772  # --> turn on post-processing submission when their modulo is zero
773  # Input parameter are the name of the variable, not the frequency value itself
774  # example
775  # IGCM_post_ModuloRuntimeFrequency config_Post_SeasonalFrequency config_UserChoices_PeriodLength
776
777  typeset MasterName SlaveName MasterFrequency SlaveFrequency PeriodMasterYear PeriodMasterMonth PeriodMasterDay PeriodSlaveYear PeriodSlaveMonth PeriodSlaveDay
778
779  # Get the name of the variable
780  MasterName=$1
781  SlaveName=$2
782  # Get the value the above name points to
783  eval MasterFrequency=\${${1}}
784  eval SlaveFrequency=\${${2}}
785
786  echo
787  IGCM_debug_Print 2 "IGCM_post_ModuloRuntimeFrequency : Master=${MasterFrequency} Slave=${SlaveFrequency} CumulPeriod=${CumulPeriod}"
788
789  case ${MasterFrequency} in
790  *y|*Y)
791    PeriodMasterYear=$( echo ${MasterFrequency} | sed -e "s/[yY]//" )
792    case ${SlaveFrequency} in
793    *Y|*y)
794      PeriodSlaveYear=$( echo ${SlaveFrequency} | sed -e "s/[yY]//" )
795      if [ $(( ( ${CumulPeriod} * ${PeriodSlaveYear} - ${PeriodOffset} ) % ${PeriodMasterYear} )) -eq 0 ] ;  then
796        if [ $(( ${CumulPeriod} * ${PeriodSlaveYear} - ${PeriodOffset} )) -ne 0 ] ; then
797          eval ${post_freq}=true ; POST=true
798          [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ${PeriodMasterYear} / ${PeriodSlaveYear} ))
799        fi
800      fi;;
801    *M|*m)
802      PeriodSlaveMonth=$( echo ${SlaveFrequency} | sed -e "s/[mM]//" )
803      if [ $(( ( ${CumulPeriod} * ${PeriodSlaveMonth} - ${PeriodOffset} * 12 ) % ( ${PeriodMasterYear} * 12 ) )) -eq 0 ] ; then
804        if [ $(( ${CumulPeriod} * ${PeriodSlaveMonth} - ${PeriodOffset} * 12 )) -ne 0 ] ; then
805          eval ${post_freq}=true ; POST=true
806          [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ( 12 * ${PeriodMasterYear} ) / ${PeriodSlaveMonth} ))
807        fi
808      fi;;
809    *D|*d)
810      PeriodSlaveDay=$( echo ${SlaveFrequency} | sed -e "s/[dD]//" )
811      NbDays=$( IGCM_date_DaysInYear ${year} )
812      if [ $(( ( ${CumulPeriod} - ( ${PeriodOffset} * ${NbDays} / ${PeriodSlaveDay} ) ) % ( ${NbDays} * ${PeriodMasterYear} / ${PeriodSlaveDay} ) )) -eq 0 ] ; then
813        if [ $(( ${CumulPeriod} - ( ${PeriodOffset} * ${NbDays} / ${PeriodSlaveDay} ) )) -ne 0 ] ; then
814          eval ${post_freq}=true ; POST=true
815          [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ( ${NbDays} * ${PeriodMasterYear} ) / ${PeriodSlaveDay} ))
816        fi
817      fi;;
818    esac ;;
819  *M|*m)
820    PeriodMasterMonth=$( echo ${MasterFrequency} | sed -e "s/[mM]//" )
821    case ${SlaveFrequency} in
822    *Y|*y)
823      PeriodSlaveYear=$( echo ${SlaveFrequency} | sed -e "s/[yY]//" )
824      if [ $(( ( ${CumulPeriod} * ${PeriodSlaveYear} * 12 - ${PeriodOffset} ) % ( ${PeriodMasterMonth} ) )) -eq 0 ] ; then
825        if [ $(( ${CumulPeriod} * ${PeriodSlaveYear} * 12 - ${PeriodOffset} )) -ne 0 ] ; then
826          eval ${post_freq}=true ; POST=true
827          [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ${PeriodMasterMonth} / ( 12 * ${PeriodSlaveYear} ) ))
828        fi
829      fi;;
830    *M|*m)
831      PeriodSlaveMonth=$( echo ${SlaveFrequency} | sed -e "s/[mM]//" )
832      if [ $(( ( ${CumulPeriod} * ${PeriodSlaveMonth} - ${PeriodOffset} ) % ${PeriodMasterMonth} )) -eq 0 ] ;  then
833        if [ $(( ${CumulPeriod} * ${PeriodSlaveMonth} -  ${PeriodOffset} )) -ne 0 ] ; then
834          eval ${post_freq}=true ; POST=true
835          [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ${PeriodMasterMonth} / ${PeriodSlaveMonth} ))
836        fi
837      fi;;
838    *D|*d)
839      IGCM_debug_Print 1 "PeriodLength frequency ${SlaveFrequency} not compatbile with"
840      IGCM_debug_Print 1 "${flag_post} frequency : ${MasterFrequency} " ;;
841    esac ;;
842  *D|*d)
843    PeriodMasterDay=$( echo ${MasterFrequency} | sed -e "s/[dD]//" )
844    case ${SlaveFrequency} in
845    *Y|*y)
846      IGCM_debug_Print 1 "PeriodLength frequency ${SlaveFrequency} not compatbile with"
847      IGCM_debug_Print 1 "${flag_post} frequency : ${MasterFrequency} " ;;
848    *M|*m)
849      IGCM_debug_Print 1 "PeriodLength frequency ${SlaveFrequency} not compatbile with"
850      IGCM_debug_Print 1 "${flag_post} frequency : ${MasterFrequency} " ;;
851    *D|*d)
852      PeriodSlaveDay=$( echo ${SlaveFrequency} | sed -e "s/[dD]//" )
853      if [ $(( ( ${CumulPeriod} * ${PeriodSlaveDay} - ${PeriodOffset} ) % ${PeriodMasterDay} )) -eq 0 ] ;  then
854        if [ $(( ${CumulPeriod} * ${PeriodSlaveDay} - ${PeriodOffset} )) -ne 0 ] ; then
855          eval ${post_freq}=true ; POST=true
856          [ X${3} = XNbPeriodPerFrequency ] && NbPeriodPerFrequency=$(( ${PeriodMasterDay} / ${PeriodSlaveDay} ))
857        fi
858      fi;;
859    esac ;;
860  NONE|none)
861    ;;
862  *)
863    IGCM_debug_Print 1 "KeyWord not allowed for ${post_freq} in config.card"
864    ;;
865  esac
866
867  IGCM_debug_PopStack "IGCM_post_ModuloRuntimeFrequency"
868}
Note: See TracBrowser for help on using the repository browser.