source: branches/libIGCM_CESMEP/AA_create_ts

Last change on this file was 1585, checked in by ssenesi, 12 months ago

merge branch libIGCM_CESMEP with trunk that handles RedHat8 on Irene

  • 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 Revision Author Date
File size: 32.4 KB
Line 
1#-Q- curie ######################
2#-Q- curie ## CURIE   TGCC/CEA ##
3#-Q- curie ######################
4#-Q- curie #MSUB -r TS             # Nom du job
5#-Q- curie #MSUB -o TS.out_%I
6#-Q- curie #MSUB -e TS.out_%I
7#-Q- curie #MSUB -n 1              # Reservation du processus
8#-Q- curie #MSUB -T 80000          # Limite de temps elapsed du job
9#-Q- curie #MSUB -q ::default_node::
10#-Q- curie #MSUB -c ::default_core::
11#-Q- curie #MSUB -Q normal
12#-Q- curie #MSUB -A ::default_project::
13#-Q- curie set +x
14#-Q- irene ######################
15#-Q- irene ## IRENE   TGCC/CEA ##
16#-Q- irene ######################
17#-Q- irene #MSUB -r TS            # Job name
18#-Q- irene #MSUB -o TS.out_%I
19#-Q- irene #MSUB -e TS.out_%I
20#-Q- irene #MSUB -n 1             # Number of cores
21#-Q- irene #MSUB -T 80000         # Maximum elapsed time
22#-Q- irene #MSUB -q ::default_node::
23#-Q- irene #MSUB -c ::default_core::
24#-Q- irene #MSUB -Q normal
25#-Q- irene #MSUB -A ::default_post_project::
26#-Q- irene #MSUB -m store,work,scratch
27#-Q- irene set +x
28#-Q- irene-amd ######################
29#-Q- irene-amd ## IRENE   TGCC/CEA ##
30#-Q- irene-amd ######################
31#-Q- irene-amd #MSUB -r TS            # Job name
32#-Q- irene-amd #MSUB -o TS.out_%I
33#-Q- irene-amd #MSUB -e TS.out_%I
34#-Q- irene-amd #MSUB -n 1             # Number of cores
35#-Q- irene-amd #MSUB -T 80000         # Maximum elapsed time
36#-Q- irene-amd #MSUB -q ::default_node::
37#-Q- irene-amd #MSUB -c ::default_core::
38#-Q- irene-amd #MSUB -Q normal
39#-Q- irene-amd #MSUB -A ::default_post_project::
40#-Q- irene-amd #MSUB -m store,work,scratch
41#-Q- irene-amd set +x
42#-Q- jeanzay #!/bin/ksh
43#-Q- jeanzay ######################
44#-Q- jeanzay ## JEANZAY    IDRIS ##
45#-Q- jeanzay ######################
46#-Q- jeanzay #SBATCH --job-name=TS         # Job Name
47#-Q- jeanzay #SBATCH --output=TS.out_%I    # standard output
48#-Q- jeanzay #SBATCH --error=TS.out_%I     # error output
49#-Q- jeanzay #SBATCH -N  1                        # Number of core
50#-Q- jeanzay #SBATCH --partition=prepost          # Post-processing partition
51#-Q- jeanzay #SBATCH --time=10:00:00       # Wall clock limit (seconds)
52#-Q- jeanzay #SBATCH --account ::default_project::@cpu
53#-Q- jeanzay set +x
54#-Q- ada #!/bin/ksh
55#-Q- ada #######################
56#-Q- ada ## ADA         IDRIS ##
57#-Q- ada #######################
58#-Q- ada # @ job_type = mpich
59#-Q- ada # @ requirements = (Feature == "prepost")
60#-Q- ada # Temps Elapsed max. d'une requete hh:mm:ss
61#-Q- ada # @ wall_clock_limit = 20:00:00
62#-Q- ada # Nom du travail LoadLeveler
63#-Q- ada # @ job_name   = TS
64#-Q- ada # Fichier de sortie standard du travail
65#-Q- ada # @ output     = $(job_name).$(jobid)
66#-Q- ada # Fichier de sortie d'erreur du travail
67#-Q- ada # @ error      =  $(job_name).$(jobid)
68#-Q- ada # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
69#-Q- ada # @ notification = error
70#-Q- ada # @ environment  = $DEBUG_debug ; $BigBrother ; $postProcessingStopLevel ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $POST_DIR ; $Script_Post_Output ; $MASTER ; $RebuildFrequency ; $DateBegin ; $PeriodDateEnd ; $StandAlone ; $CompletedFlag ; $TsTask ; $CompToRead ; $FlagToRead ; $RESOL_ATM ; $RESOL_OCE ; $RESOL_ICE ; $RESOL_MBG ; $RESOL_SRF ; $RESOL_SBG ; wall_clock_limit=$(wall_clock_limit)
71#-Q- ada # @ queue
72#-Q- obelix ######################
73#-Q- obelix ## OBELIX      LSCE ##
74#-Q- obelix ######################
75#-Q- obelix #PBS -N TS
76#-Q- obelix #PBS -m a
77#-Q- obelix #PBS -j oe
78#-Q- obelix #PBS -q medium
79#-Q- obelix #PBS -o TS.$$
80#-Q- obelix #PBS -S /bin/ksh
81#-Q- mesoipsl #!/bin/ksh
82#-Q- mesoipsl ######################
83#-Q- mesoipsl ## MESO ESPRI IPSL  ##
84#-Q- mesoipsl ######################
85#-Q- mesoipsl #SBATCH --job-name=TS         # Job Name
86#-Q- mesoipsl #SBATCH --output=TS.out_%I    # standard output
87#-Q- mesoipsl #SBATCH --error=TS.out_%I     # error output
88#-Q- mesoipsl #SBATCH -N  1                        # Number of core
89#-Q- mesoipsl #SBATCH --time=10:00:00       # Wall clock limit (seconds)
90#-Q- ifort_CICLAD ######################
91#-Q- ifort_CICLAD ##   CICLAD    IPSL ##
92#-Q- ifort_CICLAD ######################
93#-Q- ifort_CICLAD #PBS -N TS
94#-Q- ifort_CICLAD #PBS -m a
95#-Q- ifort_CICLAD #PBS -j oe
96#-Q- ifort_CICLAD ###PBS -q h12       # Queue for 12 hours at ciclad only
97#-Q- ifort_CICLAD #PBS -S /bin/ksh
98#-Q- default #!/bin/ksh
99#-Q- default ##################
100#-Q- default ## DEFAULT HOST ##
101#-Q- default ##################
102
103#**************************************************************
104# Author: Sebastien Denvil
105# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
106# $Revision::                                          $ Revision of last commit
107# $Author::                                            $ Author of last commit
108# $Date::                                              $ Date of last commit
109# IPSL (2006)
110#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
111#
112#**************************************************************
113
114#set -eu
115#set -vx
116
117date
118
119#-Q- ada export OMP_NUM_THREADS=1
120
121#D- Task type DO NOT CHANGE (computing, post-processing or checking)
122TaskType=post-processing
123
124########################################################################
125
126#D- Flag to determine if this job in a standalone mode
127#D- Default : value from AA_job if any
128StandAlone=${StandAlone:=true}
129
130#D- Path to libIGCM
131#D- Default : value from AA_job if any
132libIGCM=${libIGCM:=::modipsl::/libIGCM}
133
134#D- Flag to determine allready produced time series. Empty if you start from the beginning
135#D- Default : Value from AA_job if any. Usefull in StandAlone case if you want to continue a time series
136CompletedFlag=${CompletedFlag:=}
137
138#D- Flag to determine task type this script will perform.
139#D- Possible Value : 2D, 3D, Chunck2D, Chunck3D
140#D- Default : Value from AA_job if any. Usefull in StandAlone case.
141TsTask=${TsTask:=2D}
142if [ X${TsTask} = Xempty ] ; then
143  TsTask=""
144fi
145
146#D- Flag to determine if rebuild process has been performed asynchronously
147#D- Possible value true or false.
148#D- If true raw files has allready been patched by rebuild job
149#D- If false create_ts will patch the raw files
150#D- Default : Value from AA_job if any. Usefull in StandAlone case.
151RebuildFrequency=${RebuildFrequency:=true}
152
153#D- Flag to determine job's output directory
154#D- Default : value from libIGCM_post.ksh if any
155POST_DIR=${POST_DIR:=${PBS_O_WORKDIR:=$(pwd)}}
156
157#D- Increased verbosity (1, 2, 3)
158#D- Default : value from AA_job if any
159Verbosity=${Verbosity:=3}
160
161#D- Low level debug : to bypass lib test checks and stack construction
162#D- Default : value from AA_job if any
163DEBUG_debug=${DEBUG_debug:=false}
164
165#D- TEMPORARY Flag to determine atmospheric resolution
166#D- Default : value from atmospheric driver if any
167RESOL_ATM=${RESOL_ATM:=ALL}
168
169#D- Flag to determine surface resolution
170#D- Default : value from surface driver if any
171RESOL_SRF=${RESOL_SRF:=ALL}
172
173#D- Flag to determine surface resolution
174#D- Default : value from surface driver if any
175RESOL_SBG=${RESOL_SBG:=ALL}
176
177#D- TEMPORARY Flag to determine ocean resolution
178#D- Default : value from ocean driver if any
179RESOL_OCE=${RESOL_OCE:=ORCA2}
180
181#D- TEMPORARY Flag to determine ice resolution
182#D- Default : value from ice driver if any
183RESOL_ICE=${RESOL_OCE:=ORCA2}
184
185#D- TEMPORARY Flag to determine marine biogeochemistry resolution
186#D- Default : value from ice driver if any
187RESOL_MBG=${RESOL_OCE:=ORCA2}
188
189########################################################################
190
191. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
192. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
193. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
194#-------
195. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
196. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
197#-------
198IGCM_sys_MkdirWork ${RUN_DIR_PATH}
199IGCM_sys_Cd ${RUN_DIR_PATH}
200#-------
201( ${DEBUG_debug} ) && IGCM_debug_Check
202( ${DEBUG_debug} ) && IGCM_card_Check
203( ${DEBUG_debug} ) && IGCM_date_Check
204
205########################################################################
206
207#set -vx
208
209# Useful cleaning function
210MENAGE ()
211{
212  typeset ExistFlag
213  ExistFlag=$( IGCM_sys_RshArchive "[ -f $1/$3 ] && echo 0 || echo 1" )
214  [ ${ExistFlag} -eq 0 ] && ( IGCM_sys_RshArchive rm -f $1/$2 ;)
215}
216
217########################################################################
218
219# ------------------------------------------------------------------
220# Test if all was right before proceeding further
221# ------------------------------------------------------------------
222IGCM_debug_Verif_Exit
223
224if [ ${StandAlone} = true ] ; then
225  CARD_DIR=${SUBMIT_DIR}
226else
227  CARD_DIR=${RUN_DIR_PATH}
228
229  IGCM_sys_Get_Master ${SUBMIT_DIR}/config.card ${RUN_DIR_PATH}
230
231  IGCM_sys_Get_Master ${SUBMIT_DIR}/run.card    ${RUN_DIR_PATH}
232
233  IGCM_sys_Get_Master ${SUBMIT_DIR}/COMP        ${RUN_DIR_PATH}
234
235  IGCM_sys_Get_Master ${SUBMIT_DIR}/POST        ${RUN_DIR_PATH}
236fi
237
238#==================================
239# First of all
240#
241# Read libIGCM compatibility version in config.card
242# Read UserChoices section
243# Read Ensemble section
244# Read Post section
245# Define all netcdf output directories
246#==================================
247IGCM_config_CommonConfiguration ${CARD_DIR}/config.card
248
249# ------------------------------------------------------------------
250# Activate BigBrother so as to supervise this job
251# ------------------------------------------------------------------
252IGCM_debug_BigBro_Initialize
253
254#==================================
255# Define default value to keep compatibility with previous card: means before changes due to TGCC
256if [ X${PackDefault} = Xtrue ] ; then
257  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
258else
259  config_Post_PackFrequency=NONE
260fi
261
262#==================================
263# If pack is active then PackFrequency overule the config_UserChoices_PeriodLength
264if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
265  config_UserChoices_PeriodLength=${config_Post_PackFrequency}
266fi
267
268#
269# Determine component to take care of depending on kind of task create_ts will perform
270#
271[ ${CompToRead} ] && set -A config_ListOfComponents ${CompToRead} || IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card ListOfComponents
272#
273# Determine period for time series. Default : value from AA_job or from launch_TS if any
274#
275[ X${CompletedFlag} = X ] || CompletedFlag=$( IGCM_date_ConvertFormatToGregorian ${CompletedFlag} )
276
277DateBegin=${DateBegin:=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )}
278#
279PeriodDateEnd=${PeriodDateEnd:=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )}
280#
281# Determine Dimension of the produced time series : 2D or 3D
282if (   [ X${TsTask} = XChunck2D ] || [ X${TsTask} = X2D ] ) ; then
283  Dimension=2D
284elif ( [ X${TsTask} = XChunck3D ] || [ X${TsTask} = X3D ] ) ; then
285  Dimension=3D
286else
287  Dimension=""
288fi
289
290# ------------------------------------------------------------------
291#D- Test if all was right before entering the loop
292# ------------------------------------------------------------------
293IGCM_debug_Verif_Exit
294
295########################################################################
296#      Depending on requested time series fill following variables :
297#
298#                           - LISTE_FILE_${comp}[*]
299#                           - LISTE_VARS_${file}[*]
300#                           - LISTE_AXIS_${file}[*]
301#                           - LISTE_PATCH_${file}[*]
302########################################################################
303
304#
305# For each selected component determine which files need post-processing
306#
307DoJob=false
308for comp in ${config_ListOfComponents[*]} ; do
309  #
310  ActiveComp=false
311  #
312  IGCM_card_DefineArrayFromOption ${CARD_DIR}/config.card ListOfComponents ${comp}
313  eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
314  #
315  card=${CARD_DIR}/COMP/${compname}.card
316
317  IGCM_card_DefineArrayFromOption ${card} OutputFiles List
318  #
319  ListFilesName=${compname}_OutputFiles_List
320  eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
321  #
322  if [ X${FileName0} != X${NULL_STR} ] ; then
323    #
324    #IGCM_debug_Print 1 "Component      : ${compname}"
325    #
326    # INITIALISATION
327    #
328    typeset i
329    if [ ${FlagToRead} ] ; then
330      ((NbFiles=${FlagToRead}))
331      ((i=${NbFiles}))
332    else
333      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
334      i=2
335    fi
336    #
337    until [ $i -gt $NbFiles ]; do
338      #
339      eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
340      #
341      if [ X${flag_post} != XNONE ] ; then
342        #
343        # For each comp and each file who needs post-processing
344        # determine which variables need time series.
345        #
346        FILE=$( echo ${flag_post} | awk "-FPost_" '{print $2}' )
347        IGCM_card_DefineArrayFromOption ${card}    Post_${FILE} TimeSeriesVars${Dimension}
348        IGCM_card_DefineVariableFromOption ${card} Post_${FILE} ChunckJob${Dimension}
349        #
350        # If TimeSeriesVars list is empty we skip
351        #
352        if [ $( eval echo \${${compname}_Post_${FILE}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
353          #
354          IGCM_debug_Print 3 "Nothing to do for ${FILE} according to ${card}"
355          IGCM_debug_Print 3 "TimeSeriesVars${Dimension} for ${FILE} is empty"
356          (( i=i+3 ))
357          continue
358          #
359        fi
360        #
361        # If files/variables has been switch off by ChunckJob${Dimension}=0 we skip
362        #
363        if [ X$( eval echo \${${compname}_Post_${FILE}_ChunckJob${Dimension}} ) = XOFF ] ; then
364          IGCM_debug_Print 3 "Nothing to do for ${FILE} according to ${card}"
365          IGCM_debug_Print 3 "ChunckJob${Dimension}=OFF for ${FILE} so it has been switched off"
366          (( i=i+3 ))
367          continue
368        fi
369        #
370          # If we are not a Chunck type task, we skip files/variables handled by chunck task
371          #
372        if ( [ ! X${TsTask} = XChunck${Dimension} ] && [ ! X${TsTask} = X ] && [ ! XChunck${Dimension} = XChunck ] ) ; then
373          if [ ! $( eval echo \${${compname}_Post_${FILE}_ChunckJob${Dimension}} ) = NONE ] ; then
374            IGCM_debug_Print 3 "Nothing to do for ${FILE} TimeSeriesVars${Dimension} according to ${card}"
375            IGCM_debug_Print 3 "Let another chunck task do the job $( eval echo \${${compname}_Post_${FILE}_ChunckJob${Dimension}} )"
376            (( i=i+3 ))
377            continue
378          fi
379        fi
380        #
381        # Now on we know we have things to do
382        #
383
384        #
385        #  We need coordinates axis to properly fill produced time series
386        #
387        IGCM_card_DefineArrayFromOption ${card} Post_${FILE} GatherWithInternal
388        #
389        if [ $( eval echo \${${compname}_Post_${FILE}_GatherWithInternal} ) = ${NULL_STR} ] ; then
390          #
391          IGCM_debug_Print 1 "ERROR !! We miss coordinate axis for ${FILE} according to ${card}"
392          IGCM_debug_Print 1 "So no time series will be produced for ${FILE} !!"
393          (( i=i+3 ))
394          continue
395          #
396        fi
397        #
398        # We need LIST of variables not allready produced (useful for standalone mode)
399        #
400        FlagDir=$( echo ${FILE} | awk -F "_" '{print $1}' )
401        case ${FlagDir} in
402          *Y)  TS_Dir=TS_YE  ;;
403          *M)  TS_Dir=TS_MO  ;;
404          *D)  TS_Dir=TS_DA  ;;
405          HF)  TS_Dir=TS_HF  ;;
406          3H)  TS_Dir=TS_HF  ;;
407          INS) TS_Dir=TS_INS ;;
408        esac
409        #
410        count=0
411        for var in $( eval echo \${${compname}_Post_${FILE}_TimeSeriesVars${Dimension}[*]} ) ; do
412          #
413          DIRECTORY=${R_SAVE}/${comp}/Analyse/${TS_Dir}
414          TestedFile=${config_UserChoices_JobName}_${DateBegin}_${PeriodDateEnd}_${FlagDir}_${var}.nc
415          #
416          IGCM_sys_TestFileArchive ${DIRECTORY}/${TestedFile}
417          if [ ! $? = 0 ] ; then
418            eval set +A LISTE_VARS_${FILE} \${LISTE_VARS_${FILE}[*]} ${var}
419            ActiveComp=true
420            (( count = count + 1 ))
421          fi
422        done
423        #
424        if [ ${count} -gt 0 ] ; then
425          #
426          eval set +A LISTE_FILE_${comp} \${LISTE_FILE_${comp}[*]} ${FILE}
427          eval set +A LISTE_AXIS_${FILE} \${${compname}_Post_${FILE}_GatherWithInternal[*]}
428          #
429          if [ ! X${RebuildFrequency} = Xtrue ] ; then
430            IGCM_card_DefineArrayFromOption ${card} Post_${FILE} Patches
431            eval set +A LISTE_PATCHES_${FILE} \${${compname}_Post_${FILE}_Patches[*]}
432            if [ X$( eval echo \${LISTE_PATCHES_${FILE}[0]} ) !=  X${NULL_STR} ]; then
433              for Patch in $( eval echo \${LISTE_PATCHES_${FILE}[*]} ); do
434                if [ Xload${Patch} != X ] ; then
435                  . ${libIGCM}/libIGCM_post/IGCM_${Patch}.ksh
436                  eval load${Patch}=loaded
437                fi
438              done
439            fi
440          fi
441        fi
442      fi
443      (( i=i+3 ))
444    done
445  fi
446  #
447  if [ ${ActiveComp} = true ] ; then
448    set +A ActiveListOfComponents ${ActiveListOfComponents[*]} ${comp}
449  fi
450done
451
452set -A config_ListOfComponents ${ActiveListOfComponents[*]}
453[ ! -z "${ActiveListOfComponents}" ] && DoJob=true
454
455########################################################################
456#
457#               IS THERE SOME ALLREADY PRODUCED TIME SERIES ?
458#                 IF SO BRING THEM IN THE WORKING DIRECTORY
459#
460# PS : Keep in mind that IGCM_sys_Get here is a weak link :
461#      - especially for IDRiS
462#      - no special protection against "command too long" !
463#      - libIGCM_sys should handle that or modify following code part
464#
465########################################################################
466
467if [ ${StandAlone} != true ] ; then
468  Running_Flag=$( IGCM_sys_RshMaster "IGCM_card_DefineVariableFromOption \
469  ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesRunning ; \
470  echo \${run_PostProcessing_TimeSeriesRunning}" )
471
472  #if [ X${Running_Flag} = Xy ] ; then
473  #  # Time Series Job allready running
474  #  IGCM_debug_Print 1 "Time Series Job allready running exit"
475  #  exit
476  #fi
477  # Now run.card know we are running
478
479
480
481
482  IGCM_sys_RshMaster IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesRunning "y"
483
484
485
486
487
488  # Get information from last execution
489  #CompletedFlag=$( IGCM_sys_RshMaster \
490  # "IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted ;\
491  #        echo \${run_PostProcessing_TimeSeriesCompleted}" )
492fi
493
494# Is it the first submission or not ?
495
496if ( [ X${CompletedFlag} = X ] || [ X${CompletedFlag} = X$( IGCM_date_AddDaysToGregorianDate ${DateBegin} -1 ) ] ) ; then
497  # First Time Series Submission
498  FIRST_PASS=TRUE
499  Length=$( IGCM_date_DaysInPreviousPeriod ${DateBegin} ${config_UserChoices_PeriodLength} begin)
500  DATE_FIN_JOB_B=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( Length - 1 )) )
501else
502  # Last Completed Time Series
503  FIRST_PASS=FALSE
504  DATE_FIN_JOB_B=${CompletedFlag}
505  date=${DateBegin}_${DATE_FIN_JOB_B}
506  #
507  for comp in ${config_ListOfComponents[*]} ; do
508    #
509    IGCM_sys_Mkdir ${RUN_DIR_PATH}/${comp}
510    #
511    IGCM_sys_Cd ${RUN_DIR_PATH}/${comp}
512    #
513    unset liste_file
514    #
515    file_path=${R_SAVE}/${comp}/Analyse
516    #
517    i=0
518    file=${NULL_STR}
519    #
520    for file in $( eval echo \${LISTE_FILE_${comp}[*]} ); do
521      #
522      # Determine in which output can we find file
523      # IE : Analyse/TS or Analyse/DA2TS or ...
524      #
525      FlagDir=$( echo ${file} | awk -F "_" '{print $1}' )
526      case ${FlagDir} in
527        *Y)  TS_Dir=TS_YE  ;;
528        *M)  TS_Dir=TS_MO  ;;
529        *D)  TS_Dir=TS_DA  ;;
530        HF)  TS_Dir=TS_HF  ;;
531        3H)  TS_Dir=TS_HF  ;;
532        INS) TS_Dir=TS_INS ;;
533      esac
534      for var in $( eval echo \${LISTE_VARS_${file}[*]} ) ; do
535        #
536        IGCM_sys_TestFileArchive ${file_path}/${TS_Dir}/${config_UserChoices_JobName}_${date}_${FlagDir}_${var}.nc
537        if [ $? = 0 ] ; then
538          liste_file[${#liste_file[*]}]=${file_path}/${TS_Dir}/${config_UserChoices_JobName}_${date}_${FlagDir}_${var}.nc
539        else
540          IGCM_debug_Print 1 "WARNING ${file_path}/${TS_Dir}/${config_UserChoices_JobName}_${date}_${FlagDir}_${var}.nc dont exist"
541        fi
542        #
543      done
544    done
545    if [ X${file} != X${NULL_STR} ] ; then
546      IGCM_sys_Get /l liste_file[*] ${RUN_DIR_PATH}/${comp}
547      IGCM_debug_Verif_Exit
548    fi
549  done
550  #
551  LEVEL=0
552  #
553fi
554
555########################################################################
556#
557#                          DEFINE LOOP PARAMETERS
558#
559########################################################################
560
561DATE_COUNT=${DATE_FIN_JOB_B}
562DATE_FIN_JOB_B_LOOP=${DATE_FIN_JOB_B}
563
564( [ -n "${LEVEL}" ] && [ ${LEVEL} -eq 0 ] ) && NBRE_FILE_TOT=0 || NBRE_FILE_TOT=1
565
566if [ ${DoJob} = true ] ; then
567  while [ ${DATE_COUNT} -lt ${PeriodDateEnd} ] ; do
568    (( NBRE_FILE_TOT = NBRE_FILE_TOT + 1 ))
569    Length=$( IGCM_date_DaysInNextPeriod ${DATE_COUNT} ${config_UserChoices_PeriodLength} )
570    DATE_COUNT=$( IGCM_date_AddDaysToGregorianDate ${DATE_COUNT} ${Length} )
571  done
572else
573  NBRE_FILE_TOT=0
574fi
575
576if [ ${NBRE_FILE_TOT} -le ${UNIX_MAX_LIMIT} ] ; then
577  NBRE_TOUR=1
578elif [ ${NBRE_FILE_TOT}%${UNIX_MAX_LIMIT} -eq 0 ] ; then
579  let NBRE_TOUR=${NBRE_FILE_TOT}/${UNIX_MAX_LIMIT}
580else
581  let NBRE_TOUR=${NBRE_FILE_TOT}/${UNIX_MAX_LIMIT}+1
582fi
583
584CURRENT_LOOP=1
585# THIS LOOP GIVES PARAMETERS FOR THE DATE'S LOOP ie : DATE_COURANTE, DATE_FIN.
586# WE HAVE 3 LEVELS
587#    - LEVEL 1 : JUST ONE LOOP TO COMPLETE
588#    - LEVEL 2 : WE ARE IN THE "DEEP" LOOP
589#    - LEVEL 3 : WE ARE IN THE LAST LOOP
590
591while [ ${CURRENT_LOOP} -le  ${NBRE_TOUR} ] ; do
592
593  if [ ${NBRE_FILE_TOT} -le ${UNIX_MAX_LIMIT} ] ; then
594    # - LEVEL 1 : JUST ONE LOOP TO COMPLETE
595    NBRE_FILE_LOOP=${NBRE_FILE_TOT}
596
597    if [ ${FIRST_PASS} = TRUE ] ; then
598      DATE_COURANTE=${DATE_FIN_JOB_B_LOOP}
599    else
600      Length=$( IGCM_date_DaysInNextPeriod ${DATE_FIN_JOB_B_LOOP} ${config_UserChoices_PeriodLength} )
601      DATE_COURANTE=$( IGCM_date_AddDaysToGregorianDate ${DATE_FIN_JOB_B_LOOP} ${Length} )
602    fi
603
604    DATE_FIN=${PeriodDateEnd}
605    DATE_FIN_JOB_B_LOOP_PREC=${DATE_FIN_JOB_B_LOOP}
606
607    [ -n "${DATE_LOOP}" ] && DATE_FIN_JOB_B_LOOP=${DATE_LOOP}
608    [ -n "${LEVEL}" ] && FLAG_B="TRUE" || FLAG_B="FALSE"
609
610    LEVEL=1
611    DEPOT="TRUE"
612  elif [ ${CURRENT_LOOP} -ne  ${NBRE_TOUR} ] ; then
613    # - LEVEL 2 : WE ARE IN THE "DEEP" LOOP
614    NBRE_FILE_LOOP=${UNIX_MAX_LIMIT}
615
616    if [ ! ${FIRST_PASS} = TRUE ] && [ ${CURRENT_LOOP} -eq 1 ] ; then
617      Length=$( IGCM_date_DaysInNextPeriod ${DATE_FIN_JOB_B_LOOP} ${config_UserChoices_PeriodLength} )
618      DATE_COURANTE=$( IGCM_date_AddDaysToGregorianDate ${DATE_FIN_JOB_B_LOOP} ${Length} )
619    elif [ -z "${DATE_COURANTE}" ] ; then
620      DATE_COURANTE=${DATE_FIN_JOB_B}
621    else
622      Length=$( IGCM_date_DaysInNextPeriod ${DATE_FIN} ${config_UserChoices_PeriodLength} )
623      DATE_COURANTE=$( IGCM_date_AddDaysToGregorianDate ${DATE_FIN} ${Length} )
624    fi
625
626    (( TotLength = 0 ))
627    COMPTEUR=1
628    DATE_LOOP=${DATE_COURANTE}
629
630    while [ ${COMPTEUR} -lt ${NBRE_FILE_LOOP} ] ; do
631      #
632      Length=$( IGCM_date_DaysInNextPeriod ${DATE_LOOP} ${config_UserChoices_PeriodLength} )
633      DATE_LOOP=$( IGCM_date_AddDaysToGregorianDate ${DATE_LOOP} ${Length} )
634      (( TotLength = TotLength + Length ))
635      (( COMPTEUR = COMPTEUR + 1 ))
636      #
637    done # while [ ${COMPTEUR} -le ${NBRE_FILE_LOOP} ] done
638    DATE_FIN=$( IGCM_date_AddDaysToGregorianDate ${DATE_COURANTE} ${TotLength} )
639
640    [ -n "${DATE_LOOP}" ] && DATE_FIN_JOB_B_LOOP_PREC=${DATE_FIN_JOB_B_LOOP} ; DATE_FIN_JOB_B_LOOP=${DATE_LOOP}
641    [ -n "${LEVEL}" ] && [ ${LEVEL} -eq 0 ] && FLAG_B="TRUE" || [ ${CURRENT_LOOP} -gt 1 ] && FLAG_B="TRUE" || FLAG_B="FALSE"
642    DEPOT="FALSE"
643    LEVEL=2
644  else
645    # - LEVEL 3 : WE ARE IN THE LAST LOOP
646    NBRE_FILE_LOOP=$(( ${NBRE_FILE_TOT} % ( ${UNIX_MAX_LIMIT} * ( ${CURRENT_LOOP} - 1 ) ) ))
647    [ ${NBRE_FILE_LOOP} -eq 0 ] && NBRE_FILE_LOOP=${UNIX_MAX_LIMIT}
648
649    Length=$( IGCM_date_DaysInNextPeriod ${DATE_FIN} ${config_UserChoices_PeriodLength} )
650    DATE_COURANTE=$(IGCM_date_AddDaysToGregorianDate ${DATE_FIN} ${Length} )
651    DATE_FIN=${PeriodDateEnd}
652    [ -n "${DATE_LOOP}" ] && DATE_FIN_JOB_B_LOOP_PREC=${DATE_FIN_JOB_B_LOOP} ; DATE_FIN_JOB_B_LOOP=${DATE_LOOP}
653
654    LEVEL=3
655    DEPOT="TRUE"
656    FLAG_B="TRUE"
657  fi
658
659  # THEN FOR EACH FILE TYPE WE LOOP BETWEEN DATE_COURANTE AND DATE_FIN.
660  for comp in ${config_ListOfComponents[*]} ; do
661    #
662    IGCM_sys_Mkdir ${RUN_DIR_PATH}/${comp}
663      #
664    IGCM_sys_Cd ${RUN_DIR_PATH}/${comp}
665    #
666    eval R_OUT_${comp}=${R_SAVE}/${comp}
667    #
668    i=0
669    #
670    for file in $( eval echo \${LISTE_FILE_${comp}[*]} ); do
671      #
672      # Determine in which output we can find file
673      # IE : Output/MO or Output/DA or ...
674      #
675      FlagDir=$( echo ${file} | awk -F "_" '{print $1}' )
676      case ${FlagDir} in
677        *Y)    TS_Dir=TS_YE  ; FreqDir=YE  ;;
678        *M)    TS_Dir=TS_MO  ; FreqDir=MO  ;;
679        *D)    TS_Dir=TS_DA  ; FreqDir=DA  ;;
680        HF)    TS_Dir=TS_HF  ; FreqDir=HF  ;;
681        3H)    TS_Dir=TS_HF  ; FreqDir=HF  ;;
682        INS)   TS_Dir=TS_INS ; FreqDir=INS ;;
683        *)     IGCM_debug_Print 1 "Error in FlagDir=${FlagDir} for file ${file}."
684               IGCM_debug_Exit "Job create_ts" ;;
685      esac
686
687      # Initialize array
688      unset liste_file
689      unset liste_file_tmp
690      eval file_path=\${R_OUT_${comp}}/Output/${FreqDir}/
691
692      COMPTEUR=1
693      MissingFile=FALSE
694      DATE_LOOP=${DATE_COURANTE}
695
696      while [ ${COMPTEUR} -le ${NBRE_FILE_LOOP} ] ; do
697        #
698        Length1=$( IGCM_date_DaysInPreviousPeriod ${DATE_LOOP} ${config_UserChoices_PeriodLength} end)
699        DATE_TAB=$(  IGCM_date_AddDaysToGregorianDate ${DATE_LOOP} $(( 1 - Length1 )) )_${DATE_LOOP}
700
701        Length2=$( IGCM_date_DaysInNextPeriod ${DATE_LOOP} ${config_UserChoices_PeriodLength} )
702        DATE_LOOP=$( IGCM_date_AddDaysToGregorianDate ${DATE_LOOP} ${Length2} )
703
704        IGCM_sys_TestFileArchive ${file_path}${config_UserChoices_JobName}_${DATE_TAB}_${file}.nc
705        if [ $? = 0 ] ; then
706          liste_file[${#liste_file[*]}]=${file_path}${config_UserChoices_JobName}_${DATE_TAB}_${file}.nc
707          liste_file_tmp[${#liste_file_tmp[*]}]=${config_UserChoices_JobName}_${DATE_TAB}_${file}.nc
708        else
709          IGCM_debug_Print 1 "WARNING ${file_path}${config_UserChoices_JobName}_${DATE_TAB}_${file}.nc dont exist"
710          MissingFile=TRUE
711        fi
712        (( COMPTEUR = COMPTEUR + 1 ))
713        #
714      done # while [ ${COMPTEUR} -le ${NBRE_FILE_LOOP} ] done
715
716      # We skip this file type if one of them is missing.
717      if [ "${MissingFile}" = "TRUE" ] ; then
718        IGCM_debug_Print 1 "WARNING We skip ${file} type processing"
719        continue
720      fi
721
722      DATE_LOOP=$( IGCM_date_AddDaysToGregorianDate ${DATE_LOOP} -${Length2} )
723
724      # Get selected files
725      IGCM_sys_Get /l liste_file[*] ${RUN_DIR_PATH}/${comp}
726      IGCM_debug_Verif_Exit
727
728      # Apply IGCM_Patch if needed
729      if [ ! X${RebuildFrequency} = Xtrue ] ; then
730        if [ X$( eval echo \${LISTE_PATCHES_${file}[0]} ) !=  X${NULL_STR} ]; then
731          for file_t in $( eval echo ${liste_file_tmp[*]} ); do
732            for Patch in $( eval echo \${LISTE_PATCHES_${file}[*]} ); do
733              IGCM_${Patch} ${file_t}
734              IGCM_debug_Verif_Exit
735            done
736          done
737        fi
738      fi
739
740      # WE CAN CONCATENATE FILES AT THIS POINT
741      [ "${FLAG_B}" = "TRUE" ] && DATE_BUILD_B=${DateBegin}_${DATE_FIN_JOB_B_LOOP_PREC}
742      Length=$( IGCM_date_DaysInPreviousPeriod ${DATE_COURANTE} ${config_UserChoices_PeriodLength} end)
743      DATE_BUILD1=$( IGCM_date_AddDaysToGregorianDate ${DATE_COURANTE} -$(( Length - 1 )) )
744      DATE_BUILD=${DATE_BUILD1}_${DATE_FIN}
745      DATE_BUILD_END=${DateBegin}_${DATE_FIN}
746
747      liste_coord=" "
748      for axis in $( eval echo \${LISTE_AXIS_${file}[*]} ); do
749        liste_coord=${liste_coord}${axis}","
750      done
751
752      # Time axis must be the last dimension
753      time_axis=${axis}
754
755      # SWITCH BETWEEN MODEL TO FIT PARTICULAR CASE
756      for var in $( eval echo \${LISTE_VARS_${file}[*]} ) ; do
757        #
758        # We skip variables not in the first file of the list.
759        # Seems overkill to test thel all... but will do if needed
760        ncdump -hv ${var} ${liste_file_tmp[0]} > /dev/null 2>&1
761        if [ ! $? = 0 ] ; then
762          IGCM_debug_Print 1 "WARNING We skip ${var}, not present within ${liste_file_tmp[0]}"
763          continue
764        fi
765        #
766        if [ "${FLAG_B}" = "TRUE" ] ; then
767          # WE CONCATENATE WITH EXISTING FILES
768          file1=${config_UserChoices_JobName}_${DATE_BUILD_B}_${FlagDir}_${var}.nc
769          file_out=${config_UserChoices_JobName}_${DATE_BUILD_END}_${FlagDir}_${var}.nc
770          IGCM_sys_ncrcat --hst -v ${liste_coord}${var} ${file1} ${liste_file_tmp[*]} ${file_out}
771          IGCM_debug_Verif_Exit
772          #
773          IGCM_sys_Rm ${file1}
774          if [ ! "${DEPOT}" = "TRUE" ] ; then
775            eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}}/Analyse/${TS_Dir}/${file_out}
776            # "${file1} = file_before ?
777            [ ! "${file1}" = "${config_UserChoices_JobName}_${DateBegin}_${DATE_FIN_JOB_B}_${FlagDir}_${var}.nc" ] && eval MENAGE \${R_OUT_${comp}}/Analyse/${TS_Dir} ${file1} ${file_out}
778          fi
779        else
780          # OR NOT
781          file_out=${config_UserChoices_JobName}_${DATE_BUILD}_${FlagDir}_${var}.nc
782          IGCM_sys_ncrcat --hst -v ${liste_coord}${var} ${liste_file_tmp[*]} ${file_out}
783          IGCM_debug_Verif_Exit
784        fi
785
786        #
787        if [ "${DEPOT}" = "TRUE" ] ; then
788          # WE PUT FINAL FILE ON FILE SYSTEM
789          [ "${FLAG_B}" = "FALSE" ] && file_out=${config_UserChoices_JobName}_${DATE_BUILD}_${FlagDir}_${var}.nc
790          file_before=${config_UserChoices_JobName}_${DateBegin}_${DATE_FIN_JOB_B}_${FlagDir}_${var}.nc
791          #
792          eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}}/Analyse/${TS_Dir}/${file_out}
793          [ "${FLAG_B}" = "TRUE" ] && eval MENAGE \${R_OUT_${comp}}/Analyse/${TS_Dir} ${file_before} ${file_out}
794          if [ ! "X${file1}" = "X" ] ; then
795            [ ! "${file1}" = "${config_UserChoices_JobName}_${DateBegin}_${DATE_FIN_JOB_B}_${FlagDir}_${var}.nc" ] && eval MENAGE \${R_OUT_${comp}}/Analyse/${TS_Dir} ${file1} ${file_out}
796          fi
797          #
798          [ -f ${file_out} ] && IGCM_sys_Rm ${file_out}
799          #
800        fi
801        #
802      done                              # for var in ${liste_var} ; do
803      IGCM_sys_Rm ${liste_file_tmp[*]}
804    done                                # for file in ${liste_file_brut} do
805  done                                  # for comp in ${config_ListOfComponents[*]} ; do
806  # GO AHEAD IN DEEPEST LOOP
807  (( CURRENT_LOOP = CURRENT_LOOP + 1 ))
808done                                    # while [ ${CURRENT_LOOP} -le  ${NBRE_TOUR} ] do
809# FINISH
810
811# DODS copy
812for comp in ${config_ListOfComponents[*]} ; do
813  for TS_Dir in TS_YE TS_MO TS_DA TS_HF TS_INS ; do
814    IGCM_sys_TestDirArchive ${R_SAVE}/${comp}/Analyse/${TS_Dir}
815    [ $? = 0 ] && IGCM_sys_Put_Dods ${comp}/Analyse/${TS_Dir}
816  done
817done
818
819export DEBUG_debug; export BigBrother ; export libIGCM; export SUBMIT_DIR; export POST_DIR; export Script_Output ;
820export StandAlone ; export RESOL_ATM; export RESOL_OCE ; export RESOL_ICE ; export RESOL_MBG ; export RESOL_SRF ;
821export RESOL_SBG
822listVarEnv="DEBUG_debug,BigBrother,libIGCM,SUBMIT_DIR,POST_DIR,Script_Post_Output,StandAlone,RESOL_ATM,RESOL_OCE,RESOL_ICE,RESOL_MBG,RESOL_SRF,RESOL_SBG"
823export listVarEnv
824
825#D-
826# --------------------------------------------------------------------
827#D- Test if all was right
828# --------------------------------------------------------------------
829IGCM_debug_Verif_Exit
830# --------------------------------------------------------------------
831#D- Submit MONITORING and C-ESM-EP
832# --------------------------------------------------------------------
833if ( [ X${TsTask} = X2D ] || [ X${TsTask} = X3D ] || [ X${TsTask} = X ] ) ; then
834  # From 2D and 3D it is the last one to finish that will submit the monitoring.
835  if ( [ $( ls ${POST_DIR}/create_ts.${PeriodDateEnd}.[23]D.out | wc -l ) = 1 ] || [ ! "X$( grep "IGCM_sys_RmRunDir" ${POST_DIR}/create_ts.${PeriodDateEnd}.[23]D.out 2> /dev/null )" = "X" ] ) ; then
836    Script_Post_Output=monitoring.${PeriodDateEnd}
837    IGCM_sys_QsubPost monitoring
838    if [ $PostCesmep = TS ] ; then
839        ${SUBMIT_DIR}/cesmep_lite/libIGCM_post.sh $DateBegin $PeriodDateEnd
840    fi
841  fi
842fi
843#D-
844# --------------------------------------------------------------------
845#D- Update the run.card
846# --------------------------------------------------------------------
847if [ ${StandAlone} != true ] ; then
848  # Put in run.card end period of time series
849  [ X"${DATE_FIN}" = X ] || IGCM_sys_RshMaster IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted "${DATE_FIN}"
850  # We have finish the job !
851  IGCM_sys_RshMaster IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesRunning "n"
852fi
853
854# Clean RUN_DIR_PATH (necessary for cesium and titane only)
855IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
856
857# ------------------------------------------------------------------
858# Finalize BigBrother to inform that the jobs end
859# ------------------------------------------------------------------
860IGCM_debug_BigBro_Finalize
861
862date
Note: See TracBrowser for help on using the repository browser.