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

Last change on this file since 23 was 22, checked in by sdipsl, 16 years ago

SD : - Add the so called "rebuild déporté" or asynchronous rebuild

  • EXPERIMENTAL, work at CCRT only (for now mercure+platine)
  • Add IDRIS when new post-process machine is available
  • On SX one needs to run on $SCRATCHDIR not $LOCALTMPDIR
  • To keep it disable : RebuildFrequency?=NONE in config.card
  • To enable it : RebuildFrequency?=2Y in config.card
  • To enable it on SX8R : RUN_DIR_PATH=$SCRATCHDIR in AA_job
  • Need testing to tune empirically dependance between RebuildFrequency? and other post-processing frequency
  • Need more tests to prevent user choices' inconsitency
  • 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 Date Author Revision
File size: 15.7 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil
5# Contact: Sebastien.Denvil@ipsl.jussieu.fr
6# $Date$
7# $Author$
8# $Revision$
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11# History:
12# Modification:
13#
14#**************************************************************
15
16#=======================================================================
17
18function IGCM_post_Configure
19{
20    IGCM_debug_PushStack "IGCM_post_Configure"
21
22    # Debug Print :
23    echo
24    IGCM_debug_Print 1 "IGCM_post_Configure :"
25    echo
26
27    typeset NbDays PeriodEndJul PostEndJul PeriodPost
28    RebuildFrequency=false
29
30    if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
31
32        IGCM_debug_Print 1 "Asynchronous rebuild has been activated."
33        echo
34
35        case ${config_Post_RebuildFrequency} in
36            *y|*Y)
37                PeriodYear=$( echo ${config_Post_RebuildFrequency} | sed -e "s/[yY]//" )
38                case ${config_UserChoices_PeriodLength} in
39                    *Y|*y)
40                        PeriodPost=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[yY]//" )
41                        if [ ${PeriodPost} -le ${PeriodYear} ] ; then
42                            if [ $( expr $(( ${CumulPeriod} * ${PeriodPost} )) % ${PeriodYear}  ) -eq 0 ] ;  then
43                                RebuildFrequency=true
44                                NbRebuildDir=$( expr ${PeriodYear} / ${PeriodPost} )
45                            fi
46                        else
47                            IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
48                            IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} "
49                        fi ;;
50                    *M|*m)
51                        PeriodPost=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[mM]//" )
52                        if [ ${PeriodPost} -le $(( ${PeriodYear} * 12 )) ] ; then
53                            if [ $( expr $(( ${CumulPeriod} * ${PeriodPost} )) % $(( ${PeriodYear} * 12 )) ) -eq 0 ] ; then
54                                RebuildFrequency=true
55                                NbRebuildDir=$( expr $(( 12 * ${PeriodYear} )) / ${PeriodPost} )
56                            else
57                                IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
58                                IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} "
59                            fi
60                        fi ;;
61                    *D|*d)
62                        PeriodPost=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[dD]//" )
63                        NbDays=$( IGCM_date_DaysInYear ${year} )
64                        if [ ${config_UserChoices_CalendarType} = 360d ] || [ ${config_UserChoices_CalendarType} = noleap ] ; then
65                            if [ ${PeriodPost} -le $(( ${PeriodYear} * ${NbDays} )) ] ; then
66                                if [ $( expr ${CumulPeriod} % $( expr \( ${NbDays} \* ${PeriodYear} \/ ${PeriodPost} \) ) ) -eq 0 ] ; then
67                                    RebuildFrequency=true
68                                    NbRebuildDir=$( expr $(( ${NbDays} * ${PeriodYear} )) / ${PeriodPost} )
69                                fi
70                            else
71                                IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
72                                IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} "
73                            fi
74                        else
75#                           if [ ${PeriodYear} -eq 1 ] ; then
76#                               PeriodEndJul=$( IGCM_date_ConvertGregorianDateToJulian ${PeriodDateEnd} )
77#                               PostEndJul=${year}${NbDays}
78#                               #echo "PeriodYear=${PeriodYear} NbDays=${NbDays}"
79#                               #echo "PeriodEndJul=${PeriodEndJul} PostEndJul=${PostEndJul}"
80#                               if [ ${PostEndJul} -eq ${PeriodEndJul} ] ; then
81#                                   RebuildFrequency=true
82#                                   NbRebuildDir=$( expr ${NbDays} / ${PeriodPost} )
83#                               fi
84#                           else
85                            IGCM_debug_Print 3 "For RebuildFrequency with leap calendar:"
86                            IGCM_debug_Print 3 "We have a daily PeriodLength frequency and RebuildFrequency=${PeriodYear}Y."
87                            IGCM_debug_Print 3 "No post-treatment. Case not properly handle at this moment."
88#                           fi
89                        fi;;
90                esac ;;
91            *M|*m)
92                PeriodMonth=$( echo ${config_Post_RebuildFrequency} | sed -e "s/[mM]//" )
93                case ${config_UserChoices_PeriodLength} in
94                    *Y|*y)
95                        IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
96                        IGCM_debug_Print 3 "RebuildFrequency frequency ${config_Post_RebuildFrequency}" ;;
97                    *M|*m)
98                        PeriodPost=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[mM]//" )
99                        if [ ${PeriodPost} -le ${PeriodMonth} ] ; then
100                            if [ $( expr $(( ${CumulPeriod} * ${PeriodPost} )) % ${PeriodMonth}  ) -eq 0 ] ;  then
101                                RebuildFrequency=true
102                                NbRebuildDir=$( expr ${PeriodMonth} / ${PeriodPost} )
103                            fi
104                        else
105                            IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
106                            IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} "
107                        fi ;;
108                    *D|*d)
109                        IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
110                        IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} " ;;
111                esac
112                ;;
113            NONE|none)
114                ;;
115            *)
116                IGCM_debug_Print 3 "KeyWord not allowed for RebuildFrequency in config.card"
117                ;;
118        esac
119    else
120        #
121        IGCM_debug_Print 1 "Asynchronous rebuild has not been activated"
122        IGCM_debug_Print 1 "Proceed with standard post-treatment pathway"
123        echo
124        #
125    fi
126
127    IGCM_debug_Print 1 "RebuildFrequency flag value : ${RebuildFrequency}"
128    IGCM_post_Initialize
129
130    IGCM_debug_PopStack "IGCM_post_Configure"
131}
132
133function IGCM_post_Initialize
134{
135    IGCM_debug_PushStack "IGCM_post_Initialize"
136
137    # Debug Print :
138    echo
139    IGCM_debug_Print 1 "IGCM_post_Initialize :"
140    echo
141
142    typeset POST NbDays PeriodEndJul PostEndJul LengthDays
143    POST=false
144
145    # READ TIME SERIES OR SEASONAL FREQUENCY
146    # AND TURN ON THE FLAG WHEN MODULO IS ZERO
147    for post_freq in TimeSeriesFrequency SeasonalFrequency ; do
148        #
149        # Initialize
150        #
151        eval ${post_freq}=false
152        #
153        # Define the variable ${config_Post_${post_freq}}
154        # who contains frequency for specific post-treatment
155        #
156        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${post_freq}
157        #
158        # Extract frequency from above variable
159        #
160        config_Post_post_freq=$( eval echo \${config_Post_${post_freq}} )
161        #
162        if ( [ X${config_Post_post_freq} = X${NULL_STR} ] || [ X${config_Post_post_freq} = XNONE ] ) ; then
163            #
164            continue
165            #
166        fi
167        #
168        # For each componant select determine which files need post-processing
169        #
170        for comp in ${config_ListOfComponents[*]} ; do
171            #
172            #echo "-----"
173            eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
174            ListFilesName=${compname}_OutputFiles_List
175            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
176            #
177            if [ X${FileName0} != X${NULL_STR} ] ; then
178                #
179                #IGCM_debug_Print 1 "Component      : ${compname}"
180                #
181                # INITIALISATION
182                #
183                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
184                typeset i=0
185                #
186                until [ $i -eq $NbFiles ]; do
187                    #
188                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
189                    eval file_in=${file_in_}
190                    let $(( i_ = i+2 ))
191                    eval flag_post_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
192                    eval flag_post=${flag_post_}
193                    #
194                    if [ X${flag_post} != XNONE ] ; then
195                    #
196                        case ${config_Post_post_freq} in
197                            *y|*Y)
198                                PeriodYear=$( echo ${config_Post_post_freq} | sed -e "s/[yY]//" )
199                                case ${config_UserChoices_PeriodLength} in
200                                    *Y|*y)
201                                        PeriodPost=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[yY]//" )
202                                        if [ ${PeriodPost} -le ${PeriodYear} ] ; then
203                                            if [ $( expr $(( ${CumulPeriod} * ${PeriodPost} )) % ${PeriodYear}  ) -eq 0 ] ;  then
204                                                eval ${post_freq}=true
205                                                POST=true
206                                            fi
207                                        else
208                                            IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
209                                            IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} "
210                                        fi ;;
211                                    *M|*m)
212                                        PeriodPost=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[mM]//" )
213                                        if [ ${PeriodPost} -le $(( ${PeriodYear} * 12 )) ] ; then
214                                            if [ $( expr $(( ${CumulPeriod} * ${PeriodPost} )) % $(( ${PeriodYear} * 12 )) ) -eq 0 ] ; then
215                                                eval ${post_freq}=true
216                                                POST=true
217                                                else
218                                                IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
219                                                IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} "
220                                            fi
221                                        fi ;;
222                                    *D|*d)
223                                        PeriodPost=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[dD]//" )
224                                        NbDays=$( IGCM_date_DaysInYear ${year} )
225                                        if [ ${config_UserChoices_CalendarType} = 360d ] | [ ${config_UserChoices_CalendarType} = noleap ] ; then
226                                            if [ ${PeriodPost} -le $(( ${PeriodYear} * ${NbDays} )) ] ; then
227                                                if [ $( expr ${CumulPeriod} % $( expr \( ${NbDays} \* ${PeriodYear} \/ ${PeriodPost} \) ) ) -eq 0 ] ; then
228                                                    eval ${post_freq}=true
229                                                    POST=true
230                                                fi
231                                            else
232                                                IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
233                                                IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} "
234                                            fi
235                                        else
236#                                           if [ ${PeriodYear} -eq 1 ] ; then
237#                                               PeriodEndJul=$( IGCM_date_ConvertGregorianDateToJulian ${PeriodDateEnd} )
238#                                               PostEndJul=${year}${NbDays}
239#                                                #echo "PeriodYear=${PeriodYear} NbDays=${NbDays}"
240#                                               #echo PeriodEndJul=${PeriodEndJul} PostEndJul=${PostEndJul}"
241#                                               if [ ${PostEndJul} -le ${PeriodEndJul} ] ; then
242#                                                   eval ${post_freq}=true
243#                                                   POST=true
244#                                               fi
245#                                           else
246                                            IGCM_debug_Print 3 "For ${post_freq} with leap calendar, for ${comp} and ${file_in} :"
247                                            IGCM_debug_Print 3 "We have a daily PeriodLength frequency and RebuildFrequency=${PeriodYear}Y."
248                                            IGCM_debug_Print 3 "No post-treatment. Case not properly handle at this moment."
249#                                           fi
250                                        fi;;
251                                esac ;;
252                            *M|*m)
253                                PeriodMonth=$( echo ${config_Post_RebuildFrequency} | sed -e "s/[mM]//" )
254                                case ${config_UserChoices_PeriodLength} in
255                                    *Y|*y)
256                                        IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
257                                        IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} " ;;
258                                    *M|*m)
259                                        PeriodPost=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[mM]//" )
260                                        if [ ${PeriodPost} -le ${PeriodMonth} ] ; then
261                                            if [ $( expr $(( ${CumulPeriod} * ${PeriodPost} )) % ${PeriodMonth}  ) -eq 0 ] ;  then
262                                                eval ${post_freq}=true
263                                                POST=true
264                                            fi
265                                        else
266                                            IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
267                                            IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} "
268                                        fi;;
269                                    *D|*d)
270                                        IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
271                                        IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} " ;;
272                                esac ;;
273                            NONE|none)
274                                ;;
275                            *)
276                                IGCM_debug_Print 3 "KeyWord not allowed for ${post_freq} in config.card"
277                                ;;
278                        esac
279                    fi
280                    let $(( i=i+3 ))
281                done
282            fi
283        done
284    done
285    IGCM_debug_Print 1 "POST-TREATEMENT flag value : ${POST}"
286    [ ${POST} = true ] && IGCM_post_Submit
287
288    IGCM_debug_PopStack "IGCM_post_Initialize"
289}
290
291function IGCM_post_Submit
292{
293    IGCM_debug_PushStack "IGCM_post_Submit"
294
295    # Debug Print :
296    echo
297    IGCM_debug_Print 1 "IGCM_post_Submit :"
298    echo
299
300    POST_DIR=${R_OUT_POST}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
301    IGCM_debug_Print 1 "POST_DIR = ${POST_DIR}"
302
303    #============ TIME SERIES POST-TREATMENT ===========#
304    if [ ${TimeSeriesFrequency} = true ] ; then
305
306        IGCM_debug_Print 2 "TIME SERIES POST-TREATMENT :"
307        echo
308        #
309        typeset listVarEnv
310        listVarEnv="MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
311
312        if [ ${RebuildFrequency} = true ] ; then
313            #
314            echo IGCM_sys_QsubPost create_ts >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
315            #
316        else
317            #
318            IGCM_sys_RshPost <<-EOF
319            export MODIPSL=${MODIPSL}
320            export libIGCM_SX=${libIGCM}
321            export libIGCM=${libIGCM_POST}
322            export SUBMIT_DIR=${SUBMIT_DIR}
323            export POST_DIR=${POST_DIR}
324            export DateBegin=${DateBegin}
325            export PeriodDateEnd=${PeriodDateEnd}
326            export StandAlone=false
327            export RESOL_ATM=${RESOL_ATM}
328            export RESOL_OCE=${RESOL_OCE}
329            export RESOL_ICE=${RESOL_ICE}
330            export RESOL_SRF=${RESOL_SRF}
331            export listVarEnv=${listVarEnv}
332            . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
333            . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
334            IGCM_sys_MkdirWork ${POST_DIR}
335            IGCM_debug_Verif_Exit
336            IGCM_sys_QsubPost create_ts
337EOF
338            #
339        fi
340    fi
341
342    #=============  SEASONAL POST-TREATMENT ============#
343    if [ ${SeasonalFrequency} = true ] ; then
344        #
345        IGCM_debug_Print 2 "SEASONNAL POST-TREATMENT :"
346        echo
347        #
348        typeset listVarEnv
349        listVarEnv="MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
350
351        if [ ${RebuildFrequency} = true ] ; then
352            #
353            echo IGCM_sys_QsubPost create_se >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
354            #
355        else
356            #
357            IGCM_sys_RshPost <<-EOF
358            export MODIPSL=${MODIPSL}
359            export libIGCM_SX=${libIGCM}
360            export libIGCM=${libIGCM_POST}
361            export SUBMIT_DIR=${SUBMIT_DIR}
362            export POST_DIR=${POST_DIR}
363            export DateBegin=${DateBegin}
364            export PeriodDateEnd=${PeriodDateEnd}
365            export StandAlone=false
366            export RESOL_ATM=${RESOL_ATM}
367            export RESOL_OCE=${RESOL_OCE}
368            export RESOL_ICE=${RESOL_ICE}
369            export RESOL_SRF=${RESOL_SRF}
370            export listVarEnv=${listVarEnv}
371            . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
372            . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
373            IGCM_sys_MkdirWork ${POST_DIR}
374            IGCM_debug_Verif_Exit
375            IGCM_sys_QsubPost create_se
376EOF
377        #
378        fi
379    fi
380
381    #============== REBUILD POST-TREATMENT =============#
382    if [ ${RebuildFrequency} = true ] ; then
383        #
384        IGCM_debug_Print 2 "REBUILD POST-TREATMENT :"
385        echo
386        #
387        typeset listVarEnv
388        listVarEnv="MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,RUN_DIR,POST_DIR,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
389        IGCM_sys_RshPost <<-EOF
390        export MODIPSL=${MODIPSL}
391        export libIGCM_SX=${libIGCM}
392        export libIGCM=${libIGCM_POST}
393        export SUBMIT_DIR=${SUBMIT_DIR}
394        export RUN_DIR=${RUN_DIR}
395        export POST_DIR=${POST_DIR}
396        export DateBegin=${DateBegin}
397        export PeriodDateBegin=${PeriodDateBegin}
398        export PeriodDateEnd=${PeriodDateEnd}
399        export NbRebuildDir=${NbRebuildDir}
400        export StandAlone=false
401        export RESOL_ATM=${RESOL_ATM}
402        export RESOL_OCE=${RESOL_OCE}
403        export RESOL_ICE=${RESOL_ICE}
404        export RESOL_SRF=${RESOL_SRF}
405        export listVarEnv=${listVarEnv}
406        . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
407        . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
408        IGCM_sys_MkdirWork ${POST_DIR}
409        IGCM_debug_Verif_Exit
410        IGCM_sys_QsubPost rebuild
411EOF
412    fi
413
414    IGCM_debug_PopStack "IGCM_post_Submit"
415}
Note: See TracBrowser for help on using the repository browser.