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

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

SD : - 2 options for asynchronous rebuild

  • from SCRATCHDIR (very good for platine, the same for mercure)
  • from Archive (good for platine, good for mercure)
  • 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: 16.1 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 "RebuildFrequency frequency : ${config_Post_RebuildFrequency}"
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                            fi
57                        else
58                            IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
59                            IGCM_debug_Print 3 "RebuildFrequency frequency : ${config_Post_RebuildFrequency}"
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 "RebuildFrequency frequency : ${config_Post_RebuildFrequency}"
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 "RebuildFrequency frequency : ${config_Post_RebuildFrequency}"
107                        fi ;;
108                    *D|*d)
109                        IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
110                        IGCM_debug_Print 3 "RebuildFrequency frequency : ${config_Post_RebuildFrequency}" ;;
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                                            fi
218                                        else
219                                            IGCM_debug_Print 3 "PeriodLength frequency ${config_UserChoices_PeriodLength} not compatbile with"
220                                            IGCM_debug_Print 3 "${flag_post} frequency : ${config_Post_post_freq} "
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
286    IGCM_debug_Print 1 "POST-TREATEMENT flag value : ${POST}"
287    #
288    if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then
289        TimeSeriesFrequency=true
290    fi
291    #
292    IGCM_post_Submit
293
294    IGCM_debug_PopStack "IGCM_post_Initialize"
295}
296
297function IGCM_post_Submit
298{
299    IGCM_debug_PushStack "IGCM_post_Submit"
300
301    POST_DIR=${R_OUT_POST}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
302
303    if [ ${POST} = true ]; then
304        echo
305        IGCM_debug_Print 1 "IGCM_post_Submit :"
306        echo
307        IGCM_debug_Print 1 "POST_DIR = ${POST_DIR}"
308    fi
309
310    #============ TIME SERIES POST-TREATMENT ===========#
311    if [ ${TimeSeriesFrequency} = true ] ; then
312
313        IGCM_debug_Print 2 "TIME SERIES POST-TREATMENT :"
314        echo
315        #
316        typeset listVarEnv
317        listVarEnv="MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
318
319        if [ ${RebuildFrequency} = true ] ; then
320            #
321            echo IGCM_sys_QsubPost create_ts >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
322            #
323        else
324            #
325            IGCM_sys_RshPost <<-EOF
326            export MODIPSL=${MODIPSL}
327            export libIGCM_SX=${libIGCM}
328            export libIGCM=${libIGCM_POST}
329            export SUBMIT_DIR=${SUBMIT_DIR}
330            export POST_DIR=${POST_DIR}
331            export DateBegin=${DateBegin}
332            export PeriodDateEnd=${PeriodDateEnd}
333            export StandAlone=false
334            export RESOL_ATM=${RESOL_ATM}
335            export RESOL_OCE=${RESOL_OCE}
336            export RESOL_ICE=${RESOL_ICE}
337            export RESOL_SRF=${RESOL_SRF}
338            export listVarEnv=${listVarEnv}
339            . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
340            . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
341            IGCM_sys_MkdirWork ${POST_DIR}
342            IGCM_debug_Verif_Exit
343            IGCM_sys_QsubPost create_ts
344EOF
345            #
346        fi
347    fi
348
349    #=============  SEASONAL POST-TREATMENT ============#
350    if [ ${SeasonalFrequency} = true ] ; then
351        #
352        IGCM_debug_Print 2 "SEASONNAL POST-TREATMENT :"
353        echo
354        #
355        typeset listVarEnv
356        listVarEnv="MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
357
358        if [ ${RebuildFrequency} = true ] ; then
359            #
360            echo IGCM_sys_QsubPost create_se >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
361            #
362        else
363            #
364            IGCM_sys_RshPost <<-EOF
365            export MODIPSL=${MODIPSL}
366            export libIGCM_SX=${libIGCM}
367            export libIGCM=${libIGCM_POST}
368            export SUBMIT_DIR=${SUBMIT_DIR}
369            export POST_DIR=${POST_DIR}
370            export DateBegin=${DateBegin}
371            export PeriodDateEnd=${PeriodDateEnd}
372            export StandAlone=false
373            export RESOL_ATM=${RESOL_ATM}
374            export RESOL_OCE=${RESOL_OCE}
375            export RESOL_ICE=${RESOL_ICE}
376            export RESOL_SRF=${RESOL_SRF}
377            export listVarEnv=${listVarEnv}
378            . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
379            . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
380            IGCM_sys_MkdirWork ${POST_DIR}
381            IGCM_debug_Verif_Exit
382            IGCM_sys_QsubPost create_se
383EOF
384        #
385        fi
386    fi
387
388    #============== REBUILD POST-TREATMENT =============#
389
390    if ( [ ${config_Post_RebuildFromArchive} = true ] && [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
391        IGCM_sys_Put_Dir REBUILD_${PeriodDateBegin} ${REBUILD_DIR}
392    fi
393    #
394    if [ ${RebuildFrequency} = true ] ; then
395        #
396        IGCM_debug_Print 2 "REBUILD POST-TREATMENT :"
397        echo
398        #
399        typeset listVarEnv
400        listVarEnv="MODIPSL,libIGCM,libIGCM_SX,SUBMIT_DIR,REBUILD_DIR,RebuildFromArchive,POST_DIR,DateBegin,PeriodDateBegin,PeriodDateEnd,NbRebuildDir,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
401        IGCM_sys_RshPost <<-EOF
402        export MODIPSL=${MODIPSL}
403        export libIGCM_SX=${libIGCM}
404        export libIGCM=${libIGCM_POST}
405        export SUBMIT_DIR=${SUBMIT_DIR}
406        export RebuildFromArchive=${config_Post_RebuildFromArchive}
407        export REBUILD_DIR=${REBUILD_DIR}
408        export POST_DIR=${POST_DIR}
409        export DateBegin=${DateBegin}
410        export PeriodDateBegin=${PeriodDateBegin}
411        export PeriodDateEnd=${PeriodDateEnd}
412        export NbRebuildDir=${NbRebuildDir}
413        export StandAlone=false
414        export RESOL_ATM=${RESOL_ATM}
415        export RESOL_OCE=${RESOL_OCE}
416        export RESOL_ICE=${RESOL_ICE}
417        export RESOL_SRF=${RESOL_SRF}
418        export listVarEnv=${listVarEnv}
419        . ${libIGCM_POST}/libIGCM_debug/libIGCM_debug.ksh
420        . ${libIGCM_POST}/libIGCM_sys/libIGCM_sys.ksh
421        IGCM_sys_MkdirWork ${POST_DIR}
422        IGCM_debug_Verif_Exit
423        IGCM_sys_QsubPost rebuild
424EOF
425    fi
426
427    IGCM_debug_PopStack "IGCM_post_Submit"
428}
Note: See TracBrowser for help on using the repository browser.