source: trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh @ 1603

Last change on this file since 1603 was 1603, checked in by aclsce, 7 months ago
  • Changed libIGCM behaviour in case of pb in pack_output.job : now, we exit from the job if there is any problem, whatever we are in PROD, DEVT, TEST mode.
  • Specification of pack frequency per file :

In order to reduce the number of inodes, it is possible to specify by file the frequency of packing. The syntax to do that is in the 4th column of OutputFiles? section of the component.card, for example as follows in lmdz.card :
[OutputFiles?]
List= (histmth.nc, ${R_OUT_ATM_O_M}/${PREFIX}_1M_histmth.nc, Post_1M_histmth, 100Y), \

(histday.nc, ${R_OUT_ATM_O_D}/${PREFIX}_1D_histday.nc, Post_1D_histday, 10Y), \

...

In this example, histmth files will be packed every 100 years and histday files will be packed every 10 years.
The pack frequency you defined in config.card is the frequency of pack by default, that means if a specific frequency of pack is specified for a file in a component.card, this file will be packed at the specific frequency whereas all other files will be packed at global pack frequency (specified in config.card) and in this case, the frequency pack (from the config.card) is the frequency the pack_output job will be launched at.
There is a constraint to use this fonctionality : the Packfrequency you defined in config.card must be greater or equal to the pack frequencies you specified for each type of file in component.card, otherwise the computing job will be stopped (with an explicit error message).
Surpack mode :
A surpack mode functionality is available through the use of pack_output.job. To enable this functionality, you have to put "surpack_mode=y" (default value is n). The way to use is similar to restart post-processing pack_output jobs, as indicated here : http://forge.ipsl.jussieu.fr/igcmg_doc/wiki/Doc/CheckDebug#RestartPack_output. You can either use a global pack frequency in config.card or specific pack frequency per file, as explained above.

  • 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: 79.3 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#========================================================================
15function IGCM_comp_Initialize
16{
17  IGCM_debug_PushStack "IGCM_comp_Initialize"
18
19  # Debug Print :
20  echo
21  IGCM_debug_Print 1 "IGCM_comp_Initialize"
22  echo
23
24  typeset comp compname comptagname auxprint card_UserChoices first_option option i j
25  for comp in ${config_ListOfComponents[*]} ; do
26
27    # Define component
28    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
29    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
30    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
31
32    # Debug Print
33    IGCM_debug_Print 1 "Initialize ${comp} : ${compname} component."
34
35    # ${compname}.card PATH
36    card=${SUBMIT_DIR}/COMP/${compname}.card
37
38    # Manage component executable
39    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card Executable ${comp}
40
41    # Define all options in section [comp]
42    IGCM_debug_Print 3 " DefineArrayFromSection : ${comp}"
43    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ${comp}
44    eval config_comp=\${config_${comp}[*]} > /dev/null 2>&1
45    for option in ${config_comp[*]} ; do
46        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} ${option}
47    done
48    IGCM_debug_Print 3 " Found in section config_${comp} :  ${config_comp[*]} "
49
50    # Debug Print :
51    eval auxprint=\${config_${comp}_WriteFrequency}
52    IGCM_debug_Print 1 "Write frequency for ${compname} : ${auxprint} "
53    #2> /dev/null
54
55    # Debug Print :
56    IGCM_debug_Print 2 "Initialize following component library"
57
58    # Source drivers in directory DRIVER if it exist
59    # else source them from directory COMP
60    if [ -d ${SUBMIT_DIR}/DRIVER ] ; then
61      IGCM_debug_Print 2 ${SUBMIT_DIR}/DRIVER/${compname}.driver
62      # Source component library
63      . ${SUBMIT_DIR}/DRIVER/${compname}.driver
64    else
65      IGCM_debug_Print 2 ${SUBMIT_DIR}/COMP/${compname}.driver
66      # Source component library
67      . ${SUBMIT_DIR}/COMP/${compname}.driver
68    fi
69    IGCM_debug_Print 3 "With tag : ${comptagname}"
70
71    # Debug Print
72    IGCM_debug_Print 3 "Initialize ${comp} output directory."
73
74    # Define ARCHIVED Dirs
75    eval R_OUT_${comp}=${R_SAVE}/${comp}
76    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}}
77
78    eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output
79    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O}
80
81    eval R_OUT_${comp}_A=\${R_OUT_${comp}}/Analyse
82    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_A}
83
84    eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart
85    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R}
86
87    eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug
88    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D}
89
90    eval R_OUT_${comp}_O_H=\${R_OUT_${comp}_O}/HF
91    eval R_OUT_${comp}_O_D=\${R_OUT_${comp}_O}/DA
92    eval R_OUT_${comp}_O_M=\${R_OUT_${comp}_O}/MO
93    eval R_OUT_${comp}_O_Y=\${R_OUT_${comp}_O}/YE
94
95    eval R_OUT_${comp}_A_H=\${R_OUT_${comp}_A}/TS_HF
96    eval R_OUT_${comp}_A_D=\${R_OUT_${comp}_A}/TS_DA
97    eval R_OUT_${comp}_A_M=\${R_OUT_${comp}_A}/TS_MO
98    eval R_OUT_${comp}_A_Y=\${R_OUT_${comp}_A}/TS_YE
99
100    # Define BUFFERED Dirs
101    if ( [ ! ${config_Post_PackFrequency} = NONE ] || [ X${config_UserChoices_SpaceName} = XTEST ] ) ; then
102      eval R_BUF_${comp}=${R_BUFR}/${comp}
103      eval IGCM_sys_Mkdir \${R_BUF_${comp}}
104
105      eval R_BUF_${comp}_O=\${R_BUF_${comp}}/Output
106      eval IGCM_sys_Mkdir \${R_BUF_${comp}_O}
107
108      eval R_BUF_${comp}_A=\${R_BUF_${comp}}/Analyse
109      eval IGCM_sys_Mkdir \${R_BUF_${comp}_A}
110
111      eval R_BUF_${comp}_R=\${R_BUF_${comp}}/Restart
112      eval IGCM_sys_Mkdir \${R_BUF_${comp}_R}
113
114      eval R_BUF_${comp}_D=\${R_BUF_${comp}}/Debug
115      eval IGCM_sys_Mkdir \${R_BUF_${comp}_D}
116
117      eval R_BUF_${comp}_O_H=\${R_BUF_${comp}_O}/HF
118      eval R_BUF_${comp}_O_D=\${R_BUF_${comp}_O}/DA
119      eval R_BUF_${comp}_O_M=\${R_BUF_${comp}_O}/MO
120      eval R_BUF_${comp}_O_Y=\${R_BUF_${comp}_O}/YE
121
122      eval R_BUF_${comp}_A_H=\${R_BUF_${comp}_A}/TS_HF
123      eval R_BUF_${comp}_A_D=\${R_BUF_${comp}_A}/TS_DA
124      eval R_BUF_${comp}_A_M=\${R_BUF_${comp}_A}/TS_MO
125      eval R_BUF_${comp}_A_Y=\${R_BUF_${comp}_A}/TS_YE
126
127      # Define CMIP6 Dirs
128      eval CMIP6_BUF_${comp}=${R_CMIP}/CMIP6/${comp}
129    fi
130
131    # Read UserChoices section of component card
132    IGCM_debug_Print 2 "DefineArrayFromSection : ${compname}_UserChoices ${card}"
133    IGCM_card_DefineArrayFromSection ${card} UserChoices
134    eval first_option=\${${compname}_UserChoices[0]} > /dev/null 2>&1
135
136    # If section is not empty we define corresponding variables
137    if [ X${first_option} != X"Error:" ] ; then
138      if [ X${card_UserChoices[0]} != X ] ; then
139        unset card_UserChoices
140      fi
141      eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1
142      IGCM_debug_Print 3 "${compname}_UserChoices_values:"
143      for option in ${card_UserChoices[*]} ; do
144        IGCM_card_DefineVariableFromOption ${card} UserChoices ${option}
145        eval IGCM_debug_Print 3 "${option}=\${${compname}_UserChoices_${option}}"
146      done
147    fi
148
149    # Read and Build Output File stuff
150    IGCM_debug_Print 2 "DefineArrayFromOption  : ${compname}_OutputFiles ${card}"
151    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
152    ListFilesName=${compname}_OutputFiles_List
153    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
154    #
155    if [ X${FileName0} != X${NULL_STR} ] ; then
156      #
157      #IGCM_debug_Print 1 "Component      : ${compname}"
158      #
159      # INITIALISATION
160      #
161      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
162      #
163      i=2
164      #
165      until [ $i -ge $NbFiles ]; do
166        #
167        eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
168        #
169        if [ X${flag_post} != XNONE ] ; then
170          #
171          # First of all
172          #
173          IGCM_card_DefineArrayFromSection ${card} ${flag_post}
174          # This section is mandatory
175          if [ "X$( eval echo \${${compname}_${flag_post}[@]} )" = "X" ] ; then
176            IGCM_debug_Print 1 "IGCM_card_DefineArrayFromSection ${card} ${flag_post}"
177            IGCM_debug_Exit "${flag_post} section do not exist in ${card}. Please check your card."
178            IGCM_debug_Verif_Exit
179          fi
180          #
181          # Seasonal case : If option Seasonal is not found (old cards) put SEASONAL ON by default
182          #
183          # variable option allready typeset above
184          for option in $( eval echo \${${compname}_${flag_post}[*]} ) ; do
185            if [ ${option} = Seasonal ] ; then
186              FoundSeasonal=true
187              IGCM_card_DefineVariableFromOption ${card} ${flag_post} Seasonal
188            fi
189          done
190          #
191          if [ ! X${FoundSeasonal} = Xtrue ] ; then
192            eval ${compname}_${flag_post}_Seasonal=ON
193          fi
194          #
195          if [ $( eval echo \${${compname}_${flag_post}_Seasonal} ) = ON ] ; then
196            Seasonal=true
197          fi
198
199          # Dimension = vide si vieille card.
200          IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars
201          IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches
202          if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not" ] ; then
203            # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob.
204            ListDimension[0]=2D
205            ListDimension[1]=3D
206            TimeSeries=false
207            iLoop=${#ListDimension[*]}
208            j=0
209            until [ $j -ge ${iLoop} ]; do
210              Dimension=${ListDimension[${j}]}
211              IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension}
212              IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension}
213              #
214              # Time series WITHOUT chunk
215              #
216              if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
217                if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then
218                  IGCM_debug_Print 3 "${Dimension} time series activated for ${flag_post}"
219                  eval TimeSeries${Dimension}=true
220                fi
221              fi
222              #
223              # Time series WITH chunk
224              #
225              if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
226                chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} )
227                if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
228                  IGCM_debug_Print 3 "${Dimension} time series activated with chunck for ${flag_post}"
229                  eval TimeSeriesChunck${Dimension}=true
230                  eval CHUNCK${Dimension}_COMP[\${#CHUNCK${Dimension}_COMP[*]}]=${comp}
231                  eval CHUNCK${Dimension}_FLAG[\${#CHUNCK${Dimension}_FLAG[*]}]=${i}
232                  eval CHUNCK${Dimension}_NAME[\${#CHUNCK${Dimension}_NAME[*]}]=${flag_post}
233                  eval CHUNCK${Dimension}_SIZE[\${#CHUNCK${Dimension}_SIZE[*]}]=${chunck_size}
234                fi
235              fi
236              (( j=j+1 ))
237            done
238          else
239            ListDimension[0]=""
240            TimeSeries=true
241            TimeSeries2D=false
242            TimeSeries3D=false
243            TimeSeriesChunck2D=false
244            TimeSeriesChunck3D=false
245          fi
246        fi
247        ((i_ = i +1))
248        eval Testvar_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
249        eval Testvar=${Testvar_}
250        if [[ ${Testvar} =~ [0-9][DMY]$ ]] ; then
251            ((i = i+4))
252        else
253        (( i=i+3 ))
254        fi
255      done
256    fi
257    # Debug Print
258    IGCM_debug_Print 3 "Initialize ${compname} with driver."
259    # INIT component
260    ${comp}_Initialize
261    echo
262  done
263
264  IGCM_debug_PopStack "IGCM_comp_Initialize"
265}
266
267#=======================================================================
268function IGCM_comp_PrepareDeletedFiles
269{
270  IGCM_debug_PushStack "IGCM_comp_PrepareDeletedFiles" $@
271
272  if [ X${2} != X. ] ; then
273    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${2} ) > /dev/null 2>&1
274  else
275    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${1} ) > /dev/null 2>&1
276  fi
277
278  IGCM_debug_PopStack "IGCM_comp_PrepareDeletedFiles"
279}
280
281#=======================================================================
282function IGCM_comp_PrepareXiosFiles
283{
284  IGCM_debug_PushStack "IGCM_comp_PrepareXiosFiles" $@
285
286  typeset file
287  [ X${2} != X. ] && file=$( basename ${2} ) || file=$( basename ${1} )
288
289  if [ $( echo ${file} | grep "^field_def_" | wc -l ) = 1 ] ; then
290    eval FieldDef[${#FieldDef[@]}]=${file} > /dev/null 2>&1
291  fi
292  if [ $( echo ${file} | grep "^file_def_" | wc -l ) = 1 ] ; then
293    eval FileDef[${#FileDef[@]}]=${file} > /dev/null 2>&1
294  fi
295  if [ $( echo ${file} | grep "^timeseries_def_" | wc -l ) = 1 ] ; then
296    eval FileDef[${#FileDef[@]}]=${file} > /dev/null 2>&1
297  fi
298 
299  IGCM_debug_PopStack "IGCM_comp_PrepareXiosFiles"
300}
301
302#=======================================================================
303function IGCM_comp_GetInputInitialStateFiles
304{
305  IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles"
306
307  # Debug Print :
308  echo
309  IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles"
310  echo
311
312  # Only the first time step need InitialStateFiles
313  # otherwise it's BoundaryConditions
314  if ( ${FirstInitialize} ) ; then
315    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
316    typeset file_in_ file_in file_out_ file_out do_init
317    for comp in ${config_ListOfComponents[*]} ; do
318      # Initialize
319      do_init="y"
320      # Do we need to bring initial state file for this component
321      if ( [ "${config_Restarts_OverRule}" = "y" ] || [ "${config_Restarts_OverRule}" = "Y" ] ) ; then
322        eval do_init="n"
323      else
324        # Read component Restarts parameters
325        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
326        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
327        if [ "${do_start}" = "y" ] ; then
328          do_init="n"
329        else
330          do_init="y"
331        fi
332      fi
333
334      if [ "${do_init}" = "y" ] ; then
335        # Define component
336        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
337        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
338
339        # Debug Print :
340        IGCM_debug_Print 3 "Initialisation files ${compname}"
341
342        card=${SUBMIT_DIR}/COMP/${compname}.card
343
344        IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List
345        ListFilesName=${compname}_InitialStateFiles_List
346
347        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
348        if [ X${FileName0} != X${NULL_STR} ] ; then
349          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
350          (( i=0 ))
351          until [ $i -ge $NbFiles ]; do
352            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
353            eval file_in=${file_in_}
354            (( i_ = i+1 ))
355            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
356            eval file_out=${file_out_}
357
358            IGCM_sys_IsFileArchived ${file_in}
359            if [ $? = 0 ] ; then
360              IGCM_sys_Get ${file_in} ${file_out}
361              #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
362            else
363              IGCM_sys_Cp ${file_in} ${file_out}
364            fi
365            (( i=i+2 ))
366          done
367        fi
368      fi
369    done
370  fi
371  IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles"
372}
373
374#=======================================================================
375# Definition of Smooth modulo function
376# usage :
377# IGCM_SmoothModulo StringModulo value
378#
379# StringModulo : A string of min max and modulo like definition of Scilab vectors.
380# [min]:[modulo:][max]
381# where :
382# [] value are optionnals;
383# empty min equal 1
384# empty max equal infinity
385# modulo not given or empty equal 1
386# empty string or just ':' equal always.
387#
388# value : the value to test with the definition
389#
390# return : true(1)/false(0)
391function IGCM_SmoothModulo
392{
393  IGCM_debug_PushStack "IGCM_SmoothModulo"
394  typeset defVector ModValue
395
396  eval set +A defVector -- $( echo "${1}" | \
397    gawk -F ':' '{print ($1 == "" ? 1 : $1) " " (NF==3 ? ($2 == "" ? 1 : $2) : 1) " " (NF==3 ? ($3 == "" ? -1 : $3) : ($2 == "" ? -1 : $2))}' )
398
399  # Save Smooth Min and Max. Needed to call IGCM_sys_Get when appropriate
400  arr[1]=${defVector[0]}
401  arr[2]=${defVector[2]}
402
403  # Test limits :
404  # ${defVector[0]} <= ${2} <= ${defVector[2]}
405  #          or ${defVector[2]} == -1
406  if ( [ ${2} -ge ${defVector[0]} ] && ( [ ${2} -le ${defVector[2]} ] || [ ${defVector[2]} -lt 0 ] ) ) ; then
407    # Test modulo
408    ModValue=$( expr \( ${2} - ${defVector[0]} \) % ${defVector[1]} )
409    if [ ${ModValue} -eq 0 ] ;  then
410      arr[3]=true
411      echo ${arr[@]}
412      IGCM_debug_PopStack "IGCM_SmoothModulo"
413      return 1
414    else
415      arr[3]=false
416      echo ${arr[@]}
417      IGCM_debug_PopStack "IGCM_SmoothModulo"
418      return 0
419    fi
420  else
421    arr[3]=false
422    echo ${arr[@]}
423    IGCM_debug_PopStack "IGCM_SmoothModulo"
424    return 0
425  fi
426}
427
428#=======================================================================
429function IGCM_comp_GetInputSmoothFiles
430{
431  IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles"
432
433  # Debug Print :
434  echo
435  IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles"
436  echo
437
438  typeset comp compname comptagname card ListFilesName FileName0 NbFiles j i i_ i__
439  typeset file_in_ file_in file_out_ file_out ret SmoothDef aux val
440
441  for comp in ${config_ListOfComponents[*]} ; do
442    # Define component
443    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
444    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
445
446    # Debug Print :
447    IGCM_debug_Print 3 "Smooth files ${compname}"
448
449    card=${SUBMIT_DIR}/COMP/${compname}.card
450
451    IGCM_card_DefineArrayFromOption ${card} SmoothFiles List
452    ListFilesName=${compname}_SmoothFiles_List
453    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
454
455    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != X"Section" ] ) ; then
456      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
457
458      (( i=0 ))
459      until [ $i -ge $NbFiles ]; do
460        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
461        eval file_in=${file_in_}
462        (( i_ = i+1 ))
463        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
464        eval file_out=${file_out_}
465
466        # define CumulPeriod definition for this file
467        (( i__ = i+2 ))
468        eval SmoothDef=\${${ListFilesName}[$i__]}
469        IGCM_debug_Print 3 "  ${file_in} ${SmoothDef}"
470        aux=$( IGCM_SmoothModulo ${SmoothDef} ${CumulPeriod} )
471        j=1
472        for val in ${aux} ; do
473          [ ${j} -eq 1 ] && SmoothMin=${val}
474          [ ${j} -eq 2 ] && SmoothMax=${val}
475          [ ${j} -eq 3 ] && ret=${val}
476          (( j=j+1 ))
477        done
478        [ ${SmoothMax} -eq -1 ] && SmoothMax=${CumulPeriod}
479        if ( [ X${ret} = Xtrue ] || ( [ ${Period} -eq 1 ] && [ ${CumulPeriod} -ge ${SmoothMin} ] && [ ${CumulPeriod} -le ${SmoothMax} ] ) ) ; then
480
481          IGCM_sys_IsFileArchived ${file_in}
482          if [ $? = 0 ] ; then
483            IGCM_sys_Get ${file_in} ${file_out}
484            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
485          else
486            IGCM_sys_Cp ${file_in} ${file_out}
487          fi
488        fi
489        (( i=i+3 ))
490      done
491    fi
492  done
493
494  IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
495}
496
497#=======================================================================
498function IGCM_comp_GetInputBoundaryFiles
499{
500  IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
501
502  # Debug Print :
503  echo
504  IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles"
505  echo
506
507  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
508  typeset file_in_ file_in file_out_ file_out
509
510  if [ ${Period} = 1 ]; then
511    ListFixBoundary=" "
512  fi
513
514  for comp in ${config_ListOfComponents[*]} ; do
515
516    # Define component
517    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
518    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
519
520    # Debug Print :
521    IGCM_debug_Print 3 "Boundary files ${compname}"
522
523    card=${SUBMIT_DIR}/COMP/${compname}.card
524
525    IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
526    ListFilesName=${compname}_BoundaryFiles_List
527    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
528
529    if [ X${FileName0} != X${NULL_STR} ] ; then
530      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
531
532      (( i=0 ))
533      until [ $i -ge $NbFiles ]; do
534        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
535        eval file_in=${file_in_}
536        (( i_ = i+1 ))
537        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
538        eval file_out=${file_out_}
539
540        IGCM_sys_IsFileArchived ${file_in}
541        if [ $? = 0 ] ; then
542          IGCM_sys_Get ${file_in} ${file_out}
543          IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
544        else
545          IGCM_sys_Cp ${file_in} ${file_out}
546        fi
547
548        (( i=i+2 ))
549      done
550    fi
551
552    # Get non deleted files
553    if [ ${Period} = 1 ]; then
554
555      IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
556      ListFilesName=${compname}_BoundaryFiles_ListNonDel
557      eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
558
559      if [ X${FileName0} != X${NULL_STR} ] ; then
560        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
561
562        (( i=0 ))
563        until [ $i -ge $NbFiles ]; do
564          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
565          eval file_in=${file_in_}
566          (( i_ = i+1 ))
567          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
568          eval file_out=${file_out_}
569
570          IGCM_sys_IsFileArchived ${file_in}
571          if [ $? = 0 ] ; then
572            IGCM_sys_Get ${file_in} ${file_out}
573            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
574          else
575            IGCM_sys_Cp ${file_in} ${file_out}
576          fi
577
578          if [ X${file_out} != X. ] ; then
579            ListFixBoundary=${ListFixBoundary}" "${file_out}
580          else
581            ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
582          fi
583
584          (( i=i+2 ))
585        done
586      fi
587    fi
588  done
589
590  IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
591}
592
593#=======================================================================
594function IGCM_comp_DelFixeBoundaryFiles
595{
596  IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
597
598  # Debug Print :
599  echo
600  IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles"
601  echo
602
603  ls -l ${ListFixBoundary}
604  rm -f ${ListFixBoundary}
605
606  IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
607}
608
609#=======================================================================
610function IGCM_comp_GetInputParametersFiles
611{
612  IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
613
614  # Debug Print :
615  echo
616  IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles"
617  echo
618
619  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
620  for comp in ${config_ListOfComponents[*]} ; do
621    # Define component
622    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
623    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
624
625    # Initialize array hosting file_def and field_def files to check and/or modify
626    unset FieldDef
627    unset FileDef
628
629    # Debug Print :
630    IGCM_debug_Print 3 "Parameters ${compname}"
631
632    card=${SUBMIT_DIR}/COMP/${compname}.card
633
634    IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
635    ListFilesName=${compname}_ParametersFiles_List
636    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
637
638    if [ X${FileName0} != X${NULL_STR} ] ; then
639      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
640
641      (( i=0 ))
642      until [ $i -ge $NbFiles ]; do
643        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
644        eval file_in=${file_in_}
645        (( i_ = i+1 ))
646        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
647        eval file_out=${file_out_}
648
649        IGCM_sys_Cp ${file_in} ${file_out}
650        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
651        IGCM_comp_PrepareXiosFiles    ${file_in} ${file_out}
652
653        (( i=i+2 ))
654      done
655    fi
656
657  done
658
659  IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
660}
661
662#=======================================================================
663function IGCM_comp_GetInputRestartFiles
664{
665  IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
666
667  # Debug Print :
668  echo
669  IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles"
670  echo
671
672  typeset Date_tmp Date_r Path_r do_start CompOldName Path_OUT Path_BUF
673  typeset Buffered Archived Tared PotentialTarFile IsMatching TarFileFound
674  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
675  typeset file_in file_out file_in_ file_out_ file_in_Name
676  typeset -Z4 j4
677  #BASH declare j4
678
679  IsMatching=""
680
681  for comp in ${config_ListOfComponents[*]} ; do
682    # Define component
683    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
684    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
685    #
686    card=${SUBMIT_DIR}/COMP/${compname}.card
687    #
688    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
689    ListFilesName=${compname}_RestartFiles_List
690    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
691
692    # Debug Print :
693    IGCM_debug_Print 3 "restart ${compname}"
694
695    if ( ${FirstInitialize} ) ; then
696
697      if ( [ "${config_Restarts_OverRule}" = "y" ] || [ "${config_Restarts_OverRule}" = "Y" ] ) ; then
698        # Adhoc exception for CMIP6 : exclude XIOS from the restart overrule mechanism.
699        if ( [ X${comp} = XIOS ] ) && ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then
700          CompOldName=IOS
701          config_IOS_Restart="n"
702          do_start="n"
703          config_IOS_RestartDate=-1
704          config_IOS_RestartJobName=${NULL_STR}
705          config_IOS_RestartPath=${NULL_STR}
706        else
707          eval config_${comp}_Restart="y"
708          eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
709          eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
710          eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
711          eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
712          eval CompOldName=${comp}
713        fi
714      else
715        # Read component Restarts parameters
716        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
717        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
718
719        if [ "${do_start}" = "y" ] ; then
720          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
721          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
722          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
723        else
724          eval config_${comp}_RestartDate=-1
725          eval config_${comp}_RestartJobName=${NULL_STR}
726          eval config_${comp}_RestartPath=${NULL_STR}
727        fi
728
729        eval CompOldName=\${config_${comp}_OldName}
730        if [ X${CompOldName} = X ] ; then
731          eval CompOldName=${comp}
732        fi
733
734        # Reinitialize IsMatching to allow searching for a different tar file for each component.
735        IsMatching=""
736        TarFileFound=""
737      fi
738
739      if [ "${do_start}" = "y" ] ; then
740
741        # Restore Restarts files
742        #-----------------------
743        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
744          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
745
746          (( i=1 ))
747          until [ $i -gt $NbFiles ]; do
748            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
749            eval file_in=${file_in_}
750            (( i_ = i+1 ))
751            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
752            eval file_out=${file_out_}
753
754            eval Date_tmp=\${config_${comp}_RestartDate}
755            Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
756            # will be re-use
757            eval RestartPath=\${config_${comp}_RestartPath}
758            eval RestartJobName=\${config_${comp}_RestartJobName}
759            #
760            Path_r=${RestartPath}/${RestartJobName}/${CompOldName}/Restart
761            file_in_Name=${RestartJobName}_${Date_r}_${file_in}
762
763            extension_in=$( echo ${file_in_Name##*.} )
764            extension_out=$( echo ${file_out##*.} )
765
766            generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
767            generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
768
769            Path_OUT=${Path_r}/${generic_restart_file_name_in}
770
771            if [ $( IGCM_sys_TestFileBuffer ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
772              IGCM_debug_Print 3 "Buffered restart ${Path_OUT}*.${extension_in} "
773              Buffered=true
774              Archived=false
775              Tared=false
776              nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_OUT}_????.${extension_in})
777            elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
778              IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
779              Buffered=false
780              Archived=true
781              Tared=false
782              nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
783            else
784              IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
785              IGCM_debug_Print 3 "${Path_OUT}*.${extension_in} do not exist"
786              IGCM_debug_Print 3 "Restart files will now be searched for in : ${RestartPath}/${RestartJobName}/RESTART"
787              Buffered=false
788              Archived=false
789              Tared=true
790              # Look after the tar file we want if we did not found it already
791              if [ X${IsMatching} = X ] ; then
792                IGCM_sys_TestDirArchive ${RestartPath}/${RestartJobName}/RESTART
793                if [ $? ] ; then
794                  for PotentialTarFile in $( IGCM_sys_RshArchive "find ${RestartPath}/${RestartJobName}/RESTART -name "${RestartJobName}_*restart*.tar" -print" ) ; do
795                    IsMatching=$( echo ${PotentialTarFile##*/} | \
796                      sed "s:_restart::" | \
797                      sed "s:^${RestartJobName}_::" | \
798                      sed "s:\.tar$::" | \
799                      gawk -F_ -v restartdate=${Date_r} \
800                      '{if (($1 <= restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
801                    if [ ! X${IsMatching} = X ] ; then
802                      TarFileFound=${PotentialTarFile}
803                      break
804                    fi
805                  done
806                fi
807                # Stop here if nothing has been found
808                if [ X${TarFileFound} = X ] ; then
809                  IGCM_debug_Print 3 "Restart files were not found!"
810                  IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
811                  IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
812                  IGCM_debug_Exit "Please double check restart settings in config.card"
813                  IGCM_debug_Verif_Exit
814                fi
815              fi
816              IGCM_sys_PrepareTaredRestart ${TarFileFound}
817              TarFileLocation=$( basename ${TarFileFound} )
818              IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
819              tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
820              nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
821            fi
822
823            if [ ${nb_restart_file} -gt 1 ] ; then
824              j=0                                      # BASH LINE NOT NEEDED
825              # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
826              until [ $j -ge ${nb_restart_file} ]; do  # BASH LINE NOT NEEDED
827                j4=${j}                                # BASH LINE NOT NEEDED
828                if [ X${Buffered} = Xtrue ] ; then
829                  IGCM_sys_GetBuffer ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
830                elif [ X${Archived} = Xtrue ] ; then
831                  IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
832                elif [ X${Tared} = Xtrue ] ; then
833                  IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
834                fi
835                (( j=j+1 ))                            #BASH LINE NOT NEEDED
836              done
837
838              # OCE SPECIFIC TO REBUILD RESTART WHEN NUMBER OF RESTART FILES DONT MATCH MPI PROCESS
839              if [ X${OCE_PROC_MPI} != X ] ; then
840                if [ ${OCE_PROC_MPI} -ne ${nb_restart_file} ] ; then
841                  IGCM_sys_rebuild_nemo ${generic_restart_file_name_out} ${nb_restart_file} ${extension_out} ${generic_restart_file_name_out}_????.${extension_out}
842                  IGCM_sys_Rm ${generic_restart_file_name_out}_????.${extension_out}
843                fi
844              fi
845            else
846              if [ X${Buffered} = Xtrue ] ; then
847                IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
848              elif [ X${Archived} = Xtrue ] ; then
849                IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
850              elif [ X${Tared} = Xtrue ] ; then
851                IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
852              fi
853            fi
854            (( i=i+3 ))
855          done
856        else
857          if [ X${FileName0} != XNONE ] ; then
858            IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
859          else
860            IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
861          fi
862        fi
863      fi
864    elif ( [ ${Period} -eq 1 ] && [ ${DRYRUN} -eq 0 ] ) ; then
865      # if not FirstInitialize and first loop of this job
866
867      # Restore Restarts files
868      #-----------------------
869      if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
870        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
871
872        (( i=1 ))
873        until [ $i -gt $NbFiles ]; do
874          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
875          eval file_in=${file_in_}
876          (( i_ = i+1 ))
877          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
878          eval file_out=${file_out_}
879
880          file_in_Name=${config_UserChoices_JobName}_${LastPeriodDateEnd}_${file_in}
881
882          extension_in=$( echo ${file_in_Name##*.} )
883          extension_out=$( echo ${file_out##*.} )
884
885          generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
886          generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
887
888          eval Path_BUF=\${R_BUF_${comp}_R}/${generic_restart_file_name_in}
889          eval Path_OUT=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
890
891          if [ $( IGCM_sys_TestFileBuffer ${Path_BUF}*.${extension_in} ; echo $? ) = 0 ] ; then
892            IGCM_debug_Print 3 "Buffered restart ${Path_BUF}*.${extension_in}"
893            Buffered=true
894            Archived=false
895            Tared=false
896            nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_BUF}_????.${extension_in})
897          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
898            IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
899            Buffered=false
900            Archived=true
901            Tared=false
902            nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
903          else
904            IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
905            IGCM_debug_Print 3 "Restart files will now be searched for in : ${R_SAVE}/RESTART"
906            Buffered=false
907            Archived=false
908            Tared=true
909            # Look after the tar file we want if we did not found it already
910            if [ X${IsMatching} = X ] ; then
911              for PotentialTarFile in $( IGCM_sys_RshArchive "find ${R_SAVE}/RESTART -name "${config_UserChoices_JobName}_*_restart.tar" -print" ) ; do
912                IsMatching=$( echo ${PotentialTarFile##*/} | sed "s:^${config_UserChoices_JobName}_::" | sed "s:\.restart\.tar$::" | gawk -F_ -v restartdate=${LastPeriodDateEnd} '{if (($1 < restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
913                if [ ! X${IsMatching} = X ] ; then
914                  TarFileFound=${PotentialTarFile}
915                  break
916                fi
917              done
918            fi
919            # Stop here if nothing has been found
920            if [ X${TarFileFound} = X ] ; then
921              IGCM_debug_Print 3 "Restart files were not found!"
922              IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
923              IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
924              IGCM_debug_Exit "Please double check restart settings in config.card"
925              IGCM_debug_Verif_Exit
926            fi
927            IGCM_sys_PrepareTaredRestart ${TarFileFound}
928            TarFileLocation=$( basename ${TarFileFound} )
929            IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
930            tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
931            nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
932          fi
933
934          if [ ${nb_restart_file} -gt 1 ] ; then
935            j=0                                     # BASH LINE NOT NEEDED
936            #BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
937            until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
938              j4=${j}                               # BASH LINE NOT NEEDED
939              if [ X${Buffered} = Xtrue ] ; then
940                IGCM_sys_GetBuffer ${Path_BUF}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
941              elif [ X${Archived} = Xtrue ] ; then
942                IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
943              elif [ X${Tared} = Xtrue ] ; then
944                IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
945              fi
946              (( j=j+1 ))                           # BASH LINE NOT NEEDED
947            done
948          else
949            if [ X${Buffered} = Xtrue ] ; then
950              eval IGCM_sys_GetBuffer \${R_BUF_${comp}_R}/${file_in_Name} ${file_out}
951            elif [ X${Archived} = Xtrue ] ; then
952              eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
953            elif [ X${Tared} = Xtrue ] ; then
954              IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
955            fi
956          fi
957          (( i=i+3 ))
958        done
959      else
960        if [ X${FileName0} != XNONE ] ; then
961          IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
962        else
963          IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
964        fi
965      fi
966    fi
967  done
968
969  NbFiles=$( ls * 2> /dev/null | wc -l )
970  if [ ${NbFiles} -gt 0 ] ; then
971    IGCM_sys_Chmod u+rw *
972  fi
973
974  IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
975}
976
977#=======================================================================
978function IGCM_comp_GetInputBinaryFiles
979{
980  IGCM_debug_PushStack "IGCM_comp_GetInputBinaryFiles"
981
982  # Debug Print :
983  echo
984  IGCM_debug_Print 1 "IGCM_comp_GetInputBinaryFiles"
985  echo
986
987  # Clean up previous pass
988  [ -f ${RUN_DIR}/compiler.txt ] && rm -f ${RUN_DIR}/compiler.txt
989
990  typeset comp ExeNameIn ExeNameOut byPass
991  typeset compilerNmbr compilerUnit compilerFull
992  byPass=false
993  for comp in ${config_ListOfComponents[*]} ; do
994    # Define component
995
996    # Copy executable for this component
997    eval ExeNameIn=\${config_Executable_${comp}[0]}
998    eval ExeNameOut=\${config_Executable_${comp}[1]}
999    # Test if missing executable and DRYRUN is set to 0 or 1, then stop!
1000    if [ ${DRYRUN} -le 1 ] && [ X${ExeNameIn} != X\"\" ] ; then
1001        # The executable is set in config.card and is different from ""
1002        # Use eval to expand ExeNameIn if variables are used in the name
1003        eval ExeNameIn=${ExeNameIn}
1004        if [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
1005            IGCM_debug_Exit "IGCM_comp_GetInputBinaryFiles missing executable ${ExeNameIn}"
1006        fi
1007    fi
1008
1009    if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
1010      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1011      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1012        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1013      fi
1014    elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
1015      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1016      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1017        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1018      fi
1019    fi
1020
1021    if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1022      # Get the compiler version
1023      compilerFull=$( strings ${RUN_DIR}/${ExeNameOut}  | grep "RTL Message Catalog" | gawk '{print $6}' | gawk -F. '{print $1}' )
1024      compilerVersion=$( strings ${RUN_DIR}/${ExeNameOut}  | grep "RTL Message Catalog" | gawk '{print $6}' | gawk -F. '{print $1}' )
1025      # Save it
1026      echo $compilerFull >> ${RUN_DIR}/compiler.txt
1027      [ X${compilerFull} = X ] && byPass=true
1028      IGCM_debug_Print 1 "${RUN_DIR}/${ExeNameOut} has been compiled with ${compilerFull}"
1029      IGCM_debug_Print 1 "Compiler is ${compilerVersion}"
1030    fi
1031  done
1032
1033  compilerNmbr=$( cat ${RUN_DIR}/compiler.txt | wc -l )
1034  compilerUnit=$( cat ${RUN_DIR}/compiler.txt | sort | uniq -c )
1035
1036  if ( [ ${compilerNmbr} -ne ${compilerUnit} ] && [ ! X${byPass} = Xtrue  ] ); then
1037    IGCM_debug_Exit "Binaries has not been compiled with the same compiler version"
1038  fi
1039
1040
1041  IGCM_debug_PopStack "IGCM_comp_GetInputBinaryFiles"
1042}
1043
1044#=======================================================================
1045function IGCM_comp_PeriodStart
1046{
1047  IGCM_debug_PushStack "IGCM_comp_PeriodStart"
1048
1049  # Debug Print :
1050  echo
1051  IGCM_debug_Print 1 "IGCM_comp_PeriodStart"
1052  echo
1053
1054  typeset ExeNameIn ExeNameOut
1055  typeset comp compname comptagname
1056  for comp in ${config_ListOfComponents[*]} ; do
1057    # Define component
1058    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1059    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1060
1061    # Copy executable for this component
1062    eval ExeNameIn=\${config_Executable_${comp}[0]}
1063    eval ExeNameIn=${ExeNameIn}
1064    eval ExeNameOut=\${config_Executable_${comp}[1]}
1065
1066    # Debug Print
1067    IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
1068    # UPDATE component
1069    ${comp}_PeriodStart 2> /dev/null
1070
1071  done
1072
1073  IGCM_debug_PopStack "IGCM_comp_PeriodStart"
1074}
1075
1076
1077
1078#=======================================================================
1079function IGCM_comp_modifyFile
1080{
1081#
1082# syntax:     IGCM_comp_modifyFile  filein  key  [value]
1083#
1084# For example : IGCM_comp_modifyFile metrics_template.py case_id \'SE_${YEARS}\'
1085#
1086# This function is used to replace a pattern in a file for a specific variable.
1087#
1088# Arguments:
1089# - filein : the file in run directory in which the variable should be set
1090# - key    : the variable to modify
1091# - value  : the value to set the key equal to
1092#
1093  IGCM_debug_PushStack "IGCM_comp_modifyFile"
1094
1095  typeset filein key value pattern
1096
1097  # Set local variables and test the arguments
1098  if [ $# = 3 ] ; then
1099    # Normal case with 3 arguments
1100    filein=$1 ; key=$2 ; value=$3
1101  else
1102    IGCM_debug_Exit "IGCM_comp_modifyFile: Bad number of arguments."
1103    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1104    return
1105  fi
1106  IGCM_debug_Print 1 "Entering IGCM_comp_modifyFile with arguments: ${filein} ${key} ${value}"
1107
1108  # Test if the file exist
1109  if [ ! -f ${filein} ] ; then
1110    IGCM_debug_Exit "IGCM_comp_modifyFile: ${filein} does not exist."
1111    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1112    return
1113  fi
1114
1115  # Read the line with key in the file without the comments
1116  pattern=$( grep "^ *${key} *=" ${filein} | sed -e "s% *\!.*%%" )
1117
1118  # Verify the existance of the pattern
1119  if [ X"${pattern}" = X ] ; then
1120    # Variable key is not set in filein, stop.
1121    IGCM_debug_Exit "IGCM_comp_modifyFile : Variable ${key} is not set in correct file. It should be set in ${filein}."
1122    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1123    return
1124  fi
1125
1126  # Now change key in filein
1127  #sed -e "s:${pattern}:${key}=${value}:" ${filein} > ${filein}.tmp
1128  sed -e "s:^ *${key} *=.*:${key}=${value}:" ${filein} > ${filein}.tmp
1129  IGCM_debug_Print 1 "IGCM_comp_modifyFile: In ${filein} set ${key}=${value}"
1130  \mv ${filein}.tmp ${filein}
1131 
1132  IGCM_debug_PopStack "IGCM_comp_modifyFile"
1133}
1134
1135#=======================================================================
1136function IGCM_comp_modifyDefFile
1137{
1138#
1139# syntax:     IGCM_comp_modifyDefFile  type  filein  key  [value]
1140#
1141# For example : IGCM_comp_modifyDefFile blocker run.def day_step 1200
1142#
1143# This function is used to modify a parameter file for a specific variable.
1144# The file must be a ".def" file, i.e. with IOIPSL parameter file syntax.
1145# This function can be used in the comp.driver files for the components.
1146#
1147# Arguments:
1148# - type   : first argument must be blocker, nonblocker or force
1149#            For "blocker" case, the variable must be attributed the keyworld AUTO
1150#            otherwise this function will exit.
1151#            For "nonblocker" case, the user can remove or modify the variable. For
1152#            this case, as long as AUTO is not set, no modification will be done.
1153#            For "force" case, the variable will be modified even if it is not set to AUTO
1154# - filein : the file in run directory of .def type in which the variable should be set
1155# - key    : the variable to modify
1156# - value  : the value to set the key equal to, optional. If value is not set or if
1157#            value=DEFAULT, then a default value must be given in filein using syntax :
1158#            key= AUTO : DEFAULT=def_value
1159#
1160  IGCM_debug_PushStack "IGCM_comp_modifyDefFile"
1161
1162  typeset type filein key value
1163  typeset filelist nb_occ modify
1164
1165  # Set local variables and test the arguments
1166  if [ $# = 4 ] ; then
1167    # Normal case with 4 arguments
1168    type=$1 ; filein=$2 ; key=$3 ; value=$4
1169  elif [ $# = 3 ] ; then
1170    # Normal case with 3 arguments
1171    type=$1 ; filein=$2 ;       key=$3; value="DEFAULT"
1172  else
1173    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Bad number of arguments."
1174    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1175    return
1176  fi
1177  IGCM_debug_Print 1 "Entering IGCM_comp_modifyDefFile with arguments: ${type} ${filein} ${key} ${value}"
1178
1179  # Test if first argument is correct
1180  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1181    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Error in first argument must be blocker, nonblocker or force"
1182    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1183    return
1184  fi
1185
1186  # Test if the file exist.
1187  # Exit with error if the file does not exist for the case blocker or force.
1188  # Only return for the case nonblocker.
1189  if [ ! -f ${filein} ] ; then
1190    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1191      IGCM_debug_Exit "IGCM_comp_modifyDefFile: ${filein} does not exist."
1192    else
1193      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${filein} does not exist. Nothing will be done for this file."
1194    fi
1195    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1196    return
1197  fi
1198
1199  # Define list of files to test using all files with suffix .def (except used*.def)
1200  filelist=$( ls *def | grep -v used )
1201
1202  # Count number of occurances for the key in all files
1203  nb_occ=$( grep -w ${key} ${filelist} | grep -v "#"  | wc -l )
1204
1205  # Test if key is set several times
1206  if [ ${nb_occ} -gt 1 ] ; then
1207    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in ${filein}: Variable=${key} is set ${nb_occ} times"
1208    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1209    return
1210  fi
1211
1212  # Treatement according to different cases
1213  if [ ${nb_occ} -eq 0 ] && [ ${type} = blocker ] ; then
1214    # Stop if the key is never set and the function is blocker
1215    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in ${filein}: Variable=${key} has been removed but this function is blocker. "
1216    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: restore ${filein} for variable ${key}."
1217  elif [ ${nb_occ} -eq 0 ] && [ ${type} = nonblocker ] ; then
1218    # The key is not set but it is a nonblocker call so nothing is done.
1219    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key} is not set in ${filein}. This is a nonblocker call so nothing is done."
1220    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: Default value for ${key} from the model will be used."
1221    modify=no
1222  elif [ $( grep ${key} ${filein} | grep -v "\#"  |wc -l ) = 0 ] ; then
1223    # Variable key is not set in filein, stop.
1224    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Variable ${key} is not set in correct file. It should be set in ${filein}."
1225  fi
1226
1227  # Check if AUTO is set in the filein on the same line as the key variable
1228  if [ $( grep -w ${key} ${filein} | grep -v "\#" | grep AUTO | wc -l ) = 1 ] ; then
1229    # Modification will be done for all cases
1230    modify=yes
1231  else
1232    # The variable was not set to AUTO
1233    if [ ${type} = blocker ] ; then
1234      # Exit because this is a blocker call
1235      IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable ${key} cannot be modified. It should be set to AUTO."
1236      IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1237      return
1238    elif [ ${type} = nonblocker ] ; then
1239      # Do nothing. Suppose that the user did set the variable correct
1240      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key} is set by the user. Nothing done."
1241      modify=no
1242    elif [ ${type} = force ] ; then
1243      # Force modification
1244      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile : Variabl=${key} was not set to AUTO. Modification will be forced."
1245      modify=yes
1246    fi
1247  fi
1248
1249  # Do the modifcation now
1250  if [ ${modify} = yes ] ; then
1251
1252    # For option DEFAULT, read default value from file.
1253    if [ X"${value}" = XDEFAULT ] || [ X"${value}" = X ] ; then
1254      # Case to set DEFAULT value
1255      # Read default value from filein
1256      value=$( grep -w ${key} ${filein} | grep -v "\#" | awk  -F"DEFAULT *=" '{print $2}')
1257
1258      if [ X"${value}" = X ] ; then
1259        IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable ${key} needs a DEFAULT value in ${filein}."
1260        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: The syntax in ${filein} should be:"
1261        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key}=_AUTO_:DEFAULT=def_value"
1262        IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1263        return
1264      fi
1265    fi
1266
1267    # Now change key in filein
1268    sed -e "s/^${key}\ *=.*/${key}= ${value}/" ${filein} > ${filein}.tmp
1269    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: In ${filein} set ${key}=${value}"
1270    \mv ${filein}.tmp ${filein}
1271  fi
1272  IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1273}
1274
1275#=======================================================================
1276function IGCM_comp_modifyNamelist
1277{
1278#
1279# syntax:     IGCM_comp_modifyNamelist  type  filein  key  [value]
1280#
1281# For example : IGCM_comp_modifyNamelist blocker run.def day_step 1200
1282#
1283# This function is used to modify a parameter file for a specific variable.
1284# The file must be a "namelist" file, i.e. with fortran namelist syntax.
1285# This function can be used in the comp.driver files for the components.
1286#
1287# Arguments:
1288# - type   : first argument must be blocker, nonblocker or force
1289#            For "blocker" case, the variable must be attributed the keyworld AUTO
1290#            otherwise this function will exit.
1291#            For "nonblocker" case, the user can remove or modify the variable. For
1292#            this case, as long as AUTO is not set, no modification will be done.
1293#            For "force" case, the variable will be modified even if it is not set to AUTO
1294# - filein : the file in run directory of .def type in which the variable should be set
1295# - key    : the variable to modify
1296# - value  : the value to set the key equal to, optional. If value is not set or if
1297#            value=DEFAULT, then a default value must be given in filein using syntax :
1298#            key= AUTO : DEFAULT=def_value
1299#
1300  IGCM_debug_PushStack "IGCM_comp_modifyNamelist"
1301
1302  typeset type filein key value pattern modify
1303
1304  # Set local variables and test the arguments
1305  if [ $# = 4 ] ; then
1306    # Normal case with 4 arguments
1307    type=$1 ; filein=$2 ; key=$3 ; value=$4
1308  elif [ $# = 3 ] ; then
1309    # Normal case with 3 arguments
1310    type=$1 ; filein=$2 ;       key=$3; value="DEFAULT"
1311  else
1312    IGCM_debug_Exit "IGCM_comp_modifyNamelist: Bad number of arguments."
1313    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1314    return
1315  fi
1316  IGCM_debug_Print 1 "Entering IGCM_comp_modifyNamelist with arguments: ${type} ${filein} ${key} ${value}"
1317
1318  # Test if first argument is correct
1319  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1320    IGCM_debug_Exit "IGCM_comp_modifyNamelist: Error in first argument must be blocker, nonblocker or force"
1321    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1322    return
1323  fi
1324
1325  # Test if the file exist.
1326  # Exit with error if the file does not exist for the case blocker or force.
1327  # Only return for the case nonblocker.
1328  if [ ! -f ${filein} ] ; then
1329    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1330      IGCM_debug_Exit "IGCM_comp_modifyNamelist: ${filein} does not exist."
1331    else
1332      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${filein} does not exist. Nothing will be done for this file."
1333    fi
1334    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1335    return
1336  fi
1337
1338  # Read the line with key in the file without the comments
1339  pattern=$( grep "^ *${key} *=" ${filein} | sed -e "s% *\!.*%%" )
1340
1341  # Verify the existance of the pattern
1342  if [ X"$pattern" = X ] ; then
1343    # Variable key is not set in filein, stop.
1344    IGCM_debug_Exit "IGCM_comp_modifyNamelist : Variable ${key} is not set in correct file. It should be set in ${filein}."
1345    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1346    return
1347  fi
1348
1349  # Check if the variable is set to AUTO in the filein
1350  if [ $( echo $pattern | grep AUTO | wc -l ) = 1 ] ; then
1351    # Modification will be done for all cases
1352    modify=yes
1353  else
1354    # The variable was not set to AUTO
1355    if [ ${type} = blocker ] ; then
1356      # Exit because this is a blocker call
1357      IGCM_debug_Exit "IGCM_comp_modifyNamelist : The variable ${key} cannot be modified. It should be set to AUTO."
1358      IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1359      return
1360    elif [ ${type} = nonblocker ] ; then
1361      # Do nothing. Suppose that the user did set the variable correct
1362      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${key} is set by the user. Nothing done."
1363      modify=no
1364    elif [ ${type} = force ] ; then
1365      # Force modification
1366      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist : Variabl=${key} was not set to AUTO. Modification will be forced."
1367      modify=yes
1368    fi
1369  fi
1370
1371  # Do the modifcation now
1372  if [ ${modify} = yes ] ; then
1373
1374    # For option DEFAULT, read default value from file.
1375    if [ X"${value}" = XDEFAULT ] || [ X"${value}" = X ] ; then
1376      # Case to set DEFAULT value
1377      # Read default value from filein
1378      value=$( echo $pattern | awk  -F"DEFAULT *=" '{print $2}')
1379
1380      if [ X"${value}" = X ] ; then
1381        IGCM_debug_Exit "IGCM_comp_modifyNamelist : The variable ${key} needs a DEFAULT value in ${filein}."
1382        IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: The syntax in ${filein} should be:"
1383        IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${key}=_AUTO_:DEFAULT=def_value"
1384        IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1385        return
1386      fi
1387    fi
1388
1389    # Now change key in filein
1390    sed -e "s/${pattern}/       ${key}=${value}/" ${filein} > ${filein}.tmp
1391    IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: In ${filein} set ${key}=${value}"
1392    \mv ${filein}.tmp ${filein}
1393  fi
1394  IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1395}
1396
1397#=======================================================================
1398function IGCM_comp_modifyXmlFile
1399{
1400#
1401# syntax:     IGCM_comp_modifyXmlFile  type  filein  keyid  keyattrib  value
1402#
1403# For example : IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba2 enabled .TRUE.
1404#          or   IGCM_comp_modifyXmlFile blocker iodef.xml using_server NONE false
1405#
1406# This function is used to modify the value for a specific attribute and variable id.
1407# The file must be a valid xml file.
1408# This function can be used in the comp.driver files for the components.
1409#
1410# Arguments:
1411# - type      : first argument must be blocker, nonblocker or force.
1412#               For "blocker" case, the variable must be attributed the keyworld AUTO
1413#               otherwise this function will exit.
1414#               For "nonblocker" case, the user can remove or modify the variable. For
1415#               this case, as long as AUTO is not set, no modification will be done.
1416#               For "force" case, the variable will be modified even if it is not set to AUTO
1417# - filein    : the file in run directory of .xml type in which the variable should be set
1418# - keyid     : the variable to modify
1419# - keyattrib : the attribute name to modify. If NONE, then the variable itself will be modified
1420# - value     : the value to set in the filein
1421#
1422  IGCM_debug_PushStack "IGCM_comp_modifyXmlFile"
1423
1424  typeset type filein keyid keyattrib value modify
1425
1426  # Set local variables and test the arguments
1427  if [ $# = 5 ] ; then
1428    # Normal case with 4 arguments
1429    type=$1 ; filein=$2 ; keyid=$3 ; keyattrib=$4 ; value=$5
1430  else
1431    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Bad number of arguments."
1432    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1433    return
1434  fi
1435  IGCM_debug_Print 1 "Entering IGCM_comp_modifyXmlFile with arguments: type=${type} file=${filein}, id=${keyid} attribute=${keyattrib}, value=${value}"
1436
1437  # Test if first argument is correct
1438  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1439    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Error in first argument must be blocker, nonblocker or force"
1440    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1441    return
1442  fi
1443
1444  # Test if the file exist.
1445  # Exit with error if the file does not exist for the case blocker or force.
1446  # Only return for the case nonblocker.
1447  if [ ! -f ${filein} ] ; then
1448    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1449      IGCM_debug_Exit "IGCM_comp_modifyXmlFile: ${filein} does not exist."
1450    else
1451      IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile: ${filein} does not exist. Nothing will be done for this file."
1452    fi
1453    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1454    return
1455  fi
1456
1457  # Test if keyid is set in filein. If not exit for case all cases(blocker, force) except nonblocker.
1458  if [ $( grep -w ${keyid} ${filein} | wc -l ) = 0 ] ; then
1459      if [ ${type} = nonblocker ] ; then
1460          # This is a nonblocker case, print warning but do nothing else
1461          IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile: ${keyid} is not set in ${filein}. This is a nonblocker call so nothing is done."
1462      else
1463          # This is a blocker or force case : stop now
1464          IGCM_debug_Exit "IGCM_comp_modifyXmlFile : ${keyid} is not set in the file. Bad syntax of ${filein} file."
1465          IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1466          return
1467      fi
1468  fi
1469
1470  # Check if AUTO is set on the same line as keyid and keyattrib
1471  if [  $( grep -w ${keyid} ${filein} | grep AUTO | wc -l ) = 1 ] ; then
1472    # Modification will be done
1473    modify=yes
1474  else
1475    if [ ${type} = blocker ] ; then
1476      # Exit, the variable must be set to AUTO
1477      IGCM_debug_Exit "IGCM_comp_modifyXmlFile : blocker function. The ${keyattrib} for ${keyid} must be set to AUTO in ${filein}."
1478      IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1479      return
1480    elif [ ${type} = nonblocker ] ; then
1481      # Nothing will be done
1482      IGCM_debug_Print 1 "Nonblocker nothing is done for ${filein}, id=${keyid} and attribute ${keyattrib}"
1483      modify=no
1484    elif [ ${type} = force ] ; then
1485      # Force modification
1486      IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile : Attribute=${keyattrib} for id=${keyid} was not set to AUTO. Modification will be forced."
1487      modify=yes
1488    fi
1489  fi
1490
1491  # Do the modifcation now
1492  if [ ${modify} = yes ] ; then
1493    if [ ${keyattrib} = NONE ] ; then
1494      # Case to modify the variable itself
1495      IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting the variable=${value}"
1496      sed -e "s/\(<[^\"]*\"${keyid}\".*>\)\([^<]*\)\(<[^>]*\)/\1${value}\3/" ${filein} > ${filein}.tmp
1497    else
1498      # Check if keyattrib is set on the same line as keyid
1499      if [  $( grep -w ${keyid} ${filein} | grep ${keyattrib} | wc -l ) = 1 ] ; then
1500        # Case to modify the attribute value
1501        IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting attribute to ${keyattrib}=${value}"
1502        sed -e "/id=\"${keyid}\"/s/\(${keyattrib}=\"\)[^\"]*\(\"\)/\1${value}\2/" ${filein} > ${filein}.tmp
1503      else
1504        # Case to add the attribute and its value
1505        IGCM_debug_Print 1 "Now add in ${filein} for id=${keyid} the attribute ${keyattrib} to the value ${value}"
1506        sed -e "/id=\"${keyid}\"/s/\/>/ ${keyattrib}=\"${value}\"\/>/" ${filein} > ${filein}.tmp
1507      fi
1508    fi
1509    \mv ${filein}.tmp ${filein}
1510  fi
1511  IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1512}
1513
1514#=======================================================================
1515function IGCM_comp_Update
1516{
1517  IGCM_debug_PushStack "IGCM_comp_Update"
1518
1519  # Debug Print :
1520  echo
1521  IGCM_debug_Print 1 "IGCM_comp_Update"
1522  echo
1523
1524  typeset comp compname comptagname
1525  for comp in ${config_ListOfComponents[*]} ; do
1526    # Define component
1527    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1528    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1529
1530    # Debug Print
1531    IGCM_debug_Print 1 "Update ${compname} Parameter Files."
1532    # UPDATE component
1533    ${comp}_Update
1534
1535    # Read TimeSeries information from XML files, prepare TS directories and do modifications in timeseries_def_${compname}.xml
1536    if [ -f timeseries_def_${compname}.xml ]; then
1537      ${libIGCM}/libIGCM_post/xios_parser.py tsquery --file timeseries_def_${compname}.xml > ts.temp.${compname}.txt
1538      for line in $( cat ts.temp.${compname}.txt ); do
1539        output_freq=$( echo ${line} | awk -F "," '{print $1}' | awk -F "=" '{print $2}' )
1540        id=$(          echo ${line} | awk -F "," '{print $2}' | awk -F "=" '{print $2}' )
1541        case ${output_freq} in
1542        *Y|*y)
1543          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_Y}
1544          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_Y}/${config_UserChoices_JobName}
1545          ;;
1546        *MO|*mo)
1547          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_M}
1548          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_M}/${config_UserChoices_JobName}
1549          ;;
1550        *D|*d)
1551          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_D}
1552          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_D}/${config_UserChoices_JobName}
1553          ;;
1554        *S|*s)
1555          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_H}
1556          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_H}/${config_UserChoices_JobName}
1557          ;;
1558        esac
1559      done
1560    fi
1561
1562    # Read TimeSeries information from XML files, prepare CMIP6 TS directories and do modifications in dr2xml_${compname}.xml
1563    if [ -f dr2xml_${compname}.xml ]; then
1564      if ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then
1565        eval IGCM_sys_Mkdir \${CMIP6_BUF_${comp}}
1566        eval CMIP6_DIR=\${CMIP6_BUF_${comp}}
1567        # Modify path from dr2xml_{compname}.xml
1568        if [ X${config_Post_dr2xmlIPSL} = XTRUE ]; then
1569          ${libIGCM}/libIGCM_post/xios_parser.py -v modifydr2xmlIPSL --newPath ${CMIP6_DIR} --splitLastDate ${EndYear_p1} --JobName ${config_UserChoices_JobName} --ModelName ${config_UserChoices_ModelName} --ModelVersion ${config_UserChoices_LongName} --ExperimentName ${config_UserChoices_ExperimentName} --file dr2xml_${compname}.xml
1570        else
1571          ${libIGCM}/libIGCM_post/xios_parser.py -v modifyPath --newPath ${CMIP6_DIR} --file dr2xml_${compname}.xml
1572        fi
1573        # Overwrite the original file
1574        IGCM_sys_Mv modified.dr2xml_${compname}.xml dr2xml_${compname}.xml
1575      fi
1576    fi
1577  done
1578
1579  IGCM_debug_PopStack "IGCM_comp_Update"
1580}
1581
1582#=======================================================================
1583function IGCM_comp_Finalize
1584{
1585  IGCM_debug_PushStack "IGCM_comp_Finalize"
1586
1587  # Debug Print :
1588  echo
1589  IGCM_debug_Print 1 "IGCM_comp_Finalize"
1590  echo
1591
1592  typeset ListTextName TextName0
1593  typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
1594  typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
1595  typeset -Z4 j4 #BASH declare j4
1596  typeset list_file nlist_file
1597  typeset compactoutputs
1598
1599  # Initialize array hosting list of rebuilded files to copy
1600  unset rebuildedActionsList
1601
1602  # Text compacting options
1603  compactoutputs=false
1604  if [ X${JobType} != XRUN ] ; then
1605    compactoutputs=true
1606  elif [ X${config_UserChoices_CompactText} != Xn ] ; then
1607    compactoutputs=true
1608  fi
1609
1610  # Prepare headers for the shell dedicated to offline rebuild
1611  if [ X${AsynchronousRebuild} = Xtrue ] ; then
1612    [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1613    if [ ${DRYRUN} -le 1 ] ; then
1614      echo "#!/bin/ksh                                        " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1615      echo "function IGCM_FlushRebuild                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1616      echo "{                                                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1617      echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1618      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1619      echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1620      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1621      echo "export R_SAVE=${R_SAVE}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1622      echo "export R_BUFR=${R_BUFR}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1623      echo "export R_OUT_KSH=${R_OUT_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1624      echo "export R_BUF_KSH=${R_BUF_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1625      echo "export config_UserChoices_JobName=${config_UserChoices_JobName}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1626      echo "export config_UserChoices_SpaceName=${config_UserChoices_SpaceName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1627    fi
1628  fi
1629
1630  for comp in ${config_ListOfComponents[*]} ; do
1631    # Define component
1632    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1633    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1634
1635    # Debug Print
1636    IGCM_debug_Print 1 "Finalize ${comp} : ${compname} component."
1637    # FINALIZE component
1638    ${comp}_Finalize
1639
1640    card=${SUBMIT_DIR}/COMP/${compname}.card
1641
1642    # Save Output Text files of models
1643    #---------------------------------
1644    IGCM_debug_Print 2 "Save Output Text files for ${comp} : ${compname} component."
1645    IGCM_card_DefineArrayFromOption ${card} OutputText List
1646    ListTextName=${compname}_OutputText_List
1647
1648    eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1649    if [ X${TextName0} != X${NULL_STR} ] ; then
1650      eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1651
1652      (( i=0 ))
1653      until [ $i -eq $NbFiles ]; do
1654        eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1655        eval file_out=${PREFIX}_${file_in}
1656
1657        (( i=i+1 ))
1658
1659        unset list_file
1660        #set +A list_file -- $( ls ${file_in}* | sort 2>/dev/null )
1661        # result for a a1 a10 a2 with file_in=a a a1 a2 a10
1662        set +A list_file -- $( [ -f ${file_in} ] && ls ${file_in} ; for i in $(ls ${file_in}* 2>/dev/null | sed "s/${file_in}//" | sort -n) ; do ls ${file_in}$i ; done )
1663        nlist_file=${#list_file[@]}
1664        if [ ${nlist_file} -gt 1 ] ; then
1665          if ( ${compactoutputs} ) ; then
1666            IGCM_debug_Print 2 "Parallelism of Text Output with ${nlist_file} files."
1667            IGCM_debug_Print 2 "Compact files in ${file_out} : " ${list_file[*]}
1668            echo ${list_file[*]} > ${file_out}
1669            echo "" >> ${file_out}
1670
1671            (( i_ = 0 ))
1672            for file in ${list_file[@]} ; do
1673              echo "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " >> ${file_out}
1674              echo "| " ${i_} " " ${file} >> ${file_out}
1675              echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " >> ${file_out}
1676              cat ${file} | sed "s/\(.*\)/${i_}\1/" >> ${file_out}
1677              echo "" >> ${file_out}
1678              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1679                  (( i_ = i_ + 1 ))
1680            done
1681            if ( ${ExecutionFail} ) ; then
1682              IGCM_sys_Cp ${file_out} ${SUBMIT_DIR}/Debug
1683            fi
1684
1685            if [ X${Pack} = Xtrue ] ; then
1686              eval IGCM_sys_PutBuffer_Out ${file_out} \${R_BUF_${comp}_D}/${file_out}
1687            else
1688              eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}_D}/${file_out}
1689            fi
1690
1691            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_out}" > /dev/null 2>&1
1692          else
1693            for file in ${list_file[@]} ; do
1694              if ( ${ExecutionFail} ) ; then
1695                IGCM_sys_Cp ${file} ${SUBMIT_DIR}/Debug/${PREFIX}_${file}
1696              fi
1697
1698              if [ X${Pack} = Xtrue ] ; then
1699                eval IGCM_sys_PutBuffer_Out ${file} \${R_BUF_${comp}_D}/${PREFIX}_${file}
1700              else
1701                eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
1702              fi
1703
1704              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1705            done
1706          fi
1707        else
1708          if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1709            eval IGCM_sys_Mv ${file_in}* ${file_in}
1710          fi
1711
1712          if ( ${ExecutionFail} ) ; then
1713            IGCM_sys_Cp ${file_in} ${SUBMIT_DIR}/Debug/${file_out}
1714          fi
1715
1716          if [ X${Pack} = Xtrue ] ; then
1717            eval IGCM_sys_PutBuffer_Out ${file_in} \${R_BUF_${comp}_D}/${file_out}
1718          else
1719            eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${file_out}
1720          fi
1721          eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1722        fi
1723      done
1724    fi
1725
1726    # Save Restarts files
1727    #--------------------
1728    IGCM_debug_Print 2 "Save Restart files for ${comp} : ${compname} component."
1729    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
1730    ListFilesName=${compname}_RestartFiles_List
1731    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1732
1733    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
1734      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1735
1736      (( i=0 ))
1737      until [ $i -ge $NbFiles ]; do
1738        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1739        eval file_in=${file_in_}
1740
1741        (( i_ = i+1 ))
1742        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1743        eval file_out=${file_out_}
1744
1745        (( i_ = i+2 ))
1746        eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1747        eval file_outin=${file_outin_}
1748
1749        generic_restart_file_name_in=$(    basename ${file_in} .nc )
1750        generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
1751        generic_restart_file_name_outin=$( basename ${file_outin} .nc )
1752
1753        nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l )
1754        if [ ${nb_restart_file} -gt 1 ] ; then
1755          j=0                                     # BASH LINE NOT NEEDED
1756          # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
1757          until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
1758            j4=${j}                               # BASH LINE NOT NEEDED
1759            if [ X${Pack} = Xtrue ] ; then
1760              eval IGCM_sys_PutBuffer_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_BUF_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1761            else
1762              eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1763            fi
1764            if [ ! ${file_in} = ${file_outin} ] ; then
1765              if ( ${ExitFlag} ) ; then
1766                echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
1767              else
1768                IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
1769              fi
1770            fi
1771            (( j=j+1 ))                           # BASH LINE NOT NEEDED
1772          done
1773        else
1774          if [ X${Pack} = Xtrue ] ; then
1775            eval IGCM_sys_PutBuffer_Rest ${file_in} \${R_BUF_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1776          else
1777            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1778          fi
1779          if [ ! ${file_in} = ${file_outin} ] ; then
1780            if ( ${ExitFlag} ) ; then
1781              echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1782            else
1783              IGCM_sys_Mv ${file_in} ${file_outin}
1784            fi
1785          fi
1786        fi
1787
1788        (( i=i+3 ))
1789      done
1790    else
1791      if [ X${FileName0} != XNONE ] ; then
1792        IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
1793      else
1794        IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
1795      fi
1796    fi
1797
1798    # Save Output files
1799    #------------------
1800    IGCM_debug_Print 2 "Save Output files for ${comp} : ${compname} component."
1801    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
1802    ListFilesName=${compname}_OutputFiles_List
1803    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1804
1805    if [ X${FileName0} != X${NULL_STR} ] ; then
1806      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1807
1808      (( i=0 ))
1809      until [ $i -ge $NbFiles ]; do
1810        SaveOnArchive=true
1811        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1812        eval file_in=${file_in_}
1813        (( i_ = i+1 ))
1814        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1815        eval file_out=${file_out_}
1816        #
1817        # Override file_out path remplacing R_SAVE by R_BUFR
1818        #
1819        if [ X${Pack} = Xtrue ] ; then
1820          file_out=$( echo $file_out | sed "s:^$R_SAVE:$R_BUFR:" )
1821        fi
1822        #
1823        # Not necessarily the best option. /!\ Potential side effects /!\
1824        #
1825        (( i_ = i+2 ))
1826        eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1827        #
1828        generic_file_name=$( basename ${file_in} .nc )
1829        nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
1830        #
1831        if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
1832          IGCM_debug_Print 2 "Parallelism with 1 file. Rebuilding ${file_in} not needed"
1833          IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
1834        elif [ ${nb_rebuild_file} -gt 1 ] ; then
1835          IGCM_debug_Print 2 "Parallelism detected and rebuilding ${file_in} is needed"
1836          if [ X${AsynchronousRebuild} = Xfalse ] ; then
1837            IGCM_debug_Print 2 "Rebuilding ${file_in} online"
1838            #
1839            # for output.abort file, let use rebuild_NEMO : 13s instead of 20 mn.
1840            if [ ${file_in} = output.abort.nc ] ; then
1841              IGCM_sys_rebuild_nemo ${generic_file_name} ${nb_rebuild_file} "nc" ${generic_file_name}_[0-9]*.nc
1842            else
1843              IGCM_sys_rebuild ${file_in} ${generic_file_name}_????.nc
1844            fi
1845          else
1846            IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
1847            IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1848
1849            # Prepare the shell dedicated to offline rebuild
1850            if [ $DRYRUN -le 1 ]; then
1851              if [ ${file_in} = histstn.nc ] ; then
1852                echo "IGCM_sys_rebuild_station ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1853              else
1854                echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_[0-9]*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1855              fi
1856              echo "IGCM_debug_Verif_Exit" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1857            fi
1858            #
1859            # Load Patch we need to apply and apply
1860            if [ $DRYRUN -le 1 ]; then
1861              if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
1862                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ) ; do
1863                  echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1864                  echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1865                  echo "IGCM_debug_Verif_Exit                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1866                done
1867              fi
1868            fi
1869            #
1870            if [ $DRYRUN -le 1 ]; then
1871              if [ X${Pack} = Xtrue ] ; then
1872                rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_PutBuffer_Out ${file_in} ${file_out}"
1873              else
1874                rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_Put_Out ${file_in} ${file_out}"
1875              fi
1876              rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_debug_Verif_Exit"
1877              rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_Rm ${generic_file_name}_[0-9]*.nc"
1878            fi
1879            SaveOnArchive=false
1880          fi
1881        fi
1882        #
1883        if [ ${SaveOnArchive} = true ] ; then
1884          #
1885          # Rebuild has been done online or it was not needed
1886          #
1887          # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
1888          #
1889          thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
1890          if ( [ ! X${thereisapatch} = X${NULL_STR} ] && [ ! X${thereisapatch} = X ] && [ X${AsynchronousRebuild} = Xtrue ] && [ -f ${file_in} ] ) ; then
1891            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1892            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
1893            #
1894            if [ $DRYRUN -le 1 ]; then
1895              for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ) ; do
1896                echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1897                echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1898                echo "IGCM_debug_Verif_Exit                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1899              done
1900              #
1901              if [ X${Pack} = Xtrue ] ; then
1902                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1903              else
1904                echo "IGCM_sys_Put_Out ${file_in} ${file_out}         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1905              fi
1906              echo "IGCM_debug_Verif_Exit                             " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1907              #
1908            fi
1909          else
1910            #
1911            # No Patch, No Asynchronous rebuild, online rebuild has been done or was not needed
1912            #
1913            if [ X${Pack} = Xtrue ] ; then
1914              IGCM_sys_PutBuffer_Out ${file_in} ${file_out}
1915            else
1916              IGCM_sys_Put_Out ${file_in} ${file_out}
1917            fi
1918            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1919            if [ ${nb_rebuild_file} -gt 1 ] ; then
1920              for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
1921                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
1922              done
1923            fi
1924          fi
1925        fi
1926        ((i_ = i_ +1))
1927        eval Testvar_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1928        eval Testvar=${Testvar_}
1929        if [[ ${Testvar} =~ [0-9][DMY]$ ]] ; then
1930            ((i = i+4))
1931        else
1932        (( i=i+3 ))
1933        fi
1934      done
1935    fi
1936    echo
1937  done
1938  # Append the sync call and the copy sequence to the IGCM_FlushRebuild function if needed
1939  if [ ${#rebuildedActionsList[*]} -ne 0 ] ; then
1940    echo "IGCM_sys_sync              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1941    i=0
1942    until [ ${i} -ge ${#rebuildedActionsList[*]} ]; do
1943      echo ${rebuildedActionsList[$i]} >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1944      (( i=i+1 ))
1945    done
1946  fi
1947  IGCM_debug_PopStack "IGCM_comp_Finalize"
1948}
Note: See TracBrowser for help on using the repository browser.