source: trunk/libIGCM/AA_create_ts @ 78

Last change on this file since 78 was 78, checked in by sdipsl, 15 years ago
  • Correct tyÃpo error in aix6 headers
  • 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: 26.9 KB
Line 
1#-Q- platine #!/usr/bin/ksh
2#-Q- platine ##################
3#-Q- platine ## PLATINE   CEA ##
4#-Q- platine ##################
5#-Q- platine #BSUB -J TS                     # Nom du job
6#-Q- platine #BSUB -N                        # message a la fin du job
7#-Q- platine #BSUB -n 1                      # reservation des processeurs pour le job
8#-Q- platine #BSUB -W 1:00                   # Limite temps
9#-Q- platine #BSUB -q post              # Passage en queue post
10#-Q- sx8brodie #!/bin/ksh
11#-Q- sx8brodie #######################
12#-Q- sx8brodie ## SX8BRODIE   IDRIS ##
13#-Q- sx8brodie #######################
14#-Q- sx8brodie # Temps Elapsed max. d'une requete hh:mm:ss
15#-Q- sx8brodie # @ wall_clock_limit = 10:00:00
16#-Q- sx8brodie # Nom du travail LoadLeveler
17#-Q- sx8brodie # @ job_name   = TS
18#-Q- sx8brodie # Fichier de sortie standard du travail       
19#-Q- sx8brodie # @ output     = $(job_name).$(jobid)
20#-Q- sx8brodie # Fichier de sortie d'erreur du travail
21#-Q- sx8brodie # @ error      =  $(job_name).$(jobid)
22#-Q- sx8brodie # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
23#-Q- sx8brodie # @ notification = error
24#-Q- sx8brodie # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $REBUILD_DIR ; $RebuildFromArchive ; $POST_DIR ; $DateBegin ; $PeriodDateBegin ; $PeriodDateEnd ; $NbRebuildDir ; $StandAlone ; $RESOL_ATM ; $RESOL_OCE ; $RESOL_ICE ; $RESOL_SRF ; $MASTER
25#-Q- aix6 #!/bin/ksh
26#-Q- aix6 #######################
27#-Q- aix6 ##   VARGAS   IDRIS  ##
28#-Q- aix6 #######################
29#-Q- aix6 # Temps Elapsed max. d'une requete hh:mm:ss
30#-Q- aix6 # @ wall_clock_limit = 10:00:00
31#-Q- aix6 # Nom du travail LoadLeveler
32#-Q- aix6 # @ job_name   = TS
33#-Q- aix6 # Fichier de sortie standard du travail
34#-Q- aix6 # @ output     = $(job_name).$(jobid)
35#-Q- aix6 # Fichier de sortie d'erreur du travail
36#-Q- aix6 # @ error      =  $(job_name).$(jobid)
37#-Q- aix6 # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
38#-Q- aix6 # @ notification = error
39#-Q- aix6 # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $REBUILD_DIR ; $RebuildFromArchive ; $POST_DIR ; $DateBegin ; $PeriodDateBegin ; $PeriodDateEnd ; $NbRebuildDir ; $StandAlone ; $RESOL_ATM ; $RESOL_OCE ; $RESOL_ICE ; $RESOL_SRF ; $MASTER
40#-Q- aix6 # @ queue
41#-Q- sx8brodie # @ queue
42#-Q- sx8mercure #!/bin/ksh
43#-Q- sx8mercure ######################
44#-Q- sx8mercure ## SX8MERCURE   CEA ##
45#-Q- sx8mercure ######################
46#-Q- sx8mercure #PBS -N TS                   # Nom du job
47#-Q- sx8mercure #PBS -j o                    # regroupement des stdout et stderr
48#-Q- sx8mercure #PBS -S /usr/bin/ksh         # shell de soumission
49#-Q- sx8mercure #PBS -l memsz_job=1gb        # Limite memoire a 1 Go
50#-Q- sx8mercure #PBS -l cputim_job=2:00:00   # Limite temps a 2 heures
51#-Q- sx8mercure #PBS -q scalaire
52#-Q- default #!/bin/ksh
53#-Q- default ##################
54#-Q- default ## DEFAULT HOST ##
55#-Q- default ##################
56
57#set -vx
58
59date
60
61#-Q- sx8brodie export OMP_NUM_THREADS=1
62
63# $Date$
64# $Author$
65# $Revision$
66# IPSL (2006)
67#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
68
69########################################################################
70
71#D- Flag to determine if this job in a standalone mode
72#D- Default : value from AA_job if any
73StandAlone=${StandAlone:=true}
74
75#D- Flag to determine job's output directory
76#D- Default : value from libIGCM_post.ksh if any
77POST_DIR=${POST_DIR:=${PBS_O_WORKDIR}}
78
79#D- Increased verbosity (1, 2, 3)
80#D- Default : value from AA_job if any
81Verbosity=${Verbosity:=3}
82
83#D- Low level debug : to bypass lib test checks and stack construction
84#D- Default : value from AA_job if any
85DEBUG_debug=${DEBUG_debug:=false}
86
87#D- Low level debug : to bypass lib test checks and stack construction
88#D- Default : value from AA_job if any
89libIGCM=${libIGCM:=/work/cont003/p86denv/PARA_SX8_ORCA2xLMD144142/Prelude/modipsl/libIGCM}
90
91#D- TEMPORARY Flag to determine atmospheric resolution
92#D- Default : value from atmospheric driver if any
93RESOL_ATM=${RESOL_ATM:=LMD144142}
94
95#D- TEMPORARY Flag to determine ocean resolution
96#D- Default : value from ocean driver if any
97RESOL_OCE=${RESOL_OCE:=ORCA2}
98
99#D- TEMPORARY Flag to determine ice resolution
100#D- Default : value from ice driver if any
101RESOL_ICE=${RESOL_ICE:=ORCA2}
102
103#D- Flag to determine surface resolution
104#D- Default : value from surface driver if any
105RESOL_SRF=${RESOL_SRF:=LMD144142}
106
107########################################################################
108
109. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh ;
110. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh     #; IGCM_debug_Check
111. ${libIGCM}/libIGCM_card/libIGCM_card.ksh   #; IGCM_card_Check
112. ${libIGCM}/libIGCM_date/libIGCM_date.ksh   #; IGCM_date_Check
113
114########################################################################
115
116#set -vx
117
118# Useful cleaning function
119MENAGE () 
120{ 
121    [ -f $3 ] & ( rm -f $1/$2 ;) 
122}
123
124########################################################################
125
126#set -vx
127
128if [ ${DEBUG_debug} = true ] ; then
129    IGCM_sys_MkdirWork ${RUN_DIR_PATH}
130    echo "RUN_DIR_PATH ${RUN_DIR_PATH} ok."
131fi
132IGCM_sys_Cd ${RUN_DIR_PATH}
133
134if [ ${StandAlone} = true ] ; then
135    CARD_DIR=${SUBMIT_DIR}
136else
137    CARD_DIR=${RUN_DIR_PATH}/$( basename ${SUBMIT_DIR} )
138    IGCM_sys_Get_Master ${SUBMIT_DIR} ${RUN_DIR_PATH}
139fi
140
141#
142# First of all
143#
144IGCM_card_DefineArrayFromSection       ${CARD_DIR}/config.card UserChoices
145typeset option
146for option in ${config_UserChoices[*]} ; do
147    IGCM_card_DefineVariableFromOption ${CARD_DIR}/config.card UserChoices ${option}
148done
149#
150echo
151IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
152IGCM_debug_PrintVariables 3 config_UserChoices_JobName
153IGCM_debug_PrintVariables 3 config_UserChoices_LongName
154IGCM_debug_PrintVariables 3 config_UserChoices_TagName
155IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
156IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
157IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
158IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
159echo
160
161#==================================
162
163R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
164#
165IGCM_card_DefineArrayFromSection       ${CARD_DIR}/config.card ListOfComponents
166#
167# Determine period for time series. Default : value from AA_job if any
168#
169DateBegin=${DateBegin:=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )}
170#
171PeriodDateEnd=${PeriodDateEnd:=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )}
172
173########################################################################
174#
175#      Depending on requested time series fill following variables :
176#
177#                           - LISTE_FILE_${comp}[*]
178#                           - LISTE_VARS_${file}[*]
179#                           - LISTE_AXIS_${file}[*]
180#                           - LISTE_PATCH_${file}[*]
181########################################################################
182
183#
184# For each selected component determine which files need post-processing
185#
186DoJob=false
187for comp in ${config_ListOfComponents[*]} ; do
188    #
189    ActiveComp=false
190    #
191    IGCM_card_DefineArrayFromOption ${CARD_DIR}/config.card ListOfComponents ${comp}
192    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
193    #
194    card=${CARD_DIR}/COMP/${compname}.card
195    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
196    #
197    ListFilesName=${compname}_OutputFiles_List
198    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
199    #
200    if [ X${FileName0} != X${NULL_STR} ] ; then
201        #
202        #IGCM_debug_Print 1 "Component      : ${compname}"
203        #
204        # INITIALISATION
205        #
206        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
207        typeset i=0
208        #
209        until [ $i -eq $NbFiles ]; do
210            #
211            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
212            eval file_in=${file_in_}
213            let $(( i_ = i+2 ))
214            eval flag_post_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
215            eval flag_post=${flag_post_}
216            #
217            if [ X${flag_post} != XNONE ] ; then
218                #
219                # Initialize ${flag_post}_${compname}_${post_freq}
220                #
221                eval export ${flag_post}_${compname}_TimeSeriesFrequency=true
222            fi
223            let $(( i=i+3 ))
224        done
225    fi
226
227    for element in $( env | grep Post_ | grep ${compname}_TimeSeriesFrequency | grep -i "=true" ) ; do
228        #
229        FILE=$( echo ${element} | awk -F "_${compname}" '{print $1}' | awk "-FPost_" '{print $2}' )
230        #
231        # For each comp and each file who needs post-processing
232        # determine which variables need time series.
233        #
234        IGCM_card_DefineArrayFromOption ${card} Post_${FILE} TimeSeriesVars
235        #
236        if [ $( eval echo \$\{${compname}_Post_${FILE}_TimeSeriesVars} ) = ${NULL_STR} ] ; then
237            #
238            IGCM_debug_Print 3 "Nothing to do for ${FILE} according to ${card}"
239            continue
240            #
241        fi
242        #
243        IGCM_card_DefineArrayFromOption ${card} Post_${FILE} Patches
244        #
245        # So we need coordinates axis to properly fill produced time series
246        #
247        IGCM_card_DefineArrayFromOption ${card} Post_${FILE} GatherWithInternal
248        #
249        if [ $( eval echo \$\{${compname}_Post_${FILE}_GatherWithInternal} ) = ${NULL_STR} ] ; then
250            #
251            IGCM_debug_Print 1 "ERROR !! We miss coordinate axis for ${FILE} according to ${card}"
252            IGCM_debug_Print 1 "So no time series will be produced for ${FILE} !!"
253            continue
254            #
255        fi
256        #
257        # CREATE LIST
258        #
259        FlagDir=$( echo ${FILE} | awk -F "_" '{print $1}' )
260        case ${FlagDir} in
261            *Y)  TS_Dir=TS_YE  ;;
262            *M)  TS_Dir=TS_MO  ;;
263            *D)  TS_Dir=TS_DA  ;;
264            HF)  TS_Dir=TS_HF  ;;
265            INS) TS_Dir=TS_INS ;;
266        esac
267
268        count=0
269        for var in $( eval echo \$\{${compname}_Post_${FILE}_TimeSeriesVars[*]} ) ; do
270            #
271            DIRECTORY=${R_SAVE}/${comp}/Analyse/${TS_Dir}
272            TestedFile=${config_UserChoices_JobName}_${DateBegin}_${PeriodDateEnd}_${FlagDir}_${var}.nc
273            #
274            IGCM_sys_TestFileArchive ${DIRECTORY}/${TestedFile}
275            if [ ! $? = 0 ] ; then
276                eval set +A LISTE_VARS_${FILE} \$\{LISTE_VARS_${FILE}[*]} ${var}
277                ActiveComp=true
278                (( count = count + 1 ))
279            fi
280        done
281
282        if [ ${count} -gt 0 ] ; then
283            #
284            eval set +A LISTE_FILE_${comp} \$\{LISTE_FILE_${comp}[*]} ${FILE}
285            eval set +A LISTE_AXIS_${FILE} \$\{${compname}_Post_${FILE}_GatherWithInternal[*]}
286            eval set +A LISTE_PATCHES_${FILE} \$\{${compname}_Post_${FILE}_Patches[*]}
287            if [ X$( eval echo \${LISTE_PATCHES_${FILE}[0]} ) !=  X${NULL_STR} ]; then
288                for Patch in $( eval echo \${LISTE_PATCHES_${FILE}[*]} ); do
289                    if [ Xload${Patch} != X ] ; then
290                        . ${libIGCM}/libIGCM_post/IGCM_${Patch}.ksh
291                        eval load${Patch}=loaded
292                    fi
293                done
294            fi
295            #
296        fi
297    done
298
299    if [ ${ActiveComp} = true ] ; then
300        set +A ActiveListOfComponents ${ActiveListOfComponents[*]} ${comp}
301    fi
302
303done
304
305set -A config_ListOfComponents ${ActiveListOfComponents[*]}
306[ ! -z "${ActiveListOfComponents}" ] && DoJob=true
307
308########################################################################
309#
310#                          DEFINE DATE FUNCTIONS
311#
312########################################################################
313
314# Give the end of the next $1 period from $2 date
315function create_ts_next_date {
316    IGCM_debug_PushStack "create_ts_next_date" $@
317    typeset year month Length
318    case ${config_UserChoices_PeriodLength} in
319        *Y|*y) 
320            PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | awk -F '[yY]' '{print $1}' )
321            IGCM_date_GetYearMonth ${1} year month
322            (( Length=0 ))
323            (( i=0 ))
324            until [ $i -ge $PeriodLengthInYears ] ; do
325                (( Length = Length + $( IGCM_date_DaysInYear $(( year + i + 1 )) ) )) 
326                (( i=i+1 ))
327            done
328            ;;
329        *M|*m) 
330            PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | awk -F '[mM]' '{print $1}' )
331            IGCM_date_GetYearMonth ${1} year month
332            (( year0 = year ))
333            if [ $(( month + 1 )) -lt 13 ] ; then
334                month0=$(( month + 1 ))
335            else
336                month0=$(( month + 1 - 12 ))
337                (( year = year0 + 1 ))
338            fi
339            (( Length=0 ))
340            (( i=0 ))
341            until [ $i -ge $PeriodLengthInMonths ] ; do
342                if [ $(( month0 + i )) -lt 13 ] ; then
343                    (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i )) ) ))
344                else
345                    (( year = year0 + 1 ))
346                    (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i - 12 )) ) ))
347                fi
348                (( i=i+1 ))
349            done
350            ;;
351        *D|*d)
352            Length=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[dD]//" ) ;;
353        *)
354            IGCM_debug_Exit "create_ts " ${config_UserChoices_PeriodLength} " invalid PeriodLength : choose in 1Y, *M, *D."
355            IGCM_debug_Verif_Exit_Post ;;
356    esac
357    echo ${Length}
358
359    IGCM_debug_PopStack "create_ts_next_date"
360}
361
362# Give the end of the actual $1 period from $2 date
363function create_ts_begin_date {
364    IGCM_debug_PushStack "create_ts_begin_date" $@
365    typeset year month Length
366    case ${config_UserChoices_PeriodLength} in
367        *Y|*y) 
368            PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | awk -F '[yY]' '{print $1}' )
369            IGCM_date_GetYearMonth ${1} year month
370            if [ X${2} = Xend ] ; then
371                (( year = year - PeriodLengthInYears + 1))
372            fi
373            (( Length=0 ))
374            (( i=0 ))
375            until [ $i -ge $PeriodLengthInYears ] ; do
376                (( Length = Length + $( IGCM_date_DaysInYear $(( year + i )) ) )) 
377                (( i=i+1 ))
378            done
379            ;;
380        *M|*m) 
381            PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | awk -F '[mM]' '{print $1}' )
382            IGCM_date_GetYearMonth ${1} year month
383            if [ X${2} = Xend ] ; then
384                (( month = month - PeriodLengthInMonths + 1 ))
385            fi     
386            (( year0 = year ))
387            if [ $month -le 0 ] ; then
388                (( month = month + 12 ))
389                year=$( printf "%04i\n" $(( year - 1 )) )
390            fi
391            month=$( printf "%02i\n" ${month} )
392            (( Length=0 ))
393            (( i=0 ))
394            until [ $i -ge $PeriodLengthInMonths ] ; do
395                if [ $(( month + i )) -lt 13 ] ; then
396                    (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) ))
397                else
398                    (( year = year0 + 1 ))
399                    (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) ))
400                fi
401                (( i=i+1 ))
402            done
403            ;;
404        *D|*d)
405            Length=$( echo ${config_UserChoices_PeriodLength} | sed -e "s/[dD]//" ) ;;
406        *)
407            IGCM_debug_Exit "create_ts " ${config_UserChoices_PeriodLength} " invalid PeriodLength : choose in 1Y, *M, *D."
408            IGCM_debug_Verif_Exit_Post ;;
409    esac
410    echo ${Length}
411
412    IGCM_debug_PopStack "create_ts_begin_date"
413}
414
415########################################################################
416#
417#               IS THERE SOME ALLREADY PRODUCED TIME SERIES ?
418#                 IF SO BRING THEM IN THE WORKING DIRECTORY
419#
420# PS : Keep in mind that IGCM_sys_Get here is a weak link :
421#      - especially for IDRiS
422#      - no special protection against "command too long" !
423#      - libIGCM_sys should handle that or modify following code part
424#
425########################################################################
426
427if [ ${StandAlone} != true ] ; then
428    Running_Flag=$( IGCM_sys_RshMaster "IGCM_card_DefineVariableFromOption \
429       ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesRunning ; \
430       echo \${run_PostProcessing_TimeSeriesRunning}" )
431
432    if [ X${Running_Flag} = Xy ] ; then
433        # Time Series Job allready running
434        IGCM_debug_Print 1 "Time Series Job allready running exit"
435        exit
436    fi
437    # Now run.card know we are running
438    IGCM_sys_RshMaster IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesRunning "y"
439    # Get information from last execution
440    CompletedFlag=$( IGCM_sys_RshMaster \
441        "IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted ;\
442        echo \${run_PostProcessing_TimeSeriesCompleted}" )
443fi
444
445# Is it the first submission or not ?
446if [ X${CompletedFlag} = X ] ; then
447    # First Time Series Submission
448    FIRST_PASS=TRUE
449    Length=$( create_ts_begin_date ${DateBegin} begin)
450    DATE_FIN_JOB_B=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( Length - 1 )) )
451else
452    # Last Completed Time Series
453    FIRST_PASS=FALSE
454    DATE_FIN_JOB_B=${CompletedFlag}
455    date=${DateBegin}_${DATE_FIN_JOB_B}
456    for comp in ${config_ListOfComponents[*]} ; do
457        #
458        IGCM_sys_Mkdir ${RUN_DIR_PATH}/${comp}
459        #
460        IGCM_sys_Cd ${RUN_DIR_PATH}/${comp}
461        #
462        set -A liste_file
463        #
464        file_path=${R_SAVE}/${comp}/Analyse
465        #
466        i=0
467        file=${NULL_STR}
468        #
469        for file in $( eval echo \${LISTE_FILE_${comp}[*]} ); do
470            #
471            # Determine in which output can we find file
472            # IE : Analyse/TS or Analyse/DA2TS or ...
473            #
474            FlagDir=$( echo ${file} | awk -F "_" '{print $1}' )
475            case ${FlagDir} in
476                *Y)  TS_Dir=TS_YE  ;;
477                *M)  TS_Dir=TS_MO  ;;
478                *D)  TS_Dir=TS_DA  ;;
479                HF)  TS_Dir=TS_HF  ;;
480                INS) TS_Dir=TS_INS ;;
481            esac
482            for var in $( eval echo \${LISTE_VARS_${file}[*]} ) ; do
483                #
484                set +A liste_file ${liste_file[*]} ${file_path}/${TS_Dir}/${config_UserChoices_JobName}_${date}_${FlagDir}_${var}.nc
485                #
486            done
487        done
488        if [ X${file} != X${NULL_STR} ] ; then
489            IGCM_sys_Get /l liste_file[*] ${RUN_DIR_PATH}/${comp}
490            IGCM_debug_Verif_Exit_Post
491        fi
492    done
493    #
494    LEVEL=0
495    #
496fi
497
498########################################################################
499#
500#                          DEFINE LOOP PARAMETERS
501#
502########################################################################
503
504DATE_COUNT=${DATE_FIN_JOB_B}
505DATE_FIN_JOB_B_LOOP=${DATE_FIN_JOB_B}
506
507( [ -n "${LEVEL}" ] && [ ${LEVEL} -eq 0 ] ) && NBRE_FILE_TOT=0 || NBRE_FILE_TOT=1
508
509if [ ${DoJob} = true ] ; then
510    while [ ${DATE_COUNT} -lt ${PeriodDateEnd} ] ; do
511        (( NBRE_FILE_TOT = NBRE_FILE_TOT + 1 ))
512        Length=$( create_ts_next_date ${DATE_COUNT} )
513        DATE_COUNT=$( IGCM_date_AddDaysToGregorianDate ${DATE_COUNT} ${Length} )
514    done
515else
516    NBRE_FILE_TOT=0
517fi
518
519if [ ${NBRE_FILE_TOT} -le ${UNIX_MAX_LIMIT} ] ; then
520    NBRE_TOUR=1
521elif [ ${NBRE_FILE_TOT}%${UNIX_MAX_LIMIT} -eq 0 ] ; then
522    let NBRE_TOUR=${NBRE_FILE_TOT}/${UNIX_MAX_LIMIT} 
523else
524    let NBRE_TOUR=${NBRE_FILE_TOT}/${UNIX_MAX_LIMIT}+1
525fi
526
527CURRENT_LOOP=1
528# THIS LOOP GIVES PARAMETERS FOR THE DATE'S LOOP ie : DATE_COURANTE, DATE_FIN.
529# WE HAVE 3 LEVELS
530#    - LEVEL 1 : JUST ONE LOOP TO COMPLETE
531#    - LEVEL 2 : WE ARE IN THE "DEEP" LOOP
532#    - LEVEL 3 : WE ARE IN THE LAST LOOP
533
534while [ ${CURRENT_LOOP} -le  ${NBRE_TOUR} ] ; do
535     
536    if [ ${NBRE_FILE_TOT} -le ${UNIX_MAX_LIMIT} ] ; then 
537        # - LEVEL 1 : JUST ONE LOOP TO COMPLETE
538        NBRE_FILE_LOOP=${NBRE_FILE_TOT}
539
540        if [ ${FIRST_PASS} = TRUE ] ; then
541            DATE_COURANTE=${DATE_FIN_JOB_B_LOOP}
542        else
543            Length=$( create_ts_next_date ${DATE_FIN_JOB_B_LOOP} )
544            DATE_COURANTE=$( IGCM_date_AddDaysToGregorianDate ${DATE_FIN_JOB_B_LOOP} ${Length} )
545        fi
546
547        DATE_FIN=${PeriodDateEnd}
548        DATE_FIN_JOB_B_LOOP_PREC=${DATE_FIN_JOB_B_LOOP}
549
550        [ -n "${DATE_LOOP}" ] && DATE_FIN_JOB_B_LOOP=${DATE_LOOP}
551        [ -n "${LEVEL}" ] && FLAG_B="TRUE" || FLAG_B="FALSE"
552
553        LEVEL=1
554        DEPOT="TRUE"     
555    elif [ ${CURRENT_LOOP} -ne  ${NBRE_TOUR} ] ; then
556        # - LEVEL 2 : WE ARE IN THE "DEEP" LOOP
557        NBRE_FILE_LOOP=${UNIX_MAX_LIMIT}
558
559        if [ ! ${FIRST_PASS} = TRUE ] && [ ${CURRENT_LOOP} -eq 1 ] ; then
560            Length=$( create_ts_next_date ${DATE_FIN_JOB_B_LOOP} )
561            DATE_COURANTE=$( IGCM_date_AddDaysToGregorianDate ${DATE_FIN_JOB_B_LOOP} ${Length} )
562        elif [ -z "${DATE_COURANTE}" ] ; then
563            DATE_COURANTE=${DATE_FIN_JOB_B}
564        else
565            Length=$( create_ts_next_date ${DATE_FIN} )
566            DATE_COURANTE=$( IGCM_date_AddDaysToGregorianDate ${DATE_FIN} ${Length} )
567        fi
568         
569        (( TotLength = 0 ))
570        COMPTEUR=1
571        DATE_LOOP=${DATE_COURANTE}
572
573        while [ ${COMPTEUR} -lt ${NBRE_FILE_LOOP} ] ; do
574            #
575            Length=$( create_ts_next_date ${DATE_LOOP} )
576            DATE_LOOP=$( IGCM_date_AddDaysToGregorianDate ${DATE_LOOP} ${Length} )
577            (( TotLength = TotLength + Length ))
578            (( COMPTEUR = COMPTEUR + 1 ))
579            #
580        done # while [ ${COMPTEUR} -le ${NBRE_FILE_LOOP} ] done
581        DATE_FIN=$( IGCM_date_AddDaysToGregorianDate ${DATE_COURANTE} ${TotLength} )
582
583        [ -n "${DATE_LOOP}" ] && DATE_FIN_JOB_B_LOOP_PREC=${DATE_FIN_JOB_B_LOOP} ; DATE_FIN_JOB_B_LOOP=${DATE_LOOP}
584        [ -n "${LEVEL}" ] && [ ${LEVEL} -eq 0 ] && FLAG_B="TRUE" || [ ${CURRENT_LOOP} -gt 1 ] && FLAG_B="TRUE" || FLAG_B="FALSE"
585        DEPOT="FALSE"
586        LEVEL=2
587    else
588        # - LEVEL 3 : WE ARE IN THE LAST LOOP
589        NBRE_FILE_LOOP=$( expr ${NBRE_FILE_TOT} % $(( UNIX_MAX_LIMIT * $(( CURRENT_LOOP - 1 )) )) )
590        [ ${NBRE_FILE_LOOP} -eq 0 ] && NBRE_FILE_LOOP=${UNIX_MAX_LIMIT}
591
592        Length=$( create_ts_next_date ${DATE_FIN} )
593        DATE_COURANTE=$(IGCM_date_AddDaysToGregorianDate ${DATE_FIN} ${Length} )
594        DATE_FIN=${PeriodDateEnd}
595        [ -n "${DATE_LOOP}" ] && DATE_FIN_JOB_B_LOOP_PREC=${DATE_FIN_JOB_B_LOOP} ; DATE_FIN_JOB_B_LOOP=${DATE_LOOP}
596
597        LEVEL=3
598        DEPOT="TRUE"
599        FLAG_B="TRUE"
600    fi
601
602    # THEN FOR EACH FILE TYPE WE LOOP BETWEEN DATE_COURANTE AND DATE_FIN.
603    for comp in ${config_ListOfComponents[*]} ; do
604        #
605        IGCM_sys_Mkdir ${RUN_DIR_PATH}/${comp}
606        #
607        IGCM_sys_Cd ${RUN_DIR_PATH}/${comp}
608        #
609        eval R_OUT_${comp}=${R_SAVE}/${comp}
610        #
611        i=0
612        #
613        for file in $( eval echo \${LISTE_FILE_${comp}[*]} ); do
614            #
615            # Determine in which output can we find file
616            # IE : Output/MO or Output/DA or ...
617            #
618            FlagDir=$( echo ${file} | awk -F "_" '{print $1}' )
619            case ${FlagDir} in
620                *Y)    TS_Dir=TS_YE  ; FreqDir=YE  ;;
621                *M)    TS_Dir=TS_MO  ; FreqDir=MO  ;;
622                *D)    TS_Dir=TS_DA  ; FreqDir=DA  ;;
623                HF)    TS_Dir=TS_HF  ; FreqDir=HF  ;;
624                INS)   TS_Dir=TS_INS ; FreqDir=INS ;;
625                *) 
626                       IGCM_debug_Print 1 "Error in FlagDir=${FlagDir} for file ${file}."
627                       IGCM_sys_Exit "Job create_ts" ;;
628            esac
629
630            # Initialize array
631            set -A liste_file
632            set -A liste_file_tmp
633
634            eval file_path=\${R_OUT_${comp}}/Output/${FreqDir}/
635
636            COMPTEUR=1
637            DATE_LOOP=${DATE_COURANTE}
638
639            while [ ${COMPTEUR} -le ${NBRE_FILE_LOOP} ] ; do
640                #
641                Length1=$( create_ts_begin_date ${DATE_LOOP} end)
642                DATE_TAB=$(  IGCM_date_AddDaysToGregorianDate ${DATE_LOOP} $(( 1 - Length1 )) )_${DATE_LOOP}
643
644                Length2=$( create_ts_next_date ${DATE_LOOP} end)
645                DATE_LOOP=$( IGCM_date_AddDaysToGregorianDate ${DATE_LOOP} ${Length2} )
646
647                set +A liste_file ${liste_file[*]} ${file_path}${config_UserChoices_JobName}_${DATE_TAB}_${file}.nc
648                set +A liste_file_tmp ${liste_file_tmp[*]} ${config_UserChoices_JobName}_${DATE_TAB}_${file}.nc
649                (( COMPTEUR = COMPTEUR + 1 ))
650                #
651            done # while [ ${COMPTEUR} -le ${NBRE_FILE_LOOP} ] done
652            DATE_LOOP=$( IGCM_date_AddDaysToGregorianDate ${DATE_LOOP} -${Length2} )
653
654            # Get selected files
655            IGCM_sys_Get /l liste_file[*] ${RUN_DIR_PATH}/${comp}
656            eval ExitFlag=false
657            IGCM_debug_Verif_Exit_Post
658
659            # Apply IGCM_Patch if needed
660            if [ X$( eval echo \${LISTE_PATCHES_${file}[0]} ) !=  X${NULL_STR} ]; then
661                for file_t in $( eval echo ${liste_file_tmp[*]} ); do           
662                    for Patch in $( eval echo \${LISTE_PATCHES_${file}[*]} ); do
663                        IGCM_${Patch} ${file_t}
664                    done
665                done
666            fi
667
668            # WE CAN CONCATENATE FILES AT THIS POINT
669            [ "${FLAG_B}" = "TRUE" ] && DATE_BUILD_B=${DateBegin}_${DATE_FIN_JOB_B_LOOP_PREC}
670            Length=$( create_ts_begin_date ${DATE_COURANTE} end)
671            DATE_BUILD1=$( IGCM_date_AddDaysToGregorianDate ${DATE_COURANTE} -$(( Length - 1 )) )
672            DATE_BUILD=${DATE_BUILD1}_${DATE_FIN}
673            DATE_BUILD_END=${DateBegin}_${DATE_FIN}
674
675            liste_coord=" "
676            for axis in $( eval echo \${LISTE_AXIS_${file}[*]} ); do
677              liste_coord=${liste_coord}${axis}","
678            done
679
680            # Time axis must be the last dimension
681            time_axis=${axis}
682
683            # SWITCH BETWEEN MODEL TO FIT PARTICULAR CASE
684            for var in $( eval echo \${LISTE_VARS_${file}[*]} ) ; do
685                #
686                IGCM_sys_ncrcat --hst -v ${liste_coord}${var} ${liste_file_tmp[*]} ${config_UserChoices_JobName}_${DATE_BUILD}_${FlagDir}_${var}.nc
687                #
688#                 # Change time axis name to be CF compliant
689#                 if [ ${time_axis} != time_counter ]; then
690#                   IGCM_sys_ncrename -O -v ${time_axis},time_counter ${config_UserChoices_JobName}_${DATE_BUILD}_${FlagDir}_${var}.nc
691#                 fi
692                #
693                if [ "${FLAG_B}" = "TRUE" ] ; then
694                    # WE CONCATENATE WITH EXISTING FILES
695                    file1=${config_UserChoices_JobName}_${DATE_BUILD_B}_${FlagDir}_${var}.nc
696                    file2=${config_UserChoices_JobName}_${DATE_BUILD}_${FlagDir}_${var}.nc
697                    file_out=${config_UserChoices_JobName}_${DATE_BUILD_END}_${FlagDir}_${var}.nc
698                    IGCM_sys_ncrcat --hst ${file1} ${file2} ${file_out}
699                    #
700                    IGCM_sys_Rm ${file1} ${file2}
701                fi
702                #
703                if [ "${DEPOT}" = "TRUE" ] ; then
704                    # WE PUT FINAL FILE ON FILE SYSTEM
705                    [ "${FLAG_B}" = "FALSE" ] && file_out=${config_UserChoices_JobName}_${DATE_BUILD}_${FlagDir}_${var}.nc
706                    #${ncatted} -a modulo,time_counter,c,c," " ${file_out}
707                    file_before=${config_UserChoices_JobName}_${DateBegin}_${DATE_FIN_JOB_B}_${FlagDir}_${var}.nc
708                    eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}}/Analyse/${TS_Dir}/${file_out}
709                    [ "${FLAG_B}" = "TRUE" ] && eval MENAGE \${R_OUT_${comp}}/Analyse/${TS_Dir} ${file_before} ${file_out}
710                    IGCM_sys_Rm ${file_out}
711                    #
712                fi
713                #
714                eval ExitFlag=false
715                IGCM_debug_Verif_Exit_Post
716            done     # for var in ${liste_var} ; do
717            IGCM_sys_Rm ${liste_file_tmp[*]}
718        done         # for file in ${liste_file_brut} do
719    done             # for comp in ${config_ListOfComponents[*]} ; do
720    eval ExitFlag=false
721    IGCM_debug_Verif_Exit_Post
722    # GO AHEAD IN DEEPEST LOOP
723    (( CURRENT_LOOP = CURRENT_LOOP + 1 ))
724done                 # while [ ${CURRENT_LOOP} -le  ${NBRE_TOUR} ] do
725# FINISH
726
727# DODS copy
728for comp in ${config_ListOfComponents[*]} ; do
729    for TS_Dir in TS_YE TS_MO TS_DA TS_HF TS_INS ; do
730        IGCM_sys_TestDirArchive ${R_SAVE}/${comp}/Analyse/${TS_Dir}
731        [ $? = 0 ] && IGCM_sys_Put_Dods ${comp}/Analyse/${TS_Dir}
732    done
733done
734
735# clean environment variables and export usefull one :
736if [ X$( hostname -s ) = Xrhodes ] ; then
737    LISTE_ENV=$( env | grep -iv MYLANG | grep -iv HOST | grep -iv LOGIN | grep -iv config_ | grep -iv R_ | grep -iv libIGCM | grep -iv PERIOD \
738        | grep -iv DMFDIR | grep -iv AN_| grep -iv YEARS | grep -iv ex | grep -iv RESOL_ | grep -iv PATH | grep -iv WORKDIR | grep -iv USER   \
739        | grep -iv LOGNAME | grep -iv PROFILE | grep -iv ENV | grep -iv TMPDIR | grep -iv POST_DIR | grep -iv StandAlone | grep -iv DB | awk -F= '{print $1}' )
740 
741    for variables in ${LISTE_ENV} ; do
742        unset ${variables}
743    done
744fi
745
746export POST_DIR; export SUBMIT_DIR; export libIGCM; export R_INIT; export R_BC; export StandAlone
747export RESOL_ATM; export RESOL_OCE ; export RESOL_ICE ; export RESOL_SRF
748
749listVarEnv="POST_DIR,SUBMIT_DIR,libIGCM,R_INIT,R_BC,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_SRF"
750export listVarEnv
751
752#D-
753# --------------------------------------------------------------------
754#D- Test if all was right
755# --------------------------------------------------------------------
756IGCM_debug_Verif_Exit_Post
757# --------------------------------------------------------------------
758#D- Submit MONITORING
759# --------------------------------------------------------------------
760IGCM_sys_QsubPost monitoring
761
762#D-
763# --------------------------------------------------------------------
764#D- Update the run.card
765# --------------------------------------------------------------------
766if [ ${StandAlone} != true ] ; then
767    # Put in run.card end period of time series
768    IGCM_sys_RshMaster IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted "${DATE_FIN}"
769    # We have finish the job !
770    IGCM_sys_RshMaster IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesRunning "n"
771fi
772date
Note: See TracBrowser for help on using the repository browser.