source: trunk/libIGCM/AA_create_ts @ 1520

Last change on this file since 1520 was 1494, checked in by cetlod, 5 years ago

Use prepost partition to manage Pots-processing

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