source: trunk/libIGCM/AA_create_ts @ 70

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