source: tags/libIGCM_v1_6/AA_TimeSeries_Checker @ 1456

Last change on this file since 1456 was 286, checked in by mmaipsl, 14 years ago

Suppress default use of '-e' parameter to echo because it doesn't work on all systems.
Use explicit ANSI colors when '-e' is passed to IGCM_debug_Print function as second argument.
Use that behaviour in TimeSeries_Checker and clean_month scripts.

File size: 11.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# Check that everything went well during time series production
17# Display a short report
18# Launch what's missing
19
20#
21libIGCM=${libIGCM:=::modipsl::/libIGCM}
22
23#
24POST_DIR=${POST_DIR:=OutScript}
25
26# Type de run
27EXPERIMENT=${EXPERIMENT:=historical}
28
29# Type de run
30JobName=${JobName:=HISTORC2}
31
32#
33CURRENT_DIR=$( pwd )
34
35#
36CARD_DIR=${CURRENT_DIR}/${EXPERIMENT}/${JobName}
37
38if [ ! -d ${CARD_DIR} ]; then
39    echo "No ${CARD_DIR}, we stop here"
40    exit
41fi
42
43########################################################################
44
45. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh ;
46. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh     #; IGCM_debug_Check
47. ${libIGCM}/libIGCM_card/libIGCM_card.ksh   #; IGCM_card_Check
48. ${libIGCM}/libIGCM_date/libIGCM_date.ksh   #; IGCM_date_Check
49
50########################################################################
51
52# First of all
53IGCM_card_DefineArrayFromSection       ${CARD_DIR}/config.card UserChoices
54typeset option
55for option in ${config_UserChoices[*]} ; do
56    IGCM_card_DefineVariableFromOption ${CARD_DIR}/config.card UserChoices ${option}
57done
58
59echo
60IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
61IGCM_debug_PrintVariables 3 config_UserChoices_JobName
62#IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName
63#IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName
64IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
65IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
66IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
67echo
68
69#set -vx
70
71#====================================================
72#R_SAVE : Job output directory
73if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
74    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
75    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
76    R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
77else
78    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
79    R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName}
80fi
81
82IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card ListOfComponents
83
84for comp in ${config_ListOfComponents[*]} ; do
85    # Debug Print
86    IGCM_debug_Print 1 ${comp}
87    # Define component
88    IGCM_card_DefineArrayFromOption ${CARD_DIR}/config.card ListOfComponents ${comp}
89    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
90    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
91
92    # Read libIGCM compatibility version in ${compname}.card
93    card=${CARD_DIR}/COMP/${compname}.card
94
95    # Read and Build Output File stuff
96    #IGCM_debug_Print 1 "DefineArrayFromOption  : ${compname}_OutputFiles ${card}"
97    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
98    ListFilesName=${compname}_OutputFiles_List
99    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
100    #
101    if [ X${FileName0} != X${NULL_STR} ] ; then
102        #
103        #IGCM_debug_Print 1 "Component      : ${compname}"
104        #
105        # INITIALISATION
106        #
107        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
108        i=2
109        #
110        until [ $i -ge $NbFiles ]; do
111            #
112            eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
113            #
114            if [ X${flag_post} != XNONE ] ; then
115                #
116                # First of all
117                #
118                IGCM_card_DefineArrayFromSection ${card} ${flag_post}
119                #
120                IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars
121                IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches
122                if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not found ${flag_post}" ] ; then
123                    # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob.
124                    ListDimension[0]=2D
125                    ListDimension[1]=3D
126                    TimeSeries=false
127                    TimeSeries2D=false
128                    TimeSeries3D=false
129                    iLoop=${#ListDimension[*]}
130                    j=0
131                    until [ $j -ge ${iLoop} ]; do
132                        Dimension=${ListDimension[${j}]}
133                        IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension}
134                        IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension}
135                        #
136                        # Time series WITHOUT chunk
137                        #
138                        if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
139                            if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then
140                                IGCM_debug_Print 2 "${Dimension} time series activated for ${flag_post}"
141                                eval TimeSeries${Dimension}=true
142                                chunck=false
143                            fi
144                        fi
145                        #
146                        # Time series WITH chunk
147                        #
148                        if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
149                            chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} )
150                            if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
151                                IGCM_debug_Print 2 "${Dimension} time series activated with ${chunck_size} chunck for ${flag_post}"
152                                eval TimeSeriesChunck${Dimension}=true
153                                chunck=true
154                            fi
155                        fi
156                        (( j=j+1 ))
157
158                        #
159                        #  ICI ON TEST QUE LES FICHIERS TS SONT LA!
160                        #
161                        #
162                        FILE=$( echo ${flag_post} | awk "-FPost_" '{print $2}' )
163                        IGCM_card_DefineArrayFromOption ${card}    Post_${FILE} TimeSeriesVars${Dimension}
164                        IGCM_card_DefineVariableFromOption ${card} Post_${FILE} ChunckJob${Dimension}
165                        #
166                        FlagDir=$( echo ${FILE} | awk -F "_" '{print $1}' )
167                        case ${FlagDir} in
168                            *Y)  TS_Dir=TS_YE  ;;
169                            *M)  TS_Dir=TS_MO  ;;
170                            *D)  TS_Dir=TS_DA  ;;
171                         3H|HF)  TS_Dir=TS_HF  ;;
172                           INS) TS_Dir=TS_INS ;;
173                        esac
174
175                        #
176                        # If TimeSeriesVars list is empty we skip
177                        #
178                        if [ $( eval echo \${${compname}_Post_${FILE}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
179                            #(( i=i+3 ))
180                            continue
181                        fi
182                        #
183                        # We need LIST of variables not allready produced (useful for standalone mode)
184                        #
185                        DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
186                        DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
187
188                        IGCM_date_GetYearMonth ${DateBegin} YearBegin MonthBegin
189                        IGCM_date_GetYearMonth ${DateEnd}   YearEnd   MonthEnd
190
191                        # Si on n'a pas de chunck, dans ce cas chunck_size=la durée de la simulation en années
192                        YearsChunckLength=$( echo ${chunck_size} | sed -e "s/[yY]//" )
193                        [ ${chunck} = false ] && YearsChunckLength=$( expr \( ${YearEnd} \- ${YearBegin} \+ 1 \) )
194
195                        NbYearsChunckLoop=$( expr \( ${YearEnd} \- ${YearBegin} \+ 1 \) / ${YearsChunckLength} )
196                        Reste=$( expr \( ${YearEnd} \- ${YearBegin} \+ 1 \) % ${YearsChunckLength} )
197
198                        if [ ${Reste} != 0 ] ; then
199                            NbYearsChunckLoop=$( expr ${NbYearsChunckLoop} + 1 )
200                        fi
201
202                        if [ ${NbYearsChunckLoop} -eq 1 ] ; then
203                            PeriodDateEnd=${DateEnd}
204                        else
205                            DaysInYear=$( IGCM_date_DaysInYear ${YearBegin} )
206                            PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( YearsChunckLength * DaysInYear - 1 )) )
207                        fi
208                        #
209                        DIRECTORY=${R_SAVE}/${comp}/Analyse/${TS_Dir}
210                        YearsChunckLoop=1
211                        ChunckDebut=${DateBegin}
212                        ChunckFin=${PeriodDateEnd}
213                        while [ ${YearsChunckLoop} -le ${NbYearsChunckLoop} ] ; do
214                            countTotal=0
215                            countGood=0
216                            countBad=0
217                            for var in $( eval echo \${${compname}_Post_${FILE}_TimeSeriesVars${Dimension}[*]} ) ; do
218                                TestedFile=${config_UserChoices_JobName}_${ChunckDebut}_${ChunckFin}_${FlagDir}_${var}.nc
219                                #
220                                if [ ! -f ${DIRECTORY}/${TestedFile} ] ; then
221                                    (( countBad = countBad + 1 ))
222                                    [ ${countBad} = 1 ] && IGCM_debug_Print 3 "Missing time series from ${FILE} :"
223                                    IGCM_debug_Print 3 ${DIRECTORY}/${TestedFile}
224                                else
225                                    (( countGood = countGood + 1 ))
226                                fi
227                                (( countTotal = countTotal + 1 ))
228                            done
229
230                            SuccessRate=$(( countGood * 100 / countTotal ))
231                            if [ ! ${SuccessRate} = 100 ] ; then
232                                IGCM_debug_Print 2 -e "\033[1;31m${SuccessRate}% files OK.\033[m for period ${ChunckDebut}-${ChunckFin}"
233                            else
234                                IGCM_debug_Print 2 -e "\033[1;32m${SuccessRate}% files OK.\033[m for period ${ChunckDebut}-${ChunckFin}"
235                            fi
236
237                            echo
238                            if ( [ ${chunck} = true ] && [ ! ${SuccessRate} = 100 ] ) ; then
239                                IGCM_debug_Print 2 -e "\033[1;31mSubmit ${FILE} chunck ${Dimension}\033[m period ${ChunckDebut}-${ChunckFin}"
240                                listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,TsTask,CompToRead,FlagToRead"
241                                export libIGCM=${libIGCM}
242                                export SUBMIT_DIR=${CARD_DIR}
243                                export POST_DIR=${POST_DIR}
244                                export DateBegin=${ChunckDebut}
245                                export PeriodDateEnd=${ChunckFin}
246                                export TsTask=Chunck${Dimension}
247                                export CompToRead=${comp}
248                                export FlagToRead=${i}
249                                export listVarEnv=${listVarEnv}
250                                IGCM_sys_MkdirWork ${POST_DIR}
251                                IGCM_debug_Verif_Exit
252                                IGCM_sys_QsubPost create_ts
253                                echo
254                            fi
255
256                            if ( [ ${chunck} = false ] && [ ! ${SuccessRate} = 100 ] ) ; then
257                                eval Launch${Dimension}=true
258                            fi
259
260                            # Date update
261                            ChunckDebut=$( IGCM_date_AddDaysToGregorianDate ${ChunckFin} 1 )
262
263                            (( YearsChunckLoop = YearsChunckLoop + 1 ))
264
265                            if [ ${YearsChunckLoop} -eq ${NbYearsChunckLoop} ] ; then
266                                ChunckFin=${DateEnd}
267                            else
268                                #PeriodDateEnd=$( expr ${YearBegin} + ${YearsChunckLength} - 1 )
269                                ChunckFin=$( IGCM_date_AddDaysToGregorianDate ${ChunckDebut} $(( YearsChunckLength * DaysInYear - 1 )) )
270                            fi
271                        done
272                    done
273                else
274                    ListDimension[0]=""
275                    TimeSeries=true
276                    TimeSeries2D=false
277                    TimeSeries3D=false
278                    TimeSeriesChunck2D=false
279                    TimeSeriesChunck3D=false
280                fi
281            fi
282            (( i=i+3 ))
283        done
284    fi
285done # comp loop
286
287echo
288
289if [ X${Launch2D} = Xtrue ] ; then
290    IGCM_debug_Print 2 -e "\033[1;31mSubmit 2D\033[m without chunck period ${DateBegin}-${DateEnd}"
291    listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,TsTask"
292    export libIGCM=${libIGCM}
293    export SUBMIT_DIR=${CARD_DIR}
294    export POST_DIR=${POST_DIR}
295    export DateBegin=${DateBegin}
296    export PeriodDateEnd=${DateEnd}
297    export TsTask=2D
298    export listVarEnv=${listVarEnv}
299    IGCM_sys_MkdirWork ${POST_DIR}
300    IGCM_debug_Verif_Exit
301    IGCM_sys_QsubPost create_ts
302    echo
303fi
304
305if [ X${Launch3D} = Xtrue ] ; then
306    IGCM_debug_Print 2 -e "\033[1;31mSubmit 3D\033[m without chunck period ${DateBegin}-${DateEnd}"
307    listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,TsTask"
308    export libIGCM=${libIGCM}
309    export SUBMIT_DIR=${CARD_DIR}
310    export POST_DIR=${POST_DIR}
311    export DateBegin=${DateBegin}
312    export PeriodDateEnd=${DateEnd}
313    export TsTask=3D
314    export listVarEnv=${listVarEnv}
315    IGCM_sys_MkdirWork ${POST_DIR}
316    IGCM_debug_Verif_Exit
317    IGCM_sys_QsubPost create_ts
318    echo
319fi
Note: See TracBrowser for help on using the repository browser.