source: trunk/libIGCM/AA_create_ts @ 1438

Last change on this file since 1438 was 1437, checked in by jgipsl, 6 years ago

For Irene:

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