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

Last change on this file since 1624 was 1624, checked in by jgipsl, 4 months ago

Added possibility to declare a restart file as optional which means that libIGCM want stop if the file is not found. Only a warning will be written.

For example, in the following case, if the routing_restart file is not available when starting the model or if it is not produced, libIGCM will not stop. But if the file sechiba_rest is not available, libIGCM will stop as usual.

[RestartFiles]
List=   (sechiba_rest_out.nc, sechiba_rest.nc, sechiba_rest_in.nc) ,\
        (routing_restart.nc, routing_restart.nc, routing_start.nc, OPTIONAL)
  • Read optional argument OPTIONAL on the line where the restart file is declared.
  • Each time when a restart file is not found for coping in or out, if the argument OPTIONAL is set, then just continue. If not set, the file is considered as MANDATORY and libIGCM will exist if it is missing as before.
  • on irene-amd and jean-zay, corrected a bug for the case in config.card DataProject?=DEFAULT


  • 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: 83.8 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            (( i_ = i+2 ))
755            eval is_opt=\${${ListFilesName}[$i_]} > /dev/null 2>&1
756            if [ X${is_opt} = XOPTIONAL ] ; then
757                echo ${file_in} is optional
758                (( i=i+4 ))
759            else
760                is_opt="MANDATORY"
761                echo ${file_in} is mandatory
762                (( i=i+3 ))
763            fi
764            IGCM_debug_Print 3 "Now search for restart file ${file_in} which is ${is_opt} (in section do_start=y)"
765
766            eval Date_tmp=\${config_${comp}_RestartDate}
767            Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
768            # will be re-use
769            eval RestartPath=\${config_${comp}_RestartPath}
770            eval RestartJobName=\${config_${comp}_RestartJobName}
771            #
772            Path_r=${RestartPath}/${RestartJobName}/${CompOldName}/Restart
773            file_in_Name=${RestartJobName}_${Date_r}_${file_in}
774
775            extension_in=$( echo ${file_in_Name##*.} )
776            extension_out=$( echo ${file_out##*.} )
777
778            generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
779            generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
780
781            Path_OUT=${Path_r}/${generic_restart_file_name_in}
782
783            if [ $( IGCM_sys_TestFileBuffer ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
784              IGCM_debug_Print 3 "Buffered restart ${Path_OUT}*.${extension_in} "
785              Buffered=true
786              Archived=false
787              Tared=false
788              nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_OUT}_????.${extension_in})
789            elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
790              IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
791              Buffered=false
792              Archived=true
793              Tared=false
794              nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
795            else
796              IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
797              IGCM_debug_Print 3 "${Path_OUT}*.${extension_in} do not exist"
798              IGCM_debug_Print 3 "Restart files will now be searched for in : ${RestartPath}/${RestartJobName}/RESTART"
799              Buffered=false
800              Archived=false
801              Tared=true
802              # Look after the tar file we want if we did not found it already
803              if [ X${IsMatching} = X ] ; then
804                IGCM_sys_TestDirArchive ${RestartPath}/${RestartJobName}/RESTART
805                if [ $? ] ; then
806                  for PotentialTarFile in $( IGCM_sys_RshArchive "find ${RestartPath}/${RestartJobName}/RESTART -name "${RestartJobName}_*restart*.tar" -print" ) ; do
807                    IsMatching=$( echo ${PotentialTarFile##*/} | \
808                      sed "s:_restart::" | \
809                      sed "s:^${RestartJobName}_::" | \
810                      sed "s:\.tar$::" | \
811                      gawk -F_ -v restartdate=${Date_r} \
812                      '{if (($1 <= restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
813                    if [ ! X${IsMatching} = X ] ; then
814                      TarFileFound=${PotentialTarFile}
815                      break
816                    fi
817                  done
818                fi
819                # Stop here if nothing has been found
820                if [ X${TarFileFound} = X ] ; then
821                  IGCM_debug_Print 3 "Restart files were not found!"
822                  IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
823                  IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
824                  if [ ${is_opt} = 'OPTIONAL' ] ; then
825                    IGCM_debug_Print 3 "The restart file is optional. Now continue."
826                    nb_restart_file=0
827                    Tared=false
828                  else
829                    IGCM_debug_Exit "Please double check restart settings in config.card"
830                    IGCM_debug_Verif_Exit
831                  fi
832                fi     
833              fi
834
835              if [ X${Tared} = Xtrue ] ; then
836                # The tar file exist but not sure all files are inside
837                IGCM_sys_PrepareTaredRestart ${TarFileFound}
838                TarFileLocation=$( basename ${TarFileFound} )
839                nb_files=$( tar tvf ${TarFileLocation} | grep ${comp}_${generic_restart_file_name_in}*.${extension_in} | wc -l )
840                if [ ${nb_files} -gt 0 ] ; then
841                    IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
842                    tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
843                    nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
844                else
845                    # No file was found
846                    if [ ${is_opt} = 'OPTIONAL' ] ; then
847                        IGCM_debug_Print 3 "The restart file is not found in the tar file but it is optional. Now continue."
848                        nb_restart_file=0
849                        Tared=false
850                    else
851                        IGCM_debug_Print 3 "The restart file was not found in the tar file but it is mandatory."
852                        IGCM_debug_Exit "Please double check restart settings in config.card"
853                        IGCM_debug_Verif_Exit
854                    fi
855                fi
856              fi
857            fi
858           
859            if [ ${nb_restart_file} -gt 1 ] ; then
860              j=0                                      # BASH LINE NOT NEEDED
861              # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
862              until [ $j -ge ${nb_restart_file} ]; do  # BASH LINE NOT NEEDED
863                j4=${j}                                # BASH LINE NOT NEEDED
864                if [ X${Buffered} = Xtrue ] ; then
865                  IGCM_sys_GetBuffer ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
866                elif [ X${Archived} = Xtrue ] ; then
867                  IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
868                elif [ X${Tared} = Xtrue ] ; then
869                  IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
870                fi
871                (( j=j+1 ))                            #BASH LINE NOT NEEDED
872              done
873
874              # OCE SPECIFIC TO REBUILD RESTART WHEN NUMBER OF RESTART FILES DONT MATCH MPI PROCESS
875              if [ X${OCE_PROC_MPI} != X ] ; then
876                if [ ${OCE_PROC_MPI} -ne ${nb_restart_file} ] ; then
877                  IGCM_sys_rebuild_nemo ${generic_restart_file_name_out} ${nb_restart_file} ${extension_out} ${generic_restart_file_name_out}_????.${extension_out}
878                  IGCM_sys_Rm ${generic_restart_file_name_out}_????.${extension_out}
879                fi
880              fi
881            else
882              if [ X${Buffered} = Xtrue ] ; then
883                IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
884              elif [ X${Archived} = Xtrue ] ; then
885                IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
886              elif [ X${Tared} = Xtrue ] ; then
887                if [ -f ${comp}_${file_in_Name} ] ; then
888                   # The file exixt
889                   IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
890                elif [ ${is_opt} = 'OPTIONAL' ] ; then
891                   IGCM_debug_Print 3 "The restart file is not found in the tar file but it is optional. Now continue."
892                else
893                   IGCM_debug_Print 3 "The restart file was not found in the tar file but it is mandatory."
894                   IGCM_debug_Exit "Please double check restart settings in config.card"
895                   IGCM_debug_Verif_Exit
896                fi
897              fi
898            fi
899          done
900        else
901          if [ X${FileName0} != XNONE ] ; then
902            IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
903          else
904            IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
905          fi
906        fi
907      fi
908    elif ( [ ${Period} -eq 1 ] && [ ${DRYRUN} -eq 0 ] ) ; then
909      # if not FirstInitialize and first loop of this job
910
911      # Restore Restarts files
912      #-----------------------
913      if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
914        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
915
916        (( i=1 ))
917        until [ $i -gt $NbFiles ]; do
918          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
919          eval file_in=${file_in_}
920
921          (( i_ = i+1 ))
922          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
923          eval file_out=${file_out_}
924
925          (( i_ = i+2 ))
926          eval is_opt=\${${ListFilesName}[$i_]} > /dev/null 2>&1
927          if [ X${is_opt} = XOPTIONAL ] ; then
928              # Read a forth argument
929              echo ${file_in} is optional
930              (( i=i+4 ))
931          else
932              is_opt="MANDATORY"
933              echo ${file_in} is mandatory
934              (( i=i+3 ))
935          fi
936
937          IGCM_debug_Print 3 "Now search for restart file ${file_in} which is ${is_opt} (in section do_start=n)"
938
939          file_in_Name=${config_UserChoices_JobName}_${LastPeriodDateEnd}_${file_in}
940
941          extension_in=$( echo ${file_in_Name##*.} )
942          extension_out=$( echo ${file_out##*.} )
943
944          generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
945          generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
946
947          eval Path_BUF=\${R_BUF_${comp}_R}/${generic_restart_file_name_in}
948          eval Path_OUT=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
949
950          if [ $( IGCM_sys_TestFileBuffer ${Path_BUF}*.${extension_in} ; echo $? ) = 0 ] ; then
951            IGCM_debug_Print 3 "Buffered restart ${Path_BUF}*.${extension_in}"
952            Buffered=true
953            Archived=false
954            Tared=false
955            nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_BUF}_????.${extension_in})
956          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
957            IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
958            Buffered=false
959            Archived=true
960            Tared=false
961            nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
962          else
963            IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
964            IGCM_debug_Print 3 "Restart files will now be searched for in : ${R_SAVE}/RESTART"
965            Buffered=false
966            Archived=false
967            Tared=true
968            # Look after the tar file we want if we did not found it already
969            if [ X${IsMatching} = X ] ; then
970              for PotentialTarFile in $( IGCM_sys_RshArchive "find ${R_SAVE}/RESTART -name "${config_UserChoices_JobName}_*_restart.tar" -print" ) ; do
971                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}}' )
972                if [ ! X${IsMatching} = X ] ; then
973                  TarFileFound=${PotentialTarFile}
974                  break
975                fi
976              done
977            fi
978            # Stop here if nothing has been found
979            if [ X${TarFileFound} = X ] ; then
980              IGCM_debug_Print 3 "Restart files were not found!"
981              IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
982              IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
983              if [ ${is_opt} = 'OPTIONAL' ] ; then
984                 IGCM_debug_Print 3 "The restart file is optional. Now continue."
985                 nb_restart_file=0
986                 Tared=false
987              else
988                 IGCM_debug_Print 3 "The restart file is mandatory."
989                 IGCM_debug_Exit "Please double check restart settings in config.card"
990                 IGCM_debug_Verif_Exit
991              fi
992            else
993              # The tar file exist but not sure all files are inside
994              IGCM_sys_PrepareTaredRestart ${TarFileFound}
995              TarFileLocation=$( basename ${TarFileFound} )
996              nb_files=$( tar tvf ${TarFileLocation} | grep ${comp}_${generic_restart_file_name_in}*.${extension_in} | wc -l )
997              if [ ${nb_files} -gt 0 ] ; then
998                IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
999                tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
1000                nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
1001              else
1002                # No file was found
1003                if [ ${is_opt} = 'OPTIONAL' ] ; then
1004                  IGCM_debug_Print 3 "The restart file is not found in the tar file but it is optional. Now continue."
1005                  nb_restart_file=0
1006                  Tared=false
1007                else
1008                  IGCM_debug_Print 3 "The restart file was not found in the tar file but it is mandatory."
1009                  IGCM_debug_Exit "Please double check restart settings in config.card"
1010                  IGCM_debug_Verif_Exit
1011                fi
1012              fi
1013
1014            fi
1015          fi
1016
1017          if [ ${nb_restart_file} -gt 1 ] ; then
1018            j=0                                     # BASH LINE NOT NEEDED
1019            #BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
1020            until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
1021              j4=${j}                               # BASH LINE NOT NEEDED
1022              if [ X${Buffered} = Xtrue ] ; then
1023                IGCM_sys_GetBuffer ${Path_BUF}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
1024              elif [ X${Archived} = Xtrue ] ; then
1025                IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
1026              elif [ X${Tared} = Xtrue ] ; then
1027                IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
1028              fi
1029              (( j=j+1 ))                           # BASH LINE NOT NEEDED
1030            done
1031          else
1032            if [ X${Buffered} = Xtrue ] ; then
1033              eval IGCM_sys_GetBuffer \${R_BUF_${comp}_R}/${file_in_Name} ${file_out}
1034            elif [ X${Archived} = Xtrue ] ; then
1035              eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
1036            elif [ X${Tared} = Xtrue ] ; then
1037              IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
1038            fi
1039          fi
1040        done
1041      else
1042        if [ X${FileName0} != XNONE ] ; then
1043          IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
1044        else
1045          IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
1046        fi
1047      fi
1048    fi
1049  done
1050
1051  NbFiles=$( ls * 2> /dev/null | wc -l )
1052  if [ ${NbFiles} -gt 0 ] ; then
1053    IGCM_sys_Chmod u+rw *
1054  fi
1055
1056  IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
1057}
1058
1059#=======================================================================
1060function IGCM_comp_GetInputBinaryFiles
1061{
1062  IGCM_debug_PushStack "IGCM_comp_GetInputBinaryFiles"
1063
1064  # Debug Print :
1065  echo
1066  IGCM_debug_Print 1 "IGCM_comp_GetInputBinaryFiles"
1067  echo
1068
1069  # Clean up previous pass
1070  [ -f ${RUN_DIR}/compiler.txt ] && rm -f ${RUN_DIR}/compiler.txt
1071
1072  typeset comp ExeNameIn ExeNameOut byPass
1073  typeset compilerNmbr compilerUnit compilerFull
1074  byPass=false
1075  for comp in ${config_ListOfComponents[*]} ; do
1076    # Define component
1077
1078    # Copy executable for this component
1079    eval ExeNameIn=\${config_Executable_${comp}[0]}
1080    eval ExeNameOut=\${config_Executable_${comp}[1]}
1081    # Test if missing executable and DRYRUN is set to 0 or 1, then stop!
1082    if [ ${DRYRUN} -le 1 ] && [ X${ExeNameIn} != X\"\" ] ; then
1083        # The executable is set in config.card and is different from ""
1084        # Use eval to expand ExeNameIn if variables are used in the name
1085        eval ExeNameIn=${ExeNameIn}
1086        if [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
1087            IGCM_debug_Exit "IGCM_comp_GetInputBinaryFiles missing executable ${ExeNameIn}"
1088        fi
1089    fi
1090
1091    if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
1092      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1093      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1094        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1095      fi
1096    elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
1097      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1098      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1099        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1100      fi
1101    fi
1102
1103    if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1104      # Get the compiler version
1105      compilerFull=$( strings ${RUN_DIR}/${ExeNameOut}  | grep "RTL Message Catalog" | gawk '{print $6}' | gawk -F. '{print $1}' )
1106      compilerVersion=$( strings ${RUN_DIR}/${ExeNameOut}  | grep "RTL Message Catalog" | gawk '{print $6}' | gawk -F. '{print $1}' )
1107      # Save it
1108      echo $compilerFull >> ${RUN_DIR}/compiler.txt
1109      [ X${compilerFull} = X ] && byPass=true
1110      IGCM_debug_Print 1 "${RUN_DIR}/${ExeNameOut} has been compiled with ${compilerFull}"
1111      IGCM_debug_Print 1 "Compiler is ${compilerVersion}"
1112    fi
1113  done
1114
1115  compilerNmbr=$( cat ${RUN_DIR}/compiler.txt | wc -l )
1116  compilerUnit=$( cat ${RUN_DIR}/compiler.txt | sort | uniq -c )
1117
1118  if ( [ ${compilerNmbr} -ne ${compilerUnit} ] && [ ! X${byPass} = Xtrue  ] ); then
1119    IGCM_debug_Exit "Binaries has not been compiled with the same compiler version"
1120  fi
1121
1122
1123  IGCM_debug_PopStack "IGCM_comp_GetInputBinaryFiles"
1124}
1125
1126#=======================================================================
1127function IGCM_comp_PeriodStart
1128{
1129  IGCM_debug_PushStack "IGCM_comp_PeriodStart"
1130
1131  # Debug Print :
1132  echo
1133  IGCM_debug_Print 1 "IGCM_comp_PeriodStart"
1134  echo
1135
1136  typeset ExeNameIn ExeNameOut
1137  typeset comp compname comptagname
1138  for comp in ${config_ListOfComponents[*]} ; do
1139    # Define component
1140    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1141    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1142
1143    # Copy executable for this component
1144    eval ExeNameIn=\${config_Executable_${comp}[0]}
1145    eval ExeNameIn=${ExeNameIn}
1146    eval ExeNameOut=\${config_Executable_${comp}[1]}
1147
1148    # Debug Print
1149    IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
1150    # UPDATE component
1151    ${comp}_PeriodStart 2> /dev/null
1152
1153  done
1154
1155  IGCM_debug_PopStack "IGCM_comp_PeriodStart"
1156}
1157
1158
1159
1160#=======================================================================
1161function IGCM_comp_modifyFile
1162{
1163#
1164# syntax:     IGCM_comp_modifyFile  filein  key  [value]
1165#
1166# For example : IGCM_comp_modifyFile metrics_template.py case_id \'SE_${YEARS}\'
1167#
1168# This function is used to replace a pattern in a file for a specific variable.
1169#
1170# Arguments:
1171# - filein : the file in run directory in which the variable should be set
1172# - key    : the variable to modify
1173# - value  : the value to set the key equal to
1174#
1175  IGCM_debug_PushStack "IGCM_comp_modifyFile"
1176
1177  typeset filein key value pattern
1178
1179  # Set local variables and test the arguments
1180  if [ $# = 3 ] ; then
1181    # Normal case with 3 arguments
1182    filein=$1 ; key=$2 ; value=$3
1183  else
1184    IGCM_debug_Exit "IGCM_comp_modifyFile: Bad number of arguments."
1185    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1186    return
1187  fi
1188  IGCM_debug_Print 1 "Entering IGCM_comp_modifyFile with arguments: ${filein} ${key} ${value}"
1189
1190  # Test if the file exist
1191  if [ ! -f ${filein} ] ; then
1192    IGCM_debug_Exit "IGCM_comp_modifyFile: ${filein} does not exist."
1193    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1194    return
1195  fi
1196
1197  # Read the line with key in the file without the comments
1198  pattern=$( grep "^ *${key} *=" ${filein} | sed -e "s% *\!.*%%" )
1199
1200  # Verify the existance of the pattern
1201  if [ X"${pattern}" = X ] ; then
1202    # Variable key is not set in filein, stop.
1203    IGCM_debug_Exit "IGCM_comp_modifyFile : Variable ${key} is not set in correct file. It should be set in ${filein}."
1204    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1205    return
1206  fi
1207
1208  # Now change key in filein
1209  #sed -e "s:${pattern}:${key}=${value}:" ${filein} > ${filein}.tmp
1210  sed -e "s:^ *${key} *=.*:${key}=${value}:" ${filein} > ${filein}.tmp
1211  IGCM_debug_Print 1 "IGCM_comp_modifyFile: In ${filein} set ${key}=${value}"
1212  \mv ${filein}.tmp ${filein}
1213 
1214  IGCM_debug_PopStack "IGCM_comp_modifyFile"
1215}
1216
1217#=======================================================================
1218function IGCM_comp_modifyDefFile
1219{
1220#
1221# syntax:     IGCM_comp_modifyDefFile  type  filein  key  [value]
1222#
1223# For example : IGCM_comp_modifyDefFile blocker run.def day_step 1200
1224#
1225# This function is used to modify a parameter file for a specific variable.
1226# The file must be a ".def" file, i.e. with IOIPSL parameter file syntax.
1227# This function can be used in the comp.driver files for the components.
1228#
1229# Arguments:
1230# - type   : first argument must be blocker, nonblocker or force
1231#            For "blocker" case, the variable must be attributed the keyworld AUTO
1232#            otherwise this function will exit.
1233#            For "nonblocker" case, the user can remove or modify the variable. For
1234#            this case, as long as AUTO is not set, no modification will be done.
1235#            For "force" case, the variable will be modified even if it is not set to AUTO
1236# - filein : the file in run directory of .def type in which the variable should be set
1237# - key    : the variable to modify
1238# - value  : the value to set the key equal to, optional. If value is not set or if
1239#            value=DEFAULT, then a default value must be given in filein using syntax :
1240#            key= AUTO : DEFAULT=def_value
1241#
1242  IGCM_debug_PushStack "IGCM_comp_modifyDefFile"
1243
1244  typeset type filein key value
1245  typeset filelist nb_occ modify
1246
1247  # Set local variables and test the arguments
1248  if [ $# = 4 ] ; then
1249    # Normal case with 4 arguments
1250    type=$1 ; filein=$2 ; key=$3 ; value=$4
1251  elif [ $# = 3 ] ; then
1252    # Normal case with 3 arguments
1253    type=$1 ; filein=$2 ;       key=$3; value="DEFAULT"
1254  else
1255    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Bad number of arguments."
1256    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1257    return
1258  fi
1259  IGCM_debug_Print 1 "Entering IGCM_comp_modifyDefFile with arguments: ${type} ${filein} ${key} ${value}"
1260
1261  # Test if first argument is correct
1262  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1263    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Error in first argument must be blocker, nonblocker or force"
1264    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1265    return
1266  fi
1267
1268  # Test if the file exist.
1269  # Exit with error if the file does not exist for the case blocker or force.
1270  # Only return for the case nonblocker.
1271  if [ ! -f ${filein} ] ; then
1272    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1273      IGCM_debug_Exit "IGCM_comp_modifyDefFile: ${filein} does not exist."
1274    else
1275      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${filein} does not exist. Nothing will be done for this file."
1276    fi
1277    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1278    return
1279  fi
1280
1281  # Define list of files to test using all files with suffix .def (except used*.def)
1282  filelist=$( ls *def | grep -v used )
1283
1284  # Count number of occurances for the key in all files
1285  nb_occ=$( grep -w ${key} ${filelist} | grep -v "#"  | wc -l )
1286
1287  # Test if key is set several times
1288  if [ ${nb_occ} -gt 1 ] ; then
1289    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in ${filein}: Variable=${key} is set ${nb_occ} times"
1290    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1291    return
1292  fi
1293
1294  # Treatement according to different cases
1295  if [ ${nb_occ} -eq 0 ] && [ ${type} = blocker ] ; then
1296    # Stop if the key is never set and the function is blocker
1297    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in ${filein}: Variable=${key} has been removed but this function is blocker. "
1298    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: restore ${filein} for variable ${key}."
1299  elif [ ${nb_occ} -eq 0 ] && [ ${type} = nonblocker ] ; then
1300    # The key is not set but it is a nonblocker call so nothing is done.
1301    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key} is not set in ${filein}. This is a nonblocker call so nothing is done."
1302    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: Default value for ${key} from the model will be used."
1303    modify=no
1304  elif [ $( grep ${key} ${filein} | grep -v "\#"  |wc -l ) = 0 ] ; then
1305    # Variable key is not set in filein, stop.
1306    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Variable ${key} is not set in correct file. It should be set in ${filein}."
1307  fi
1308
1309  # Check if AUTO is set in the filein on the same line as the key variable
1310  if [ $( grep -w ${key} ${filein} | grep -v "\#" | grep AUTO | wc -l ) = 1 ] ; then
1311    # Modification will be done for all cases
1312    modify=yes
1313  else
1314    # The variable was not set to AUTO
1315    if [ ${type} = blocker ] ; then
1316      # Exit because this is a blocker call
1317      IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable ${key} cannot be modified. It should be set to AUTO."
1318      IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1319      return
1320    elif [ ${type} = nonblocker ] ; then
1321      # Do nothing. Suppose that the user did set the variable correct
1322      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key} is set by the user. Nothing done."
1323      modify=no
1324    elif [ ${type} = force ] ; then
1325      # Force modification
1326      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile : Variabl=${key} was not set to AUTO. Modification will be forced."
1327      modify=yes
1328    fi
1329  fi
1330
1331  # Do the modifcation now
1332  if [ ${modify} = yes ] ; then
1333
1334    # For option DEFAULT, read default value from file.
1335    if [ X"${value}" = XDEFAULT ] || [ X"${value}" = X ] ; then
1336      # Case to set DEFAULT value
1337      # Read default value from filein
1338      value=$( grep -w ${key} ${filein} | grep -v "\#" | awk  -F"DEFAULT *=" '{print $2}')
1339
1340      if [ X"${value}" = X ] ; then
1341        IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable ${key} needs a DEFAULT value in ${filein}."
1342        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: The syntax in ${filein} should be:"
1343        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key}=_AUTO_:DEFAULT=def_value"
1344        IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1345        return
1346      fi
1347    fi
1348
1349    # Now change key in filein
1350    sed -e "s/^${key}\ *=.*/${key}= ${value}/" ${filein} > ${filein}.tmp
1351    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: In ${filein} set ${key}=${value}"
1352    \mv ${filein}.tmp ${filein}
1353  fi
1354  IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1355}
1356
1357#=======================================================================
1358function IGCM_comp_modifyNamelist
1359{
1360#
1361# syntax:     IGCM_comp_modifyNamelist  type  filein  key  [value]
1362#
1363# For example : IGCM_comp_modifyNamelist blocker run.def day_step 1200
1364#
1365# This function is used to modify a parameter file for a specific variable.
1366# The file must be a "namelist" file, i.e. with fortran namelist syntax.
1367# This function can be used in the comp.driver files for the components.
1368#
1369# Arguments:
1370# - type   : first argument must be blocker, nonblocker or force
1371#            For "blocker" case, the variable must be attributed the keyworld AUTO
1372#            otherwise this function will exit.
1373#            For "nonblocker" case, the user can remove or modify the variable. For
1374#            this case, as long as AUTO is not set, no modification will be done.
1375#            For "force" case, the variable will be modified even if it is not set to AUTO
1376# - filein : the file in run directory of .def type in which the variable should be set
1377# - key    : the variable to modify
1378# - value  : the value to set the key equal to, optional. If value is not set or if
1379#            value=DEFAULT, then a default value must be given in filein using syntax :
1380#            key= AUTO : DEFAULT=def_value
1381#
1382  IGCM_debug_PushStack "IGCM_comp_modifyNamelist"
1383
1384  typeset type filein key value pattern modify
1385
1386  # Set local variables and test the arguments
1387  if [ $# = 4 ] ; then
1388    # Normal case with 4 arguments
1389    type=$1 ; filein=$2 ; key=$3 ; value=$4
1390  elif [ $# = 3 ] ; then
1391    # Normal case with 3 arguments
1392    type=$1 ; filein=$2 ;       key=$3; value="DEFAULT"
1393  else
1394    IGCM_debug_Exit "IGCM_comp_modifyNamelist: Bad number of arguments."
1395    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1396    return
1397  fi
1398  IGCM_debug_Print 1 "Entering IGCM_comp_modifyNamelist with arguments: ${type} ${filein} ${key} ${value}"
1399
1400  # Test if first argument is correct
1401  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1402    IGCM_debug_Exit "IGCM_comp_modifyNamelist: Error in first argument must be blocker, nonblocker or force"
1403    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1404    return
1405  fi
1406
1407  # Test if the file exist.
1408  # Exit with error if the file does not exist for the case blocker or force.
1409  # Only return for the case nonblocker.
1410  if [ ! -f ${filein} ] ; then
1411    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1412      IGCM_debug_Exit "IGCM_comp_modifyNamelist: ${filein} does not exist."
1413    else
1414      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${filein} does not exist. Nothing will be done for this file."
1415    fi
1416    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1417    return
1418  fi
1419
1420  # Read the line with key in the file without the comments
1421  pattern=$( grep "^ *${key} *=" ${filein} | sed -e "s% *\!.*%%" )
1422
1423  # Verify the existance of the pattern
1424  if [ X"$pattern" = X ] ; then
1425    # Variable key is not set in filein, stop.
1426    IGCM_debug_Exit "IGCM_comp_modifyNamelist : Variable ${key} is not set in correct file. It should be set in ${filein}."
1427    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1428    return
1429  fi
1430
1431  # Check if the variable is set to AUTO in the filein
1432  if [ $( echo $pattern | grep AUTO | wc -l ) = 1 ] ; then
1433    # Modification will be done for all cases
1434    modify=yes
1435  else
1436    # The variable was not set to AUTO
1437    if [ ${type} = blocker ] ; then
1438      # Exit because this is a blocker call
1439      IGCM_debug_Exit "IGCM_comp_modifyNamelist : The variable ${key} cannot be modified. It should be set to AUTO."
1440      IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1441      return
1442    elif [ ${type} = nonblocker ] ; then
1443      # Do nothing. Suppose that the user did set the variable correct
1444      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${key} is set by the user. Nothing done."
1445      modify=no
1446    elif [ ${type} = force ] ; then
1447      # Force modification
1448      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist : Variabl=${key} was not set to AUTO. Modification will be forced."
1449      modify=yes
1450    fi
1451  fi
1452
1453  # Do the modifcation now
1454  if [ ${modify} = yes ] ; then
1455
1456    # For option DEFAULT, read default value from file.
1457    if [ X"${value}" = XDEFAULT ] || [ X"${value}" = X ] ; then
1458      # Case to set DEFAULT value
1459      # Read default value from filein
1460      value=$( echo $pattern | awk  -F"DEFAULT *=" '{print $2}')
1461
1462      if [ X"${value}" = X ] ; then
1463        IGCM_debug_Exit "IGCM_comp_modifyNamelist : The variable ${key} needs a DEFAULT value in ${filein}."
1464        IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: The syntax in ${filein} should be:"
1465        IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${key}=_AUTO_:DEFAULT=def_value"
1466        IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1467        return
1468      fi
1469    fi
1470
1471    # Now change key in filein
1472    sed -e "s/${pattern}/       ${key}=${value}/" ${filein} > ${filein}.tmp
1473    IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: In ${filein} set ${key}=${value}"
1474    \mv ${filein}.tmp ${filein}
1475  fi
1476  IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1477}
1478
1479#=======================================================================
1480function IGCM_comp_modifyXmlFile
1481{
1482#
1483# syntax:     IGCM_comp_modifyXmlFile  type  filein  keyid  keyattrib  value
1484#
1485# For example : IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba2 enabled .TRUE.
1486#          or   IGCM_comp_modifyXmlFile blocker iodef.xml using_server NONE false
1487#
1488# This function is used to modify the value for a specific attribute and variable id.
1489# The file must be a valid xml file.
1490# This function can be used in the comp.driver files for the components.
1491#
1492# Arguments:
1493# - type      : first argument must be blocker, nonblocker or force.
1494#               For "blocker" case, the variable must be attributed the keyworld AUTO
1495#               otherwise this function will exit.
1496#               For "nonblocker" case, the user can remove or modify the variable. For
1497#               this case, as long as AUTO is not set, no modification will be done.
1498#               For "force" case, the variable will be modified even if it is not set to AUTO
1499# - filein    : the file in run directory of .xml type in which the variable should be set
1500# - keyid     : the variable to modify
1501# - keyattrib : the attribute name to modify. If NONE, then the variable itself will be modified
1502# - value     : the value to set in the filein
1503#
1504  IGCM_debug_PushStack "IGCM_comp_modifyXmlFile"
1505
1506  typeset type filein keyid keyattrib value modify
1507
1508  # Set local variables and test the arguments
1509  if [ $# = 5 ] ; then
1510    # Normal case with 4 arguments
1511    type=$1 ; filein=$2 ; keyid=$3 ; keyattrib=$4 ; value=$5
1512  else
1513    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Bad number of arguments."
1514    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1515    return
1516  fi
1517  IGCM_debug_Print 1 "Entering IGCM_comp_modifyXmlFile with arguments: type=${type} file=${filein}, id=${keyid} attribute=${keyattrib}, value=${value}"
1518
1519  # Test if first argument is correct
1520  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1521    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Error in first argument must be blocker, nonblocker or force"
1522    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1523    return
1524  fi
1525
1526  # Test if the file exist.
1527  # Exit with error if the file does not exist for the case blocker or force.
1528  # Only return for the case nonblocker.
1529  if [ ! -f ${filein} ] ; then
1530    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1531      IGCM_debug_Exit "IGCM_comp_modifyXmlFile: ${filein} does not exist."
1532    else
1533      IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile: ${filein} does not exist. Nothing will be done for this file."
1534    fi
1535    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1536    return
1537  fi
1538
1539  # Test if keyid is set in filein. If not exit for case all cases(blocker, force) except nonblocker.
1540  if [ $( grep -w ${keyid} ${filein} | wc -l ) = 0 ] ; then
1541      if [ ${type} = nonblocker ] ; then
1542          # This is a nonblocker case, print warning but do nothing else
1543          IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile: ${keyid} is not set in ${filein}. This is a nonblocker call so nothing is done."
1544      else
1545          # This is a blocker or force case : stop now
1546          IGCM_debug_Exit "IGCM_comp_modifyXmlFile : ${keyid} is not set in the file. Bad syntax of ${filein} file."
1547          IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1548          return
1549      fi
1550  fi
1551
1552  # Check if AUTO is set on the same line as keyid and keyattrib
1553  if [  $( grep -w ${keyid} ${filein} | grep AUTO | wc -l ) = 1 ] ; then
1554    # Modification will be done
1555    modify=yes
1556  else
1557    if [ ${type} = blocker ] ; then
1558      # Exit, the variable must be set to AUTO
1559      IGCM_debug_Exit "IGCM_comp_modifyXmlFile : blocker function. The ${keyattrib} for ${keyid} must be set to AUTO in ${filein}."
1560      IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1561      return
1562    elif [ ${type} = nonblocker ] ; then
1563      # Nothing will be done
1564      IGCM_debug_Print 1 "Nonblocker nothing is done for ${filein}, id=${keyid} and attribute ${keyattrib}"
1565      modify=no
1566    elif [ ${type} = force ] ; then
1567      # Force modification
1568      IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile : Attribute=${keyattrib} for id=${keyid} was not set to AUTO. Modification will be forced."
1569      modify=yes
1570    fi
1571  fi
1572
1573  # Do the modifcation now
1574  if [ ${modify} = yes ] ; then
1575    if [ ${keyattrib} = NONE ] ; then
1576      # Case to modify the variable itself
1577      IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting the variable=${value}"
1578      sed -e "s/\(<[^\"]*\"${keyid}\".*>\)\([^<]*\)\(<[^>]*\)/\1${value}\3/" ${filein} > ${filein}.tmp
1579    else
1580      # Check if keyattrib is set on the same line as keyid
1581      if [  $( grep -w ${keyid} ${filein} | grep ${keyattrib} | wc -l ) = 1 ] ; then
1582        # Case to modify the attribute value
1583        IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting attribute to ${keyattrib}=${value}"
1584        sed -e "/id=\"${keyid}\"/s/\(${keyattrib}=\"\)[^\"]*\(\"\)/\1${value}\2/" ${filein} > ${filein}.tmp
1585      else
1586        # Case to add the attribute and its value
1587        IGCM_debug_Print 1 "Now add in ${filein} for id=${keyid} the attribute ${keyattrib} to the value ${value}"
1588        sed -e "/id=\"${keyid}\"/s/\/>/ ${keyattrib}=\"${value}\"\/>/" ${filein} > ${filein}.tmp
1589      fi
1590    fi
1591    \mv ${filein}.tmp ${filein}
1592  fi
1593  IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1594}
1595
1596#=======================================================================
1597function IGCM_comp_Update
1598{
1599  IGCM_debug_PushStack "IGCM_comp_Update"
1600
1601  # Debug Print :
1602  echo
1603  IGCM_debug_Print 1 "IGCM_comp_Update"
1604  echo
1605
1606  typeset comp compname comptagname
1607  for comp in ${config_ListOfComponents[*]} ; do
1608    # Define component
1609    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1610    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1611
1612    # Debug Print
1613    IGCM_debug_Print 1 "Update ${compname} Parameter Files."
1614    # UPDATE component
1615    ${comp}_Update
1616
1617    # Read TimeSeries information from XML files, prepare TS directories and do modifications in timeseries_def_${compname}.xml
1618    if [ -f timeseries_def_${compname}.xml ]; then
1619      ${libIGCM}/libIGCM_post/xios_parser.py tsquery --file timeseries_def_${compname}.xml > ts.temp.${compname}.txt
1620      for line in $( cat ts.temp.${compname}.txt ); do
1621        output_freq=$( echo ${line} | awk -F "," '{print $1}' | awk -F "=" '{print $2}' )
1622        id=$(          echo ${line} | awk -F "," '{print $2}' | awk -F "=" '{print $2}' )
1623        case ${output_freq} in
1624        *Y|*y)
1625          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_Y}
1626          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_Y}/${config_UserChoices_JobName}
1627          ;;
1628        *MO|*mo)
1629          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_M}
1630          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_M}/${config_UserChoices_JobName}
1631          ;;
1632        *D|*d)
1633          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_D}
1634          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_D}/${config_UserChoices_JobName}
1635          ;;
1636        *S|*s)
1637          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_H}
1638          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_H}/${config_UserChoices_JobName}
1639          ;;
1640        esac
1641      done
1642    fi
1643
1644    # Read TimeSeries information from XML files, prepare CMIP6 TS directories and do modifications in dr2xml_${compname}.xml
1645    if [ -f dr2xml_${compname}.xml ]; then
1646      if ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then
1647        eval IGCM_sys_Mkdir \${CMIP6_BUF_${comp}}
1648        eval CMIP6_DIR=\${CMIP6_BUF_${comp}}
1649        # Modify path from dr2xml_{compname}.xml
1650        if [ X${config_Post_dr2xmlIPSL} = XTRUE ]; then
1651          ${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
1652        else
1653          ${libIGCM}/libIGCM_post/xios_parser.py -v modifyPath --newPath ${CMIP6_DIR} --file dr2xml_${compname}.xml
1654        fi
1655        # Overwrite the original file
1656        IGCM_sys_Mv modified.dr2xml_${compname}.xml dr2xml_${compname}.xml
1657      fi
1658    fi
1659  done
1660
1661  IGCM_debug_PopStack "IGCM_comp_Update"
1662}
1663
1664#=======================================================================
1665function IGCM_comp_Finalize
1666{
1667  IGCM_debug_PushStack "IGCM_comp_Finalize"
1668
1669  # Debug Print :
1670  echo
1671  IGCM_debug_Print 1 "IGCM_comp_Finalize"
1672  echo
1673
1674  typeset ListTextName TextName0
1675  typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
1676  typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
1677  typeset -Z4 j4 #BASH declare j4
1678  typeset list_file nlist_file
1679  typeset compactoutputs
1680
1681  # Initialize array hosting list of rebuilded files to copy
1682  unset rebuildedActionsList
1683
1684  # Text compacting options
1685  compactoutputs=false
1686  if [ X${JobType} != XRUN ] ; then
1687    compactoutputs=true
1688  elif [ X${config_UserChoices_CompactText} != Xn ] ; then
1689    compactoutputs=true
1690  fi
1691
1692  # Prepare headers for the shell dedicated to offline rebuild
1693  if [ X${AsynchronousRebuild} = Xtrue ] ; then
1694    [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1695    if [ ${DRYRUN} -le 1 ] ; then
1696      echo "#!/bin/ksh                                        " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1697      echo "function IGCM_FlushRebuild                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1698      echo "{                                                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1699      echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1700      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1701      echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1702      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1703      echo "export R_SAVE=${R_SAVE}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1704      echo "export R_BUFR=${R_BUFR}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1705      echo "export R_OUT_KSH=${R_OUT_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1706      echo "export R_BUF_KSH=${R_BUF_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1707      echo "export config_UserChoices_JobName=${config_UserChoices_JobName}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1708      echo "export config_UserChoices_SpaceName=${config_UserChoices_SpaceName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1709    fi
1710  fi
1711
1712  for comp in ${config_ListOfComponents[*]} ; do
1713    # Define component
1714    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1715    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1716
1717    # Debug Print
1718    IGCM_debug_Print 1 "Finalize ${comp} : ${compname} component."
1719    # FINALIZE component
1720    ${comp}_Finalize
1721
1722    card=${SUBMIT_DIR}/COMP/${compname}.card
1723
1724    # Save Output Text files of models
1725    #---------------------------------
1726    IGCM_debug_Print 2 "Save Output Text files for ${comp} : ${compname} component."
1727    IGCM_card_DefineArrayFromOption ${card} OutputText List
1728    ListTextName=${compname}_OutputText_List
1729
1730    eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1731    if [ X${TextName0} != X${NULL_STR} ] ; then
1732      eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1733
1734      (( i=0 ))
1735      until [ $i -eq $NbFiles ]; do
1736        eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1737        eval file_out=${PREFIX}_${file_in}
1738
1739        (( i=i+1 ))
1740
1741        unset list_file
1742        #set +A list_file -- $( ls ${file_in}* | sort 2>/dev/null )
1743        # result for a a1 a10 a2 with file_in=a a a1 a2 a10
1744        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 )
1745        nlist_file=${#list_file[@]}
1746        if [ ${nlist_file} -gt 1 ] ; then
1747          if ( ${compactoutputs} ) ; then
1748            IGCM_debug_Print 2 "Parallelism of Text Output with ${nlist_file} files."
1749            IGCM_debug_Print 2 "Compact files in ${file_out} : " ${list_file[*]}
1750            echo ${list_file[*]} > ${file_out}
1751            echo "" >> ${file_out}
1752
1753            (( i_ = 0 ))
1754            for file in ${list_file[@]} ; do
1755              echo "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " >> ${file_out}
1756              echo "| " ${i_} " " ${file} >> ${file_out}
1757              echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " >> ${file_out}
1758              cat ${file} | sed "s/\(.*\)/${i_}\1/" >> ${file_out}
1759              echo "" >> ${file_out}
1760              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1761                  (( i_ = i_ + 1 ))
1762            done
1763            if ( ${ExecutionFail} ) ; then
1764              IGCM_sys_Cp ${file_out} ${SUBMIT_DIR}/Debug
1765            fi
1766
1767            if [ X${Pack} = Xtrue ] ; then
1768              eval IGCM_sys_PutBuffer_Out ${file_out} \${R_BUF_${comp}_D}/${file_out}
1769            else
1770              eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}_D}/${file_out}
1771            fi
1772
1773            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_out}" > /dev/null 2>&1
1774          else
1775            for file in ${list_file[@]} ; do
1776              if ( ${ExecutionFail} ) ; then
1777                IGCM_sys_Cp ${file} ${SUBMIT_DIR}/Debug/${PREFIX}_${file}
1778              fi
1779
1780              if [ X${Pack} = Xtrue ] ; then
1781                eval IGCM_sys_PutBuffer_Out ${file} \${R_BUF_${comp}_D}/${PREFIX}_${file}
1782              else
1783                eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
1784              fi
1785
1786              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1787            done
1788          fi
1789        else
1790          if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1791            eval IGCM_sys_Mv ${file_in}* ${file_in}
1792          fi
1793
1794          if ( ${ExecutionFail} ) ; then
1795            IGCM_sys_Cp ${file_in} ${SUBMIT_DIR}/Debug/${file_out}
1796          fi
1797
1798          if [ X${Pack} = Xtrue ] ; then
1799            eval IGCM_sys_PutBuffer_Out ${file_in} \${R_BUF_${comp}_D}/${file_out}
1800          else
1801            eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${file_out}
1802          fi
1803          eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1804        fi
1805      done
1806    fi
1807
1808    # Save Restarts files
1809    #--------------------
1810    IGCM_debug_Print 2 "Save Restart files for ${comp} : ${compname} component."
1811    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
1812    ListFilesName=${compname}_RestartFiles_List
1813    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1814   
1815    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
1816      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1817      (( i=0 ))
1818      until [ $i -ge $NbFiles ]; do
1819        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1820        eval file_in=${file_in_}
1821
1822        (( i_ = i+1 ))
1823        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1824        eval file_out=${file_out_}
1825
1826        (( i_ = i+2 ))
1827        eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1828        eval file_outin=${file_outin_}
1829
1830        (( i_ = i+3 ))
1831        eval is_opt=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1832        if [ X${is_opt} = XOPTIONAL ] ; then
1833            echo ${file_in} is optional
1834            (( i=i+4 ))
1835        else
1836            is_opt=""
1837            echo ${file_in} is mandatory
1838            (( i=i+3 ))
1839        fi
1840       
1841        generic_restart_file_name_in=$(    basename ${file_in} .nc )
1842        generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
1843        generic_restart_file_name_outin=$( basename ${file_outin} .nc )
1844
1845        nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l )
1846        if [ ${nb_restart_file} -gt 1 ] ; then
1847          j=0                                     # BASH LINE NOT NEEDED
1848          # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
1849          until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
1850            j4=${j}                               # BASH LINE NOT NEEDED
1851            if [ X${Pack} = Xtrue ] ; then
1852              eval IGCM_sys_PutBuffer_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_BUF_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc ${is_opt}
1853            else
1854              eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc ${is_opt}
1855            fi
1856
1857            if [ -f  ${generic_restart_file_name_in}_${j4}.nc ] ; then
1858                if [ ! ${file_in} = ${file_outin} ] ; then
1859                    if ( ${ExitFlag} ) ; then
1860                        echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
1861                    else
1862                        IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
1863                    fi
1864                fi
1865            else
1866                # This is the case where the restart file no not exist.
1867                # It has already been checked if the model should stop for this case.
1868                IGCM_debug_Print 1 "Restart file does not exist, no move in RUN_DIR done :  ${generic_restart_file_name_in}_${j4}.nc"
1869            fi
1870            (( j=j+1 ))                           # BASH LINE NOT NEEDED
1871          done
1872        else
1873          if [ X${Pack} = Xtrue ] ; then
1874            eval IGCM_sys_PutBuffer_Rest ${file_in} \${R_BUF_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} ${is_opt}
1875          else
1876            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} ${is_opt}
1877          fi
1878
1879          if [ -f ${file_in} ] ; then
1880              if [ ! ${file_in} = ${file_outin} ] ; then
1881                  if ( ${ExitFlag} ) ; then
1882                      echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1883                  else
1884                      IGCM_sys_Mv ${file_in} ${file_outin}
1885                  fi
1886              fi
1887          else
1888              # This is the case where the restart file no not exist.
1889              # It has already been checked if the model should stop for this case.
1890              IGCM_debug_Print 1 "Restart file does not exist, no move in RUN_DIR done :   ${file_in}"
1891          fi
1892        fi
1893
1894      done
1895    else
1896      if [ X${FileName0} != XNONE ] ; then
1897        IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
1898      else
1899        IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
1900      fi
1901    fi
1902
1903    # Save Output files
1904    #------------------
1905    IGCM_debug_Print 2 "Save Output files for ${comp} : ${compname} component."
1906    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
1907    ListFilesName=${compname}_OutputFiles_List
1908    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1909
1910    if [ X${FileName0} != X${NULL_STR} ] ; then
1911      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1912
1913      (( i=0 ))
1914      until [ $i -ge $NbFiles ]; do
1915        SaveOnArchive=true
1916        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1917        eval file_in=${file_in_}
1918        (( i_ = i+1 ))
1919        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1920        eval file_out=${file_out_}
1921        #
1922        # Override file_out path remplacing R_SAVE by R_BUFR
1923        #
1924        if [ X${Pack} = Xtrue ] ; then
1925          file_out=$( echo $file_out | sed "s:^$R_SAVE:$R_BUFR:" )
1926        fi
1927        #
1928        # Not necessarily the best option. /!\ Potential side effects /!\
1929        #
1930        (( i_ = i+2 ))
1931        eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1932        #
1933        generic_file_name=$( basename ${file_in} .nc )
1934        nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
1935        #
1936        if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
1937          IGCM_debug_Print 2 "Parallelism with 1 file. Rebuilding ${file_in} not needed"
1938          IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
1939        elif [ ${nb_rebuild_file} -gt 1 ] ; then
1940          IGCM_debug_Print 2 "Parallelism detected and rebuilding ${file_in} is needed"
1941          if [ X${AsynchronousRebuild} = Xfalse ] ; then
1942            IGCM_debug_Print 2 "Rebuilding ${file_in} online"
1943            #
1944            # for output.abort file, let use rebuild_NEMO : 13s instead of 20 mn.
1945            if [ ${file_in} = output.abort.nc ] ; then
1946              IGCM_sys_rebuild_nemo ${generic_file_name} ${nb_rebuild_file} "nc" ${generic_file_name}_[0-9]*.nc
1947            else
1948              IGCM_sys_rebuild ${file_in} ${generic_file_name}_????.nc
1949            fi
1950          else
1951            IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
1952            IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1953
1954            # Prepare the shell dedicated to offline rebuild
1955            if [ $DRYRUN -le 1 ]; then
1956              if [ ${file_in} = histstn.nc ] ; then
1957                echo "IGCM_sys_rebuild_station ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1958              else
1959                echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_[0-9]*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1960              fi
1961              echo "IGCM_debug_Verif_Exit" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1962            fi
1963            #
1964            # Load Patch we need to apply and apply
1965            if [ $DRYRUN -le 1 ]; then
1966              if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
1967                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ) ; do
1968                  echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1969                  echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1970                  echo "IGCM_debug_Verif_Exit                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1971                done
1972              fi
1973            fi
1974            #
1975            if [ $DRYRUN -le 1 ]; then
1976              if [ X${Pack} = Xtrue ] ; then
1977                rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_PutBuffer_Out ${file_in} ${file_out}"
1978              else
1979                rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_Put_Out ${file_in} ${file_out}"
1980              fi
1981              rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_debug_Verif_Exit"
1982              rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_Rm ${generic_file_name}_[0-9]*.nc"
1983            fi
1984            SaveOnArchive=false
1985          fi
1986        fi
1987        #
1988        if [ ${SaveOnArchive} = true ] ; then
1989          #
1990          # Rebuild has been done online or it was not needed
1991          #
1992          # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
1993          #
1994          thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
1995          if ( [ ! X${thereisapatch} = X${NULL_STR} ] && [ ! X${thereisapatch} = X ] && [ X${AsynchronousRebuild} = Xtrue ] && [ -f ${file_in} ] ) ; then
1996            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1997            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
1998            #
1999            if [ $DRYRUN -le 1 ]; then
2000              for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ) ; do
2001                echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2002                echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2003                echo "IGCM_debug_Verif_Exit                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2004              done
2005              #
2006              if [ X${Pack} = Xtrue ] ; then
2007                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2008              else
2009                echo "IGCM_sys_Put_Out ${file_in} ${file_out}         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2010              fi
2011              echo "IGCM_debug_Verif_Exit                             " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2012              #
2013            fi
2014          else
2015            #
2016            # No Patch, No Asynchronous rebuild, online rebuild has been done or was not needed
2017            #
2018            if [ X${Pack} = Xtrue ] ; then
2019              IGCM_sys_PutBuffer_Out ${file_in} ${file_out}
2020            else
2021              IGCM_sys_Put_Out ${file_in} ${file_out}
2022            fi
2023            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
2024            if [ ${nb_rebuild_file} -gt 1 ] ; then
2025              for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
2026                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
2027              done
2028            fi
2029          fi
2030        fi
2031        ((i_ = i_ +1))
2032        eval Testvar_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
2033        eval Testvar=${Testvar_}
2034        if [[ ${Testvar} =~ [0-9][DMY]$ ]] ; then
2035            ((i = i+4))
2036        else
2037        (( i=i+3 ))
2038        fi
2039      done
2040    fi
2041    echo
2042  done
2043  # Append the sync call and the copy sequence to the IGCM_FlushRebuild function if needed
2044  if [ ${#rebuildedActionsList[*]} -ne 0 ] ; then
2045    echo "IGCM_sys_sync              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2046    i=0
2047    until [ ${i} -ge ${#rebuildedActionsList[*]} ]; do
2048      echo ${rebuildedActionsList[$i]} >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2049      (( i=i+1 ))
2050    done
2051  fi
2052  IGCM_debug_PopStack "IGCM_comp_Finalize"
2053}
Note: See TracBrowser for help on using the repository browser.