source: trunk/libIGCM/AA_create_ts @ 1449

Last change on this file since 1449 was 1448, checked in by jgipsl, 6 years ago

Change in headers at irene : temporary remove option -m and use a workaround given by the TGCC. This change is done to avoid problems with resubmitting from job when submitting the main job from workdir.

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