source: trunk/libIGCM/AA_TimeSeries_Checker @ 395

Last change on this file since 395 was 392, checked in by sdipsl, 14 years ago

Step 2/3 toward CompletedFlag? auto-detection, part of ticket #40.
Tests OK. For chunck2D and chunck3D time series.

This should close ticket #42

  • Property svn:keywords set to Revision Author Date
File size: 17.1 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# Check that everything went well during time series production
15# Display a short report
16# Launch what's missing
17# For use during a run (not on the end : PeriodState=Completed), it will complete
18# all TS to last PeriodDateEnd value, give by run.card->Configuration->OldPrefix string.
19
20# Chemin vers libIGCM
21libIGCM=${libIGCM:=::modipsl::/libIGCM}
22# Attention : à changer si la machine de post-traitement n'est pas la frontale du serveur de calcul !
23#             voir précence de la variable MirrorlibIGCM dans votre couche systÚme.
24
25# Name Space of this experience
26SpaceName=${SpaceName:=PROD}
27
28# Expericence class of the run
29ExperimentName=${ExperimentName:=historical}
30
31# Name of this job
32JobName=${JobName:=v2.historical1}
33
34# répertoire courrant
35CURRENT_DIR=$( pwd )
36
37# Emplacement des cartes
38CARD_DIR=${CARD_DIR:=${CURRENT_DIR}/${ExperimentName}/${JobName}}
39
40# répertoire de stockage des sorties des create_ts
41POST_DIR=${POST_DIR:=${CARD_DIR}/OutScript}
42
43if [ ! -d ${CARD_DIR} ]; then
44    echo "No ${CARD_DIR}, we stop here"
45    exit
46fi
47
48########################################################################
49
50. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh ;
51. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh     #; IGCM_debug_Check
52. ${libIGCM}/libIGCM_card/libIGCM_card.ksh   #; IGCM_card_Check
53. ${libIGCM}/libIGCM_date/libIGCM_date.ksh   #; IGCM_date_Check
54
55########################################################################
56
57#set -vx
58
59# First of all
60IGCM_card_DefineArrayFromSection       ${CARD_DIR}/config.card UserChoices
61typeset option
62for option in ${config_UserChoices[*]} ; do
63    IGCM_card_DefineVariableFromOption ${CARD_DIR}/config.card UserChoices ${option}
64done
65
66echo
67IGCM_debug_Print 1 "DefineVariableFromOption  : config_UserChoices"
68IGCM_debug_PrintVariables 3 config_UserChoices_JobName
69#IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName
70#IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName
71IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
72IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
73IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
74
75if [ -f ${CARD_DIR}/run.card ] ; then
76    IGCM_card_DefineVariableFromOption ${CARD_DIR}/run.card Configuration OldPrefix
77    IGCM_card_DefineVariableFromOption ${CARD_DIR}/run.card Configuration PeriodState
78    IGCM_card_DefineVariableFromOption ${CARD_DIR}/run.card PostProcessing TimeSeriesCompleted
79    IGCM_debug_Print 1 "DefineVariableFromOption  : run_Configuration"
80    IGCM_debug_PrintVariables 3 run_Configuration_OldPrefix
81    IGCM_debug_PrintVariables 3 run_Configuration_PeriodState
82    IGCM_debug_Print 1 "DefineVariableFromOption  : run_PostProcessing"
83    IGCM_debug_PrintVariables 3 run_PostProcessing_TimeSeriesCompleted
84    if [ X${run_Configuration_PeriodState} != X"Completed" ] ; then
85        DateEnd=$( IGCM_date_ConvertFormatToGregorian $( echo ${run_Configuration_OldPrefix} | awk -F'_' '{print $2}' ) )
86    else
87        DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
88    fi
89    CompletedFlag=${run_PostProcessing_TimeSeriesCompleted}
90else
91    DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
92    CompletedFlag=""
93fi
94SavedCompletedFlag=${CompletedFlag}
95DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
96
97IGCM_date_GetYearMonth ${DateBegin} YearBegin MonthBegin
98IGCM_date_GetYearMonth ${DateEnd}   YearEnd   MonthEnd
99
100echo
101IGCM_debug_Print 1 "DateBegin for TimeSeries_Checker : "${DateBegin}
102IGCM_debug_Print 1 "DateEnd   for TimeSeries_Checker : "${DateEnd}
103IGCM_debug_Print 1 "CompletedFlag = "${CompletedFlag}
104echo
105
106#====================================================
107#R_SAVE : Job output directory
108if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
109    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
110    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
111    R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
112else
113    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
114    R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName}
115fi
116
117IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card ListOfComponents
118
119for comp in ${config_ListOfComponents[*]} ; do
120    # Debug Print
121    IGCM_debug_Print 1 ${comp}
122    # Define component
123    IGCM_card_DefineArrayFromOption ${CARD_DIR}/config.card ListOfComponents ${comp}
124    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
125    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
126
127    # Read libIGCM compatibility version in ${compname}.card
128    card=${CARD_DIR}/COMP/${compname}.card
129
130    # Read and Build Output File stuff
131    #IGCM_debug_Print 1 "DefineArrayFromOption  : ${compname}_OutputFiles ${card}"
132    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
133    ListFilesName=${compname}_OutputFiles_List
134    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
135    #
136    if [ X${FileName0} != X${NULL_STR} ] ; then
137        #
138        #IGCM_debug_Print 1 "Component      : ${compname}"
139        #
140        # INITIALISATION
141        #
142        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
143        i=2
144        #
145        until [ $i -ge $NbFiles ]; do
146            #
147            eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
148            #
149            if [ X${flag_post} != XNONE ] ; then
150                #
151                # First of all
152                #
153                IGCM_card_DefineArrayFromSection ${card} ${flag_post}
154                #
155                IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars
156                IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches
157                if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not found ${flag_post}" ] ; then
158                    # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob.
159                    unset ListDimension
160                    ListDimension[0]=2D
161                    ListDimension[1]=3D
162                    TimeSeries=false
163                    TimeSeries2D=false
164                    TimeSeries3D=false
165                    chunck=false
166                    iLoop=${#ListDimension[*]}
167                    j=0
168                    until [ $j -ge ${iLoop} ]; do
169                        Dimension=${ListDimension[${j}]}
170                        IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension}
171                        IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension}
172                        #
173                        # Time series WITHOUT chunk
174                        #
175                        if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
176                            if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then
177                                IGCM_debug_Print 2 "${Dimension} time series activated for ${flag_post}"
178                                eval TimeSeries${Dimension}=true
179                                chunck=false
180                            fi
181                        fi
182                        #
183                        # Time series WITH chunk
184                        #
185                        if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
186                            chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} )
187                            if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
188                                IGCM_debug_Print 2 "${Dimension} time series activated with ${chunck_size} chunck for ${flag_post}"
189                                eval TimeSeriesChunck${Dimension}=true
190                                chunck=true
191                            fi
192                        fi
193                        (( j=j+1 ))
194                        #
195                        # If TimeSeriesVars list is empty or OFF we skip
196                        #
197                        if ( [ $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] || \
198                            [ ${chunck_size} = OFF ] ) ; then
199                            #IGCM_debug_Print 2 "Empty TS : ${compname}_Post_${FILE}_TimeSeriesVars${Dimension}"
200                            #(( i=i+3 ))
201                            continue
202                        fi
203                        #
204                        #  ICI ON TESTE QUE LES FICHIERS TS SONT LA!
205                        #
206                        #
207                        FILE=$( echo ${flag_post} | awk "-FPost_" '{print $2}' )
208                        IGCM_card_DefineArrayFromOption ${card}    Post_${FILE} TimeSeriesVars${Dimension}
209                        IGCM_card_DefineVariableFromOption ${card} Post_${FILE} ChunckJob${Dimension}
210                        #
211                        FlagDir=$( echo ${FILE} | awk -F "_" '{print $1}' )
212                        case ${FlagDir} in
213                            *Y)  TS_Dir=TS_YE  ;;
214                            *M)  TS_Dir=TS_MO  ;;
215                            *D)  TS_Dir=TS_DA  ;;
216                         3H|HF)  TS_Dir=TS_HF  ;;
217                           INS) TS_Dir=TS_INS ;;
218                        esac
219                        #
220                        # We need LIST of variables not allready produced (useful for standalone mode)
221                        #
222                        DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
223                        IGCM_date_GetYearMonth ${DateBegin} YearBegin MonthBegin
224
225                        # Si on n'a pas de chunck, dans ce cas chunck_size=la durée de la simulation en années
226                        YearsChunckLength=$( echo ${chunck_size} | sed -e "s/[yY]//" )
227                        [ ${chunck} = false ] && YearsChunckLength=$(( YearEnd - YearBegin + 1 ))
228
229                        NbYearsChunckLoop=$(( ( YearEnd - YearBegin + 1 ) / YearsChunckLength ))
230                        Reste=$(( ( YearEnd - YearBegin + 1 ) % YearsChunckLength ))
231
232                        if [ ${Reste} -ne 0 ] ; then
233                            NbYearsChunckLoop=$(( NbYearsChunckLoop + 1 ))
234                        fi
235
236                        if [ ${NbYearsChunckLoop} -eq 1 ] ; then
237                            PeriodDateEnd=${DateEnd}
238                        else
239                            DaysInYear=$( IGCM_date_DaysInYear ${YearBegin} )
240                            PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( YearsChunckLength * DaysInYear - 1 )) )
241                        fi
242                        #
243                        DIRECTORY=${R_SAVE}/${comp}/Analyse/${TS_Dir}
244                        YearsChunckLoop=1
245                        ChunckDebut=${DateBegin}
246                        ChunckFin=${PeriodDateEnd}
247                        while [ ${YearsChunckLoop} -le ${NbYearsChunckLoop} ] ; do
248                            countTotal=0
249                            countGood=0
250                            countBad=0
251                            unset RemoveList
252                            unset PotentialCompletedFlag
253                            for var in $( eval echo \${${compname}_Post_${FILE}_TimeSeriesVars${Dimension}[*]} ) ; do
254                                TestedFile=${config_UserChoices_JobName}_${ChunckDebut}_${ChunckFin}_${FlagDir}_${var}.nc
255                                #
256                                Candidat=$( find ${DIRECTORY} -name "${config_UserChoices_JobName}_${ChunckDebut}_*_${FlagDir}_${var}.nc" )
257                                #
258                                BestCandidat=${ChunckDebut}
259                                #
260                                FoundCandidat=false
261                                if [ ! "X${Candidat}" = "X" ] ; then
262                                    for candid in ${Candidat} ; do
263                                        #IGCM_debug_Print 1 -e "\033[1;32m[CompletedFlag CANDIDAT MATCH FOUND]\033[m $( basename ${candid} )"
264                                        CandidatEnd=$( echo ${candid}   | awk -F${config_UserChoices_JobName} '{print $3}' | awk -F_ '{print $3}' )
265                                        if [ ${CandidatEnd} -gt ${ChunckFin} ] ; then
266                                            #IGCM_debug_Print 3 -e "File $( basename ${candid} ) should be suppress"
267                                            set +A RemoveList ${RemoveList[*]} ${candid}
268                                        elif [ ${CandidatEnd} -lt ${ChunckFin} ] ; then
269                                            #IGCM_debug_Print 3 -e "File $( basename ${candid} ) should be suppress or used as a CompletedFlag baseline"
270                                            # We keep the best candidat and remove the others
271                                            if [ ${BestCandidat} -lt ${CandidatEnd} ] ; then
272                                                BestCandidat=${CandidatEnd}
273                                                FoundCandidat=true
274                                            else
275                                                set +A RemoveList ${RemoveList[*]} ${candid}
276                                            fi
277                                        fi
278                                    done
279                                else
280                                    # No CompletedFlag candidat found
281                                    CandidatCompletedFlag=""
282                                fi
283                                #
284                                if [ ! -f ${DIRECTORY}/${TestedFile} ] ; then
285                                    (( countBad = countBad + 1 ))
286                                    [ ${countBad} = 1 ] && IGCM_debug_Print 3 "Missing time series from ${FILE} :"
287                                    IGCM_debug_Print 3 ${DIRECTORY}/${TestedFile}
288                                    # Then we keep a track of the Best Candidat
289                                    if [ ${FoundCandidat} = true ] ; then
290                                        if [ ${chunck} = true ] ; then
291                                            set +A PotentialCompletedFlag ${PotentialCompletedFlag[*]} ${BestCandidat}
292                                        else
293                                            eval set +A PotentialCompletedFlag${Dimension} \${PotentialCompletedFlag${Dimension}[*]} \${BestCandidat}
294                                        fi
295                                    fi
296                                else
297                                    (( countGood = countGood + 1 ))
298                                    # Then we do not need the best candidat if any
299                                    [ ${FoundCandidat} = true ] && set +A RemoveList ${RemoveList[*]} ${config_UserChoices_JobName}_${ChunckDebut}_${BestCandidat}_${FlagDir}_${var}.nc
300                                fi
301                                (( countTotal = countTotal + 1 ))
302                            done
303
304                            SuccessRate=$(( countGood * 100 / countTotal ))
305                            if [ ${SuccessRate} -ne 100 ] ; then
306                                IGCM_debug_Print 2 -e "\033[1;31m${SuccessRate}% files OK.\033[m for period ${ChunckDebut}-${ChunckFin}"
307                            else
308                                IGCM_debug_Print 2 -e "\033[1;32m${SuccessRate}% files OK.\033[m for period ${ChunckDebut}-${ChunckFin}"
309                            fi
310                            echo
311
312                            # Remove what's in the RemoveList
313                            if [ ${RemoveList} ] ; then
314                                IGCM_debug_Print 2 "File(s) that will be removed ${RemoveList[*]}"
315                                #IGCM_sys_Rm ${RemoveList[*]}
316                            fi
317                            #[ ${FoundCandidat} = true ] && IGCM_debug_Print 2 "Potentials CompletedFlag: ${PotentialCompletedFlag[*]}"
318                            if ( [ ${chunck} = true ] && [ ${SuccessRate} -ne 100 ] ) ; then
319                                #
320                                # TO REWRITE BEGIN
321                                #
322                                NbCandidats=${#PotentialCompletedFlag[@]}
323                                countCandid=1
324                                if [ ${NbCandidats} -eq 0 ] ; then
325                                    ChunckCompletedFlag=""
326                                    IGCM_debug_Print 2 -e "\033[1;31mNO CompletedFlag\033[m"
327                                elif [ ${NbCandidats} -eq 1 ] ; then
328                                    ChunckCompletedFlag=${PotentialCompletedFlag[0]}
329                                    IGCM_debug_Print 2 -e "\033[1;32mCompletedFlag=${ChunckCompletedFlag}\033[m"
330                                elif [ ${NbCandidats} -gt 1 ] ; then
331                                    k=1
332                                    until [ $k -ge ${NbCandidats} ]; do
333                                        ((k_m1=k-1))
334                                        if [ ${PotentialCompletedFlag[${k_m1}]} = ${PotentialCompletedFlag[${k}]} ] ; then
335                                            ((countCandid=countCandid+1))
336                                        fi
337                                        ((k=k+1))
338                                    done
339                                    if [ ${NbCandidats} -eq ${countCandid} ] ; then
340                                        ChunckCompletedFlag=${PotentialCompletedFlag[0]}
341                                        IGCM_debug_Print 2 -e "\033[1;32mCompletedFlag=${ChunckCompletedFlag}\033[m"
342                                    else
343                                        IGCM_debug_Print 2 -e "\033[1;31mToo Many Potential CompletedFlag\033[m CASE NOT HANDLE YET"
344                                    fi
345                                fi
346                                #
347                                # TO REWRITE END
348                                #
349                                IGCM_debug_Print 2 -e "\033[1;31mSubmit ${FILE} chunck ${Dimension}\033[m period ${ChunckDebut}-${ChunckFin} and CompletedFlag=${ChunckCompletedFlag}"
350                                listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,CompletedFlag,TsTask,CompToRead,FlagToRead"
351                                export libIGCM=${libIGCM}
352                                export SUBMIT_DIR=${CARD_DIR}
353                                export POST_DIR=${POST_DIR}
354                                export DateBegin=${ChunckDebut}
355                                export PeriodDateEnd=${ChunckFin}
356                                export CompletedFlag=${ChunckCompletedFlag}
357                                export TsTask=Chunck${Dimension}
358                                export CompToRead=${comp}
359                                export FlagToRead=${i}
360                                export NameToRead=${flag_post}
361                                export listVarEnv=${listVarEnv}
362                                IGCM_sys_MkdirWork ${POST_DIR}
363                                IGCM_debug_Verif_Exit
364                                Script_Post_Output=create_ts.${PeriodDateEnd}.${TsTask}.${CompToRead}.${NameToRead}
365                                IGCM_sys_QsubPost create_ts
366                                echo
367                            fi
368
369                            if ( [ ${chunck} = false ] && [ ${SuccessRate} -ne 100 ] ) ; then
370                                eval Launch${Dimension}=true
371                            fi
372
373                            # Date update
374                            ChunckDebut=$( IGCM_date_AddDaysToGregorianDate ${ChunckFin} 1 )
375
376                            (( YearsChunckLoop = YearsChunckLoop + 1 ))
377
378                            if [ ${YearsChunckLoop} -eq ${NbYearsChunckLoop} ] ; then
379                                ChunckFin=${DateEnd}
380                            else
381                                ChunckFin=$( IGCM_date_AddDaysToGregorianDate ${ChunckDebut} $(( YearsChunckLength * DaysInYear - 1 )) )
382                            fi
383                        done
384                    done
385                else
386                    ListDimension[0]=""
387                    TimeSeries=true
388                    TimeSeries2D=false
389                    TimeSeries3D=false
390                    TimeSeriesChunck2D=false
391                    TimeSeriesChunck3D=false
392                fi
393            fi
394            (( i=i+3 ))
395        done
396    fi
397done # comp loop
398
399echo
400
401DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
402IGCM_date_GetYearMonth ${DateBegin} YearBegin MonthBegin
403CompletedFlag=${SavedCompletedFlag}
404
405if [ X${Launch2D} = Xtrue ] ; then
406    #IGCM_debug_Print 2 "Potentials CompletedFlag: ${PotentialCompletedFlag2D[*]}"
407    IGCM_debug_Print 2 -e "\033[1;31mSubmit 2D\033[m without chunck period ${DateBegin}-${DateEnd}"
408    listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,CompletedFlag,TsTask"
409    export libIGCM=${libIGCM}
410    export SUBMIT_DIR=${CARD_DIR}
411    export POST_DIR=${POST_DIR}
412    export DateBegin=${DateBegin}
413    export PeriodDateEnd=${DateEnd}
414    export CompletedFlag=${CompletedFlag}
415    export TsTask=2D
416    export listVarEnv=${listVarEnv}
417    IGCM_sys_MkdirWork ${POST_DIR}
418    IGCM_debug_Verif_Exit
419    Script_Post_Output=create_ts.${PeriodDateEnd}.${TsTask}
420    IGCM_sys_QsubPost create_ts
421    echo
422fi
423
424if [ X${Launch3D} = Xtrue ] ; then
425    #IGCM_debug_Print 2 "Potentials CompletedFlag: ${PotentialCompletedFlag3D[*]}"
426    IGCM_debug_Print 2 -e "\033[1;31mSubmit 3D\033[m without chunck period ${DateBegin}-${DateEnd}"
427    listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,CompletedFlag,TsTask"
428    export libIGCM=${libIGCM}
429    export SUBMIT_DIR=${CARD_DIR}
430    export POST_DIR=${POST_DIR}
431    export DateBegin=${DateBegin}
432    export PeriodDateEnd=${DateEnd}
433    export CompletedFlag=${CompletedFlag}
434    export TsTask=3D
435    export listVarEnv=${listVarEnv}
436    IGCM_sys_MkdirWork ${POST_DIR}
437    IGCM_debug_Verif_Exit
438    Script_Post_Output=create_ts.${PeriodDateEnd}.${TsTask}
439    IGCM_sys_QsubPost create_ts
440    echo
441fi
Note: See TracBrowser for help on using the repository browser.