source: trunk/libIGCM/AA_TimeSeries_Checker @ 390

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

Step 1/3 toward CompletedFlag? auto-detection, part of ticket #40
Tests ongoing.

This should close ticket #41

  • Property svn:keywords set to Revision Author Date
File size: 16.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 "YearBegin MonthBegin for TimeSeries_Checker : ${YearBegin} ${MonthBegin}"
104IGCM_debug_Print 1 "YearEnd   MonthEnd   for TimeSeries_Checker : ${YearEnd} ${MonthEnd}"
105IGCM_debug_Print 1 "CompletedFlag = "${CompletedFlag}
106echo
107
108#====================================================
109#R_SAVE : Job output directory
110if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
111    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
112    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
113    R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
114else
115    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
116    R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName}
117fi
118
119IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card ListOfComponents
120
121for comp in ${config_ListOfComponents[*]} ; do
122    # Debug Print
123    IGCM_debug_Print 1 ${comp}
124    # Define component
125    IGCM_card_DefineArrayFromOption ${CARD_DIR}/config.card ListOfComponents ${comp}
126    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
127    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
128
129    # Read libIGCM compatibility version in ${compname}.card
130    card=${CARD_DIR}/COMP/${compname}.card
131
132    # Read and Build Output File stuff
133    #IGCM_debug_Print 1 "DefineArrayFromOption  : ${compname}_OutputFiles ${card}"
134    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
135    ListFilesName=${compname}_OutputFiles_List
136    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
137    #
138    if [ X${FileName0} != X${NULL_STR} ] ; then
139        #
140        #IGCM_debug_Print 1 "Component      : ${compname}"
141        #
142        # INITIALISATION
143        #
144        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
145        i=2
146        #
147        until [ $i -ge $NbFiles ]; do
148            #
149            eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
150            #
151            if [ X${flag_post} != XNONE ] ; then
152                #
153                # First of all
154                #
155                IGCM_card_DefineArrayFromSection ${card} ${flag_post}
156                #
157                IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars
158                IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches
159                if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not found ${flag_post}" ] ; then
160                    # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob.
161                    unset ListDimension
162                    ListDimension[0]=2D
163                    ListDimension[1]=3D
164                    TimeSeries=false
165                    TimeSeries2D=false
166                    TimeSeries3D=false
167                    chunck=false
168                    iLoop=${#ListDimension[*]}
169                    j=0
170                    until [ $j -ge ${iLoop} ]; do
171                        Dimension=${ListDimension[${j}]}
172                        IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension}
173                        IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension}
174                        #
175                        # Time series WITHOUT chunk
176                        #
177                        if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
178                            if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then
179                                IGCM_debug_Print 2 "${Dimension} time series activated for ${flag_post}"
180                                eval TimeSeries${Dimension}=true
181                                chunck=false
182                            fi
183                        fi
184                        #
185                        # Time series WITH chunk
186                        #
187                        if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
188                            chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} )
189                            if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
190                                IGCM_debug_Print 2 "${Dimension} time series activated with ${chunck_size} chunck for ${flag_post}"
191                                eval TimeSeriesChunck${Dimension}=true
192                                chunck=true
193                            fi
194                        fi
195                        (( j=j+1 ))
196                        #
197                        # If TimeSeriesVars list is empty or OFF we skip
198                        #
199                        if ( [ $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] || \
200                            [ ${chunck_size} = OFF ] ) ; then
201                            #IGCM_debug_Print 2 "Empty TS : ${compname}_Post_${FILE}_TimeSeriesVars${Dimension}"
202                            #(( i=i+3 ))
203                            continue
204                        fi
205                        #
206                        #  ICI ON TESTE QUE LES FICHIERS TS SONT LA!
207                        #
208                        #
209                        FILE=$( echo ${flag_post} | awk "-FPost_" '{print $2}' )
210                        IGCM_card_DefineArrayFromOption ${card}    Post_${FILE} TimeSeriesVars${Dimension}
211                        IGCM_card_DefineVariableFromOption ${card} Post_${FILE} ChunckJob${Dimension}
212                        #
213                        FlagDir=$( echo ${FILE} | awk -F "_" '{print $1}' )
214                        case ${FlagDir} in
215                            *Y)  TS_Dir=TS_YE  ;;
216                            *M)  TS_Dir=TS_MO  ;;
217                            *D)  TS_Dir=TS_DA  ;;
218                         3H|HF)  TS_Dir=TS_HF  ;;
219                           INS) TS_Dir=TS_INS ;;
220                        esac
221                        #
222                        # We need LIST of variables not allready produced (useful for standalone mode)
223                        #
224                        DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
225                        IGCM_date_GetYearMonth ${DateBegin} YearBegin MonthBegin
226
227                        # Si on n'a pas de chunck, dans ce cas chunck_size=la durée de la simulation en années
228                        YearsChunckLength=$( echo ${chunck_size} | sed -e "s/[yY]//" )
229                        [ ${chunck} = false ] && YearsChunckLength=$(( YearEnd - YearBegin + 1 ))
230
231                        NbYearsChunckLoop=$(( ( YearEnd - YearBegin + 1 ) / YearsChunckLength ))
232                        Reste=$(( ( YearEnd - YearBegin + 1 ) % YearsChunckLength ))
233
234                        if [ ${Reste} -ne 0 ] ; then
235                            NbYearsChunckLoop=$(( NbYearsChunckLoop + 1 ))
236                        fi
237
238                        if [ ${NbYearsChunckLoop} -eq 1 ] ; then
239                            PeriodDateEnd=${DateEnd}
240                        else
241                            DaysInYear=$( IGCM_date_DaysInYear ${YearBegin} )
242                            PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( YearsChunckLength * DaysInYear - 1 )) )
243                        fi
244                        #
245                        DIRECTORY=${R_SAVE}/${comp}/Analyse/${TS_Dir}
246                        YearsChunckLoop=1
247                        ChunckDebut=${DateBegin}
248                        ChunckFin=${PeriodDateEnd}
249                        while [ ${YearsChunckLoop} -le ${NbYearsChunckLoop} ] ; do
250                            countTotal=0
251                            countGood=0
252                            countBad=0
253                            unset RemoveList
254                            unset PotentialCompletedFlag
255                            for var in $( eval echo \${${compname}_Post_${FILE}_TimeSeriesVars${Dimension}[*]} ) ; do
256                                TestedFile=${config_UserChoices_JobName}_${ChunckDebut}_${ChunckFin}_${FlagDir}_${var}.nc
257                                #
258                                Candidat=$( find ${DIRECTORY} -name "${config_UserChoices_JobName}_${ChunckDebut}_*_${FlagDir}_${var}.nc" )
259                                #
260                                BestCandidat=${ChunckDebut}
261                                #
262                                FoundCandidat=false
263                                if [ ! "X${Candidat}" = "X" ] ; then
264                                    FoundCandidat=true
265                                    for i in ${Candidat} ; do
266                                        IGCM_debug_Print 1 -e "\033[1;32m[CompletedFlag CANDIDAT MATCH FOUND]\033[m $( basename ${i} )"
267                                        CandidatEnd=$( echo ${i}   | awk -F${config_UserChoices_JobName} '{print $3}' | awk -F_ '{print $3}' )
268                                        if [ ${CandidatEnd} -gt ${ChunckFin} ] ; then
269                                            IGCM_debug_Print 2 -e "File $( basename ${i} ) should be suppress"
270                                            set +A RemoveList ${RemoveList[*]} ${i}
271                                        elif [ ${CandidatEnd} -lt ${ChunckFin} ] ; then
272                                            IGCM_debug_Print 2 -e "File $( basename ${i} ) should be suppress or used as a CompletedFlag baseline"
273                                            # We keep the best candidat and remove the others
274                                            if [ ${BestCandidat} -lt ${CandidatEnd} ] ; then
275                                                BestCandidat=${CandidatEnd}
276                                            else
277                                                set +A RemoveList ${RemoveList[*]} ${i}
278                                            fi
279                                        fi
280                                    done
281                                else
282                                    # No CompletedFlag candidat found
283                                    CandidatCompletedFlag=""
284                                fi
285                                #
286                                if [ ! -f ${DIRECTORY}/${TestedFile} ] ; then
287                                    (( countBad = countBad + 1 ))
288                                    [ ${countBad} = 1 ] && IGCM_debug_Print 3 "Missing time series from ${FILE} :"
289                                    IGCM_debug_Print 3 ${DIRECTORY}/${TestedFile}
290                                    # Then we keep a track of the Best Candidat
291                                    [ ${FoundCandidat} = true ] && set +A PotentialCompletedFlag ${PotentialCompletedFlag[*]} ${BestCandidat}
292                                else
293                                    (( countGood = countGood + 1 ))
294                                    # Then we do not need the best candidat
295                                    [ ${FoundCandidat} = true ] && set +A RemoveList ${RemoveList[*]} ${config_UserChoices_JobName}_${ChunckDebut}_${BestCandidat}_${FlagDir}_${var}.nc
296                                fi
297                                (( countTotal = countTotal + 1 ))
298                            done
299
300                            SuccessRate=$(( countGood * 100 / countTotal ))
301                            if [ ${SuccessRate} -ne 100 ] ; then
302                                IGCM_debug_Print 2 -e "\033[1;31m${SuccessRate}% files OK.\033[m for period ${ChunckDebut}-${ChunckFin}"
303                            else
304                                IGCM_debug_Print 2 -e "\033[1;32m${SuccessRate}% files OK.\033[m for period ${ChunckDebut}-${ChunckFin}"
305                            fi
306                            echo
307
308                            # Remove what's in the RemoveList
309                            if [ ${RemoveList} ] ; then
310                                IGCM_debug_Print 2 "File(s) that will be removed ${RemoveList[*]}"
311                                #IGCM_sys_Rm ${RemoveList[*]}
312                            fi
313
314                            if ( [ ${chunck} = true ] && [ ${SuccessRate} -ne 100 ] ) ; then
315
316                                #
317                                # TO REWRITE BEGIN
318                                #
319                                ChunckCompletedFlag=""
320                                CompletedFlag=${SavedCompletedFlag}
321                                if [ X${CompletedFlag} != X ] ; then
322                                        ( [ ${CompletedFlag} -gt ${ChunckDebut} ] && [ ${CompletedFlag} -le ${ChunckFin} ] ) && ChunckCompletedFlag=${CompletedFlag}
323                                fi
324                                #
325                                # TO REWRITE END
326                                #
327
328
329                                IGCM_debug_Print 2 -e "\033[1;31mSubmit ${FILE} chunck ${Dimension}\033[m period ${ChunckDebut}-${ChunckFin}"
330                                listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,CompletedFlag,TsTask,CompToRead,FlagToRead"
331                                export libIGCM=${libIGCM}
332                                export SUBMIT_DIR=${CARD_DIR}
333                                export POST_DIR=${POST_DIR}
334                                export DateBegin=${ChunckDebut}
335                                export PeriodDateEnd=${ChunckFin}
336                                export CompletedFlag=${ChunckCompletedFlag}
337                                export TsTask=Chunck${Dimension}
338                                export CompToRead=${comp}
339                                export FlagToRead=${i}
340                                export NameToRead=${flag_post}
341                                export listVarEnv=${listVarEnv}
342                                IGCM_sys_MkdirWork ${POST_DIR}
343                                IGCM_debug_Verif_Exit
344                                Script_Post_Output=create_ts.${PeriodDateEnd}.${TsTask}.${CompToRead}.${NameToRead}
345                                IGCM_sys_QsubPost create_ts
346                                echo
347                            fi
348
349                            if ( [ ${chunck} = false ] && [ ${SuccessRate} -ne 100 ] ) ; then
350                                eval Launch${Dimension}=true
351                            fi
352
353                            # Date update
354                            ChunckDebut=$( IGCM_date_AddDaysToGregorianDate ${ChunckFin} 1 )
355
356                            (( YearsChunckLoop = YearsChunckLoop + 1 ))
357
358                            if [ ${YearsChunckLoop} -eq ${NbYearsChunckLoop} ] ; then
359                                ChunckFin=${DateEnd}
360                            else
361                                #PeriodDateEnd=$(( YearBegin + YearsChunckLength - 1 ))
362                                ChunckFin=$( IGCM_date_AddDaysToGregorianDate ${ChunckDebut} $(( YearsChunckLength * DaysInYear - 1 )) )
363                            fi
364                        done
365                    done
366                else
367                    ListDimension[0]=""
368                    TimeSeries=true
369                    TimeSeries2D=false
370                    TimeSeries3D=false
371                    TimeSeriesChunck2D=false
372                    TimeSeriesChunck3D=false
373                fi
374            fi
375            (( i=i+3 ))
376        done
377    fi
378done # comp loop
379
380echo
381
382DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
383IGCM_date_GetYearMonth ${DateBegin} YearBegin MonthBegin
384CompletedFlag=${SavedCompletedFlag}
385
386if [ X${Launch2D} = Xtrue ] ; then
387    IGCM_debug_Print 2 -e "\033[1;31mSubmit 2D\033[m without chunck period ${DateBegin}-${DateEnd}"
388    listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,CompletedFlag,TsTask"
389    export libIGCM=${libIGCM}
390    export SUBMIT_DIR=${CARD_DIR}
391    export POST_DIR=${POST_DIR}
392    export DateBegin=${DateBegin}
393    export PeriodDateEnd=${DateEnd}
394    export CompletedFlag=${CompletedFlag}
395    export TsTask=2D
396    export listVarEnv=${listVarEnv}
397    IGCM_sys_MkdirWork ${POST_DIR}
398    IGCM_debug_Verif_Exit
399    Script_Post_Output=create_ts.${PeriodDateEnd}.${TsTask}
400    IGCM_sys_QsubPost create_ts
401    echo
402fi
403
404if [ X${Launch3D} = Xtrue ] ; then
405    IGCM_debug_Print 2 -e "\033[1;31mSubmit 3D\033[m without chunck period ${DateBegin}-${DateEnd}"
406    listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,CompletedFlag,TsTask"
407    export libIGCM=${libIGCM}
408    export SUBMIT_DIR=${CARD_DIR}
409    export POST_DIR=${POST_DIR}
410    export DateBegin=${DateBegin}
411    export PeriodDateEnd=${DateEnd}
412    export CompletedFlag=${CompletedFlag}
413    export TsTask=3D
414    export listVarEnv=${listVarEnv}
415    IGCM_sys_MkdirWork ${POST_DIR}
416    IGCM_debug_Verif_Exit
417    Script_Post_Output=create_ts.${PeriodDateEnd}.${TsTask}
418    IGCM_sys_QsubPost create_ts
419    echo
420fi
Note: See TracBrowser for help on using the repository browser.