source: trunk/libIGCM/AA_TimeSeries_Checker @ 271

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

Add a script that will :

  • check every timeseries has been properly done (be given a set of cards)
  • for each raw files give a colorized status report (red : some variables are missing , green : everything is cool)
  • will submit what's missing

If everything is green you are ready to launch the cmor2 files processing

File size: 10.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# 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                    iLoop=${#ListDimension[*]}
128                    j=0
129                    until [ $j -ge ${iLoop} ]; do
130                        Dimension=${ListDimension[${j}]}
131                        IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension}
132                        IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension}
133                        #
134                        # Time series WITHOUT chunk
135                        #
136                        if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
137                            if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then
138                                IGCM_debug_Print 2 "${Dimension} time series activated for ${flag_post}"
139                                eval TimeSeries${Dimension}=true
140                                chunck=false
141                            fi
142                        fi
143                        #
144                        # Time series WITH chunk
145                        #
146                        if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
147                            chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} )
148                            if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
149                                IGCM_debug_Print 2 "${Dimension} time series activated with ${chunck_size} chunck for ${flag_post}"
150                                eval TimeSeriesChunck${Dimension}=true
151                                chunck=true
152                            fi
153                        fi
154                        (( j=j+1 ))
155
156                        #
157                        #  ICI ON TEST QUE LES FICHIERS TS SONT LA!
158                        #
159                        #
160                        FILE=$( echo ${flag_post} | awk "-FPost_" '{print $2}' )
161                        IGCM_card_DefineArrayFromOption ${card}    Post_${FILE} TimeSeriesVars${Dimension}
162                        IGCM_card_DefineVariableFromOption ${card} Post_${FILE} ChunckJob${Dimension}
163                        #
164                        FlagDir=$( echo ${FILE} | awk -F "_" '{print $1}' )
165                        case ${FlagDir} in
166                            *Y)  TS_Dir=TS_YE  ;;
167                            *M)  TS_Dir=TS_MO  ;;
168                            *D)  TS_Dir=TS_DA  ;;
169                         3H|HF)  TS_Dir=TS_HF  ;;
170                           INS) TS_Dir=TS_INS ;;
171                        esac
172
173                        #
174                        # If TimeSeriesVars list is empty we skip
175                        #
176                        if [ $( eval echo \${${compname}_Post_${FILE}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
177                            #(( i=i+3 ))
178                            continue
179                        fi
180                        #
181                        # We need LIST of variables not allready produced (useful for standalone mode)
182                        #
183                        DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
184                        DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
185
186                        IGCM_date_GetYearMonth ${DateBegin} YearBegin MonthBegin
187                        IGCM_date_GetYearMonth ${DateEnd}   YearEnd   MonthEnd
188
189                        # Si on n'a pas de chunck, dans ce cas chunck_size=la durée de la simulation en années
190                        YearsChunckLength=$( echo ${chunck_size} | sed -e "s/[yY]//" )
191                        [ ${chunck} = false ] && YearsChunckLength=$( expr \( ${YearEnd} \- ${YearBegin} \+ 1 \) )
192
193                        NbYearsChunckLoop=$( expr \( ${YearEnd} \- ${YearBegin} \+ 1 \) / ${YearsChunckLength} )
194                        Reste=$( expr \( ${YearEnd} \- ${YearBegin} \+ 1 \) % ${YearsChunckLength} )
195
196                        if [ ${Reste} != 0 ] ; then
197                            NbYearsChunckLoop=$( expr ${NbYearsChunckLoop} + 1 )
198                        fi
199
200                        if [ ${NbYearsChunckLoop} -eq 1 ] ; then
201                            PeriodDateEnd=${DateEnd}
202                        else
203                            DaysInYear=$( IGCM_date_DaysInYear ${YearBegin} )
204                            PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( YearsChunckLength * DaysInYear - 1 )) )
205                        fi
206                        #
207                        DIRECTORY=${R_SAVE}/${comp}/Analyse/${TS_Dir}
208                        YearsChunckLoop=1
209                        ChunckDebut=${DateBegin}
210                        ChunckFin=${PeriodDateEnd}
211                        while [ ${YearsChunckLoop} -le ${NbYearsChunckLoop} ] ; do
212                            countTotal=0
213                            countGood=0
214                            countBad=0
215                            for var in $( eval echo \${${compname}_Post_${FILE}_TimeSeriesVars${Dimension}[*]} ) ; do
216                                TestedFile=${config_UserChoices_JobName}_${ChunckDebut}_${ChunckFin}_${FlagDir}_${var}.nc
217                                #
218                                if [ ! -f ${DIRECTORY}/${TestedFile} ] ; then
219                                    (( countBad = countBad + 1 ))
220                                    [ ${countBad} = 1 ] && IGCM_debug_Print 3 "Missing time series from ${FILE} :"
221                                    IGCM_debug_Print 3 ${DIRECTORY}/${TestedFile}
222                                else
223                                    (( countGood = countGood + 1 ))
224                                fi
225                                (( countTotal = countTotal + 1 ))
226                            done
227
228                            SuccessRate=$(( countGood * 100 / countTotal ))
229                            if [ ! ${SuccessRate} = 100 ] ; then
230                                IGCM_debug_Print 2 "\033[1;31m${SuccessRate}% files OK.\033[m for period ${ChunckDebut}-${ChunckFin}"
231                            else
232                                IGCM_debug_Print 2 "\033[1;32m${SuccessRate}% files OK.\033[m for period ${ChunckDebut}-${ChunckFin}"
233                            fi
234
235                            echo
236                            if ( [ ${chunck} = true ] && [ ! ${SuccessRate} = 100 ] ) ; then
237                                listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,TsTask,CompToRead,FlagToRead"
238                                export libIGCM=${libIGCM}
239                                export SUBMIT_DIR=${CARD_DIR}
240                                export POST_DIR=${POST_DIR}
241                                export DateBegin=${ChunckDebut}
242                                export PeriodDateEnd=${ChunckFin}
243                                export TsTask=Chunck${Dimension}
244                                export CompToRead=${comp}
245                                export FlagToRead=${i}
246                                export listVarEnv=${listVarEnv}
247                                IGCM_sys_MkdirWork ${POST_DIR}
248                                IGCM_debug_Verif_Exit
249                                IGCM_sys_QsubPost create_ts
250                            fi
251
252                            if ( [ ${chunck} = false ] && [ ! ${SuccessRate} = 100 ] ) ; then
253                                eval Launch${Dimension}=true
254                            fi
255
256                            # Date update
257                            ChunckDebut=$( IGCM_date_AddDaysToGregorianDate ${ChunckFin} 1 )
258
259                            (( YearsChunckLoop = YearsChunckLoop + 1 ))
260
261                            if [ ${YearsChunckLoop} -eq ${NbYearsChunckLoop} ] ; then
262                                ChunckFin=${DateEnd}
263                            else
264                                #PeriodDateEnd=$( expr ${YearBegin} + ${YearsChunckLength} - 1 )
265                                ChunckFin=$( IGCM_date_AddDaysToGregorianDate ${ChunckDebut} $(( YearsChunckLength * DaysInYear - 1 )) )
266                            fi
267                        done
268                    done
269                else
270                    ListDimension[0]=""
271                    TimeSeries=true
272                    TimeSeries2D=false
273                    TimeSeries3D=false
274                    TimeSeriesChunck2D=false
275                    TimeSeriesChunck3D=false
276                fi
277            fi
278            (( i=i+3 ))
279        done
280    fi
281done # comp loop
282
283if [ X${launch2D} = Xtrue ] ; then
284    listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,TsTask"
285    export libIGCM=${libIGCM}
286    export SUBMIT_DIR=${CARD_DIR}
287    export POST_DIR=${POST_DIR}
288    export DateBegin=${DateBegin}
289    export PeriodDateEnd=${DateEnd}
290    export TsTask=2D
291    export listVarEnv=${listVarEnv}
292    IGCM_sys_MkdirWork ${POST_DIR}
293    IGCM_debug_Verif_Exit
294    IGCM_sys_QsubPost create_ts
295fi
296
297if [ X${launch3D} = Xtrue ] ; then
298    listVarEnv="libIGCM,SUBMIT_DIR,POST_DIR,DateBegin,PeriodDateEnd,TsTask"
299    export libIGCM=${libIGCM}
300    export SUBMIT_DIR=${CARD_DIR}
301    export POST_DIR=${POST_DIR}
302    export DateBegin=${DateBegin}
303    export PeriodDateEnd=${DateEnd}
304    export TsTask=3D
305    export listVarEnv=${listVarEnv}
306    IGCM_sys_MkdirWork ${POST_DIR}
307    IGCM_debug_Verif_Exit
308    IGCM_sys_QsubPost create_ts
309fi
Note: See TracBrowser for help on using the repository browser.