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

Last change on this file since 1074 was 1074, checked in by jgipsl, 10 years ago

Added function IGCM_comp_modifyXmlFile

  • 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: 62.4 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 CompatibilityTag 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    # Read libIGCM compatibility version in ${compname}.card
36    card=${SUBMIT_DIR}/COMP/${compname}.card
37    IGCM_card_DefineVariableFromOption ${card} Compatibility libIGCM
38
39    eval CompatibilityTag=\${${compname}_Compatibility_libIGCM} > /dev/null 2>&1
40    if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then
41      IGCM_debug_Exit "${compname}.card is not compatible with libIGCM version ${libIGCM_CurrentTag} see libIGCM FAQ http://wiki.ipsl.jussieu.fr/wiki_ipsl/IGCMG/libIGCM/DocUtilisateur/FAQ ."
42    fi
43
44    # Manage component executable
45    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card Executable ${comp}
46
47    # Define all options in section [comp]
48    IGCM_debug_Print 3 " DefineArrayFromSection : ${comp}"
49    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ${comp}
50    eval config_comp=\${config_${comp}[*]} > /dev/null 2>&1
51    for option in ${config_comp[*]} ; do
52        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} ${option}
53    done
54    IGCM_debug_Print 3 " Found in section config_${comp} :  ${config_comp[*]} "
55
56    # Debug Print :
57    eval auxprint=\${config_${comp}_WriteFrequency}
58    IGCM_debug_Print 1 "Write frequency for ${compname} : ${auxprint} "
59    #2> /dev/null
60
61    # Debug Print :
62    IGCM_debug_Print 2 "Initialize following component library"
63
64    # Source drivers in directory DRIVER if it exist
65    # else source them from directory COMP
66    if [ -d ${SUBMIT_DIR}/DRIVER ] ; then
67      IGCM_debug_Print 2 ${SUBMIT_DIR}/DRIVER/${compname}.driver
68      # Source component library
69      . ${SUBMIT_DIR}/DRIVER/${compname}.driver
70    else
71      IGCM_debug_Print 2 ${SUBMIT_DIR}/COMP/${compname}.driver
72      # Source component library
73      . ${SUBMIT_DIR}/COMP/${compname}.driver
74    fi
75    IGCM_debug_Print 3 "With tag : ${comptagname}"
76
77    # Debug Print
78    IGCM_debug_Print 3 "Initialize ${comp} output directory."
79
80    # Define ARCHIVED Dirs
81    eval R_OUT_${comp}=${R_SAVE}/${comp}
82    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}}
83
84    eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output
85    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O}
86
87    eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart
88    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R}
89
90    eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug
91    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D}
92
93    eval R_OUT_${comp}_O_I=\${R_OUT_${comp}_O}/INS
94    eval R_OUT_${comp}_O_H=\${R_OUT_${comp}_O}/HF
95    eval R_OUT_${comp}_O_D=\${R_OUT_${comp}_O}/DA
96    eval R_OUT_${comp}_O_M=\${R_OUT_${comp}_O}/MO
97    eval R_OUT_${comp}_O_Y=\${R_OUT_${comp}_O}/YE
98
99    # Define BUFFERED Dirs
100    if ( [ ! ${config_Post_PackFrequency} = NONE ] || [ X${config_UserChoices_SpaceName} = XTEST ] ) ; then
101      eval R_BUF_${comp}=${R_BUFR}/${comp}
102      eval IGCM_sys_Mkdir \${R_BUF_${comp}}
103
104      eval R_BUF_${comp}_O=\${R_BUF_${comp}}/Output
105      eval IGCM_sys_Mkdir \${R_BUF_${comp}_O}
106
107      eval R_BUF_${comp}_R=\${R_BUF_${comp}}/Restart
108      eval IGCM_sys_Mkdir \${R_BUF_${comp}_R}
109
110      eval R_BUF_${comp}_D=\${R_BUF_${comp}}/Debug
111      eval IGCM_sys_Mkdir \${R_BUF_${comp}_D}
112
113      eval R_BUF_${comp}_O_I=\${R_BUF_${comp}_O}/INS
114      eval R_BUF_${comp}_O_H=\${R_BUF_${comp}_O}/HF
115      eval R_BUF_${comp}_O_D=\${R_BUF_${comp}_O}/DA
116      eval R_BUF_${comp}_O_M=\${R_BUF_${comp}_O}/MO
117      eval R_BUF_${comp}_O_Y=\${R_BUF_${comp}_O}/YE
118    fi
119
120    # Read UserChoices section of component card
121    IGCM_debug_Print 2 "DefineArrayFromSection : ${compname}_UserChoices ${card}"
122    IGCM_card_DefineArrayFromSection ${card} UserChoices
123    eval first_option=\${${compname}_UserChoices[0]} > /dev/null 2>&1
124
125    # If section is not empty we define corresponding variables
126    if [ X${first_option} != X"Error:" ] ; then
127      if [ X${card_UserChoices[0]} != X ] ; then
128        unset card_UserChoices
129      fi
130      eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1
131      IGCM_debug_Print 3 "${compname}_UserChoices_values:"
132      for option in ${card_UserChoices[*]} ; do
133        IGCM_card_DefineVariableFromOption ${card} UserChoices ${option}
134        eval IGCM_debug_Print 3 "${option}=\${${compname}_UserChoices_${option}}"
135      done
136    fi
137
138    # Read and Build Output File stuff
139    IGCM_debug_Print 2 "DefineArrayFromOption  : ${compname}_OutputFiles ${card}"
140    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
141    ListFilesName=${compname}_OutputFiles_List
142    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
143    #
144    if [ X${FileName0} != X${NULL_STR} ] ; then
145      #
146      #IGCM_debug_Print 1 "Component      : ${compname}"
147      #
148      # INITIALISATION
149      #
150      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
151      #
152      i=2
153      #
154      until [ $i -ge $NbFiles ]; do
155        #
156        eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
157        #
158        if [ X${flag_post} != XNONE ] ; then
159          #
160          # First of all
161          #
162          IGCM_card_DefineArrayFromSection ${card} ${flag_post}
163          #
164          # Seasonal case : If option Seasonal is not found (old cards) put SEASONAL ON by default
165          #
166          # variable option allready typeset above
167          for option in $( eval echo \${${compname}_${flag_post}[*]} ) ; do
168            if [ ${option} = Seasonal ] ; then
169              FoundSeasonal=true
170              IGCM_card_DefineVariableFromOption ${card} ${flag_post} Seasonal
171            fi
172          done
173          #
174          if [ ! X${FoundSeasonal} = Xtrue ] ; then
175            eval ${compname}_${flag_post}_Seasonal=ON
176          fi
177          #
178          if [ $( eval echo \${${compname}_${flag_post}_Seasonal} ) = ON ] ; then
179            Seasonal=true
180          fi
181
182          # Dimension = vide si vieille card.
183          IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars
184          IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches
185          if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not" ] ; then
186            # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob.
187            ListDimension[0]=2D
188            ListDimension[1]=3D
189            TimeSeries=false
190            iLoop=${#ListDimension[*]}
191            j=0
192            until [ $j -ge ${iLoop} ]; do
193              Dimension=${ListDimension[${j}]}
194              IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension}
195              IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension}
196              #
197              # Time series WITHOUT chunk
198              #
199              if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
200                if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then
201                  IGCM_debug_Print 3 "${Dimension} time series activated for ${flag_post}"
202                  eval TimeSeries${Dimension}=true
203                fi
204              fi
205              #
206              # Time series WITH chunk
207              #
208              if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
209                chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} )
210                if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
211                  IGCM_debug_Print 3 "${Dimension} time series activated with chunck for ${flag_post}"
212                  eval TimeSeriesChunck${Dimension}=true
213                  eval CHUNCK${Dimension}_COMP[\${#CHUNCK${Dimension}_COMP[*]}]=${comp}
214                  eval CHUNCK${Dimension}_FLAG[\${#CHUNCK${Dimension}_FLAG[*]}]=${i}
215                  eval CHUNCK${Dimension}_NAME[\${#CHUNCK${Dimension}_NAME[*]}]=${flag_post}
216                  eval CHUNCK${Dimension}_SIZE[\${#CHUNCK${Dimension}_SIZE[*]}]=${chunck_size}
217                fi
218              fi
219              (( j=j+1 ))
220            done
221          else
222            ListDimension[0]=""
223            TimeSeries=true
224            TimeSeries2D=false
225            TimeSeries3D=false
226            TimeSeriesChunck2D=false
227            TimeSeriesChunck3D=false
228          fi
229        fi
230        (( i=i+3 ))
231      done
232    fi
233    # Debug Print
234    IGCM_debug_Print 3 "Initialize ${compname} with driver."
235    # INIT component
236    ${comp}_Initialize
237    echo
238  done
239
240  IGCM_debug_PopStack "IGCM_comp_Initialize"
241}
242
243#=======================================================================
244function IGCM_comp_PrepareDeletedFiles
245{
246  IGCM_debug_PushStack "IGCM_comp_PrepareDeletedFiles" $@
247
248  if [ X${2} != X. ] ; then
249    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${2} ) > /dev/null 2>&1
250  else
251    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${1} ) > /dev/null 2>&1
252  fi
253
254  IGCM_debug_PopStack "IGCM_comp_PrepareDeletedFiles"
255}
256
257#=======================================================================
258function IGCM_comp_GetInputInitialStateFiles
259{
260  IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles"
261
262  # Debug Print :
263  echo
264  IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles"
265  echo
266
267  # Only the first time step need InitialStateFiles
268  # otherwise it's BoundaryConditions
269  if ( ${FirstInitialize} ) ; then
270    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
271    typeset file_in_ file_in file_out_ file_out do_init
272    for comp in ${config_ListOfComponents[*]} ; do
273      # Initialize
274      do_init="y"
275      # Do we need to bring initial state file for this component
276      if [ "${config_Restarts_OverRule}" = "y" ] ; then
277        eval do_init="n"
278      else
279        # Read component Restarts parameters
280        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
281        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
282        if [ "${do_start}" = "y" ] ; then
283          do_init="n"
284        else
285          do_init="y"
286        fi
287      fi
288
289      if [ "${do_init}" = "y" ] ; then
290        # Define component
291        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
292        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
293
294        # Debug Print :
295        IGCM_debug_Print 3 "Initialisation files ${compname}"
296
297        card=${SUBMIT_DIR}/COMP/${compname}.card
298
299        IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List
300        ListFilesName=${compname}_InitialStateFiles_List
301
302        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
303        if [ X${FileName0} != X${NULL_STR} ] ; then
304          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
305          (( i=0 ))
306          until [ $i -ge $NbFiles ]; do
307            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
308            eval file_in=${file_in_}
309            (( i_ = i+1 ))
310            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
311            eval file_out=${file_out_}
312
313            IGCM_sys_IsFileArchived ${file_in}
314            if [ $? = 0 ] ; then
315              IGCM_sys_Get ${file_in} ${file_out}
316              #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
317            else
318              IGCM_sys_Cp ${file_in} ${file_out}
319            fi
320            (( i=i+2 ))
321          done
322        fi
323      fi
324    done
325  fi
326  IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles"
327}
328
329#=======================================================================
330# Definition of Smooth modulo function
331# usage :
332# IGCM_SmoothModulo StringModulo value
333#
334# StringModulo : A string of min max and modulo like definition of Scilab vectors.
335# [min]:[modulo:][max]
336# where :
337# [] value are optionnals;
338# empty min equal 1
339# empty max equal infinity
340# modulo not given or empty equal 1
341# empty string or just ':' equal always.
342#
343# value : the value to test with the definition
344#
345# return : true(1)/false(0)
346function IGCM_SmoothModulo
347{
348  IGCM_debug_PushStack "IGCM_SmoothModulo"
349  typeset defVector ModValue
350
351  eval set +A defVector -- $( echo "${1}" | \
352    gawk -F ':' '{print ($1 == "" ? 1 : $1) " " (NF==3 ? ($2 == "" ? 1 : $2) : 1) " " (NF==3 ? ($3 == "" ? -1 : $3) : ($2 == "" ? -1 : $2))}' )
353
354  # Save Smooth Min and Max. Needed to call IGCM_sys_Get when appropriate
355  arr[1]=${defVector[0]}
356  arr[2]=${defVector[2]}
357
358  # Test limits :
359  # ${defVector[0]} <= ${2} <= ${defVector[2]}
360  #          or ${defVector[2]} == -1
361  if ( [ ${2} -ge ${defVector[0]} ] && ( [ ${2} -le ${defVector[2]} ] || [ ${defVector[2]} -lt 0 ] ) ) ; then
362    # Test modulo
363    ModValue=$( expr \( ${2} - ${defVector[0]} \) % ${defVector[1]} )
364    if [ ${ModValue} -eq 0 ] ;  then
365      arr[3]=true
366      echo ${arr[@]}
367      IGCM_debug_PopStack "IGCM_SmoothModulo"
368      return 1
369    else
370      arr[3]=false
371      echo ${arr[@]}
372      IGCM_debug_PopStack "IGCM_SmoothModulo"
373      return 0
374    fi
375  else
376    arr[3]=false
377    echo ${arr[@]}
378    IGCM_debug_PopStack "IGCM_SmoothModulo"
379    return 0
380  fi
381}
382
383#=======================================================================
384function IGCM_comp_GetInputSmoothFiles
385{
386  IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles"
387
388  # Debug Print :
389  echo
390  IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles"
391  echo
392
393  typeset comp compname comptagname card ListFilesName FileName0 NbFiles j i i_ i__
394  typeset file_in_ file_in file_out_ file_out ret SmoothDef aux val
395
396  for comp in ${config_ListOfComponents[*]} ; do
397    # Define component
398    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
399    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
400
401    # Debug Print :
402    IGCM_debug_Print 3 "Smooth files ${compname}"
403
404    card=${SUBMIT_DIR}/COMP/${compname}.card
405
406    IGCM_card_DefineArrayFromOption ${card} SmoothFiles List
407    ListFilesName=${compname}_SmoothFiles_List
408    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
409
410    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != X"Section" ] ) ; then
411      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
412
413      (( i=0 ))
414      until [ $i -ge $NbFiles ]; do
415        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
416        eval file_in=${file_in_}
417        (( i_ = i+1 ))
418        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
419        eval file_out=${file_out_}
420
421        # define CumulPeriod definition for this file
422        (( i__ = i+2 ))
423        eval SmoothDef=\${${ListFilesName}[$i__]}
424        IGCM_debug_Print 3 "  ${file_in} ${SmoothDef}"
425        aux=$( IGCM_SmoothModulo ${SmoothDef} ${CumulPeriod} )
426        j=1
427        for val in ${aux} ; do
428          [ ${j} -eq 1 ] && SmoothMin=${val}
429          [ ${j} -eq 2 ] && SmoothMax=${val}
430          [ ${j} -eq 3 ] && ret=${val}
431          (( j=j+1 ))
432        done
433        [ ${SmoothMax} -eq -1 ] && SmoothMax=${CumulPeriod}
434        if ( [ X${ret} = Xtrue ] || ( [ ${Period} -eq 1 ] && [ ${CumulPeriod} -ge ${SmoothMin} ] && [ ${CumulPeriod} -le ${SmoothMax} ] ) ) ; then
435
436          IGCM_sys_IsFileArchived ${file_in}
437          if [ $? = 0 ] ; then
438            IGCM_sys_Get ${file_in} ${file_out}
439            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
440          else
441            IGCM_sys_Cp ${file_in} ${file_out}
442          fi
443        fi
444        (( i=i+3 ))
445      done
446    fi
447  done
448
449  IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
450}
451
452#=======================================================================
453function IGCM_comp_GetInputBoundaryFiles
454{
455  IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
456
457  # Debug Print :
458  echo
459  IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles"
460  echo
461
462  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
463  typeset file_in_ file_in file_out_ file_out
464
465  if [ ${Period} = 1 ]; then
466    ListFixBoundary=" "
467  fi
468
469  for comp in ${config_ListOfComponents[*]} ; do
470
471    # Define component
472    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
473    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
474
475    # Debug Print :
476    IGCM_debug_Print 3 "Boundary files ${compname}"
477
478    card=${SUBMIT_DIR}/COMP/${compname}.card
479
480    IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
481    ListFilesName=${compname}_BoundaryFiles_List
482    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
483
484    if [ X${FileName0} != X${NULL_STR} ] ; then
485      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
486
487      (( i=0 ))
488      until [ $i -ge $NbFiles ]; do
489        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
490        eval file_in=${file_in_}
491        (( i_ = i+1 ))
492        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
493        eval file_out=${file_out_}
494
495        IGCM_sys_IsFileArchived ${file_in}
496        if [ $? = 0 ] ; then
497          IGCM_sys_Get ${file_in} ${file_out}
498          IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
499        else
500          IGCM_sys_Cp ${file_in} ${file_out}
501        fi
502
503        (( i=i+2 ))
504      done
505    fi
506
507    # Get non deleted files
508    if [ ${Period} = 1 ]; then
509
510      IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
511      ListFilesName=${compname}_BoundaryFiles_ListNonDel
512      eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
513
514      if [ X${FileName0} != X${NULL_STR} ] ; then
515        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
516
517        (( i=0 ))
518        until [ $i -ge $NbFiles ]; do
519          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
520          eval file_in=${file_in_}
521          (( i_ = i+1 ))
522          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
523          eval file_out=${file_out_}
524
525          IGCM_sys_IsFileArchived ${file_in}
526          if [ $? = 0 ] ; then
527            IGCM_sys_Get ${file_in} ${file_out}
528            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
529          else
530            IGCM_sys_Cp ${file_in} ${file_out}
531          fi
532
533          if [ X${file_out} != X. ] ; then
534            ListFixBoundary=${ListFixBoundary}" "${file_out}
535          else
536            ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
537          fi
538
539          (( i=i+2 ))
540        done
541      fi
542    fi
543  done
544
545  IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
546}
547
548#=======================================================================
549function IGCM_comp_DelFixeBoundaryFiles
550{
551  IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
552
553  # Debug Print :
554  echo
555  IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles"
556  echo
557
558  ls -l ${ListFixBoundary}
559  rm -f ${ListFixBoundary}
560
561  IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
562}
563
564#=======================================================================
565function IGCM_comp_GetInputParametersFiles
566{
567  IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
568
569  # Debug Print :
570  echo
571  IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles"
572  echo
573
574  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
575  for comp in ${config_ListOfComponents[*]} ; do
576    # Define component
577    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
578    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
579
580    # Debug Print :
581    IGCM_debug_Print 3 "Parameters ${compname}"
582
583    card=${SUBMIT_DIR}/COMP/${compname}.card
584
585    IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
586    ListFilesName=${compname}_ParametersFiles_List
587    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
588
589    if [ X${FileName0} != X${NULL_STR} ] ; then
590      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
591
592      (( i=0 ))
593      until [ $i -ge $NbFiles ]; do
594        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
595        eval file_in=${file_in_}
596        (( i_ = i+1 ))
597        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
598        eval file_out=${file_out_}
599
600        IGCM_sys_Cp ${file_in} ${file_out}
601        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
602
603        (( i=i+2 ))
604      done
605    fi
606  done
607
608  IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
609}
610
611#=======================================================================
612function IGCM_comp_GetInputRestartFiles
613{
614  IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
615
616  # Debug Print :
617  echo
618  IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles"
619  echo
620
621  typeset Date_tmp Date_r Path_r do_start CompOldName Path_OUT Path_BUF
622  typeset Buffered Archived Tared PotentialTarFile IsMatching TarFileFound
623  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
624  typeset file_in file_out file_in_ file_out_ file_in_Name
625  typeset -Z4 j4
626  #BASH declare j4
627
628  IsMatching=""
629
630  for comp in ${config_ListOfComponents[*]} ; do
631    # Define component
632    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
633    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
634    #
635    card=${SUBMIT_DIR}/COMP/${compname}.card
636    #
637    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
638    ListFilesName=${compname}_RestartFiles_List
639    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
640
641    # Debug Print :
642    IGCM_debug_Print 3 "restart ${compname}"
643
644    if ( ${FirstInitialize} ) ; then
645
646      if [ "${config_Restarts_OverRule}" = "y" ] ; then
647        eval config_${comp}_Restart="y"
648        eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
649        eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
650        eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
651        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
652        eval CompOldName=${comp}
653      else
654        # Read component Restarts parameters
655        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
656        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
657
658        if [ "${do_start}" = "y" ] ; then
659          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
660          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
661          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
662        else
663          eval config_${comp}_RestartDate=-1
664          eval config_${comp}_RestartJobName=${NULL_STR}
665          eval config_${comp}_RestartPath=${NULL_STR}
666        fi
667
668        eval CompOldName=\${config_${comp}_OldName}
669        if [ X${CompOldName} = X ] ; then
670          eval CompOldName=${comp}
671        fi
672
673        # Reinitialize IsMatching to allow searching for a different tar file for each component.
674        IsMatching=""
675        TarFileFound=""
676      fi
677
678      if [ "${do_start}" = "y" ] ; then
679
680        # Restore Restarts files
681        #-----------------------
682        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
683          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
684
685          (( i=1 ))
686          until [ $i -gt $NbFiles ]; do
687            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
688            eval file_in=${file_in_}
689            (( i_ = i+1 ))
690            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
691            eval file_out=${file_out_}
692
693            eval Date_tmp=\${config_${comp}_RestartDate}
694            Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
695            # will be re-use
696            eval RestartPath=\${config_${comp}_RestartPath}
697            eval RestartJobName=\${config_${comp}_RestartJobName}
698            #
699            Path_r=${RestartPath}/${RestartJobName}/${CompOldName}/Restart
700            file_in_Name=${RestartJobName}_${Date_r}_${file_in}
701
702            extension_in=$( echo ${file_in_Name##*.} )
703            extension_out=$( echo ${file_out##*.} )
704
705            generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
706            generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
707
708            Path_OUT=${Path_r}/${generic_restart_file_name_in}
709
710            if [ $( IGCM_sys_TestFileBuffer ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
711              IGCM_debug_Print 3 "Buffered restart ${Path_OUT}*.${extension_in} "
712              Buffered=true
713              Archived=false
714              Tared=false
715              nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_OUT}_????.${extension_in})
716            elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
717              IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
718              Buffered=false
719              Archived=true
720              Tared=false
721              nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
722            else
723              IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
724              IGCM_debug_Print 3 "${Path_OUT}*.${extension_in} do not exist"
725              IGCM_debug_Print 3 "Restart files will now be searched for in : ${RestartPath}/${RestartJobName}/RESTART"
726              Buffered=false
727              Archived=false
728              Tared=true
729              # Look after the tar file we want if we did not found it already
730              if [ X${IsMatching} = X ] ; then
731                IGCM_sys_TestDirArchive ${RestartPath}/${RestartJobName}/RESTART
732                if [ $? ] ; then
733                  for PotentialTarFile in $( IGCM_sys_RshArchive "find ${RestartPath}/${RestartJobName}/RESTART -name "${RestartJobName}_*restart*.tar" -print" ) ; do
734                    IsMatching=$( echo ${PotentialTarFile##*/} | \
735                      sed "s:_restart::" | \
736                      sed "s:^${RestartJobName}_::" | \
737                      sed "s:\.tar$::" | \
738                      gawk -F_ -v restartdate=${Date_r} \
739                      '{if (($1 <= restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
740                    if [ ! X${IsMatching} = X ] ; then
741                      TarFileFound=${PotentialTarFile}
742                      break
743                    fi
744                  done
745                fi
746                # Stop here if nothing has been found
747                if [ X${TarFileFound} = X ] ; then
748                  IGCM_debug_Print 3 "Restart files were not found!"
749                  IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
750                  IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
751                  IGCM_debug_Exit "Please double check restart settings in config.card"
752                  IGCM_debug_Verif_Exit
753                fi
754              fi
755              IGCM_sys_PrepareTaredRestart ${TarFileFound}
756              TarFileLocation=$( basename ${TarFileFound} )
757              IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
758              tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
759              nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
760            fi
761
762            if [ ${nb_restart_file} -gt 1 ] ; then
763              j=0                                      # BASH LINE NOT NEEDED
764              # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
765              until [ $j -ge ${nb_restart_file} ]; do  # BASH LINE NOT NEEDED
766                j4=${j}                                # BASH LINE NOT NEEDED
767                if [ X${Buffered} = Xtrue ] ; then
768                  IGCM_sys_GetBuffer ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
769                elif [ X${Archived} = Xtrue ] ; then
770                  IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
771                elif [ X${Tared} = Xtrue ] ; then
772                  IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
773                fi
774                (( j=j+1 ))                            #BASH LINE NOT NEEDED
775              done
776
777              if [ X${NUM_PROC_OCE} != X ] ; then
778                if [ ${NUM_PROC_OCE} -ne ${nb_restart_file} ] ; then
779                  IGCM_sys_rebuild ${generic_restart_file_name_out}.${extension_out} ${generic_restart_file_name_out}_????.${extension_out}
780                  IGCM_sys_Rm ${generic_restart_file_name_out}_????.${extension_out}
781                fi
782              fi
783            else
784              if [ X${Buffered} = Xtrue ] ; then
785                IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
786              elif [ X${Archived} = Xtrue ] ; then
787                IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
788              elif [ X${Tared} = Xtrue ] ; then
789                IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
790              fi
791            fi
792            (( i=i+3 ))
793          done
794        else
795          if [ X${FileName0} != XNONE ] ; then
796            IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
797          else
798            IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
799          fi
800        fi
801      fi
802    elif ( [ ${Period} -eq 1 ] && [ ${DRYRUN} -eq 0 ] ) ; then
803      # if not FirstInitialize and first loop of this job
804
805      # Restore Restarts files
806      #-----------------------
807      if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
808        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
809
810        (( i=1 ))
811        until [ $i -gt $NbFiles ]; do
812          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
813          eval file_in=${file_in_}
814          (( i_ = i+1 ))
815          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
816          eval file_out=${file_out_}
817
818          file_in_Name=${config_UserChoices_JobName}_${LastPeriodDateEnd}_${file_in}
819
820          extension_in=$( echo ${file_in_Name##*.} )
821          extension_out=$( echo ${file_out##*.} )
822
823          generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
824          generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
825
826          eval Path_BUF=\${R_BUF_${comp}_R}/${generic_restart_file_name_in}
827          eval Path_OUT=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
828
829          if [ $( IGCM_sys_TestFileBuffer ${Path_BUF}*.${extension_in} ; echo $? ) = 0 ] ; then
830            IGCM_debug_Print 3 "Buffered restart ${Path_BUF}*.${extension_in}"
831            Buffered=true
832            Archived=false
833            Tared=false
834            nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_BUF}_????.${extension_in})
835          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
836            IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
837            Buffered=false
838            Archived=true
839            Tared=false
840            nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
841          else
842            IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
843            IGCM_debug_Print 3 "Restart files will now be searched for in : ${R_SAVE}/RESTART"
844            Buffered=false
845            Archived=false
846            Tared=true
847            # Look after the tar file we want if we did not found it already
848            if [ X${IsMatching} = X ] ; then
849              for PotentialTarFile in $( IGCM_sys_RshArchive "find ${R_SAVE}/RESTART -name "${config_UserChoices_JobName}_*_restart.tar" -print" ) ; do
850                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}}' )
851                if [ ! X${IsMatching} = X ] ; then
852                  TarFileFound=${PotentialTarFile}
853                  break
854                fi
855              done
856            fi
857            # Stop here if nothing has been found
858            if [ X${TarFileFound} = X ] ; then
859              IGCM_debug_Print 3 "Restart files were not found!"
860              IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
861              IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
862              IGCM_debug_Exit "Please double check restart settings in config.card"
863              IGCM_debug_Verif_Exit
864            fi
865            IGCM_sys_PrepareTaredRestart ${TarFileFound}
866            TarFileLocation=$( basename ${TarFileFound} )
867            IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
868            tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
869            nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
870          fi
871
872          if [ ${nb_restart_file} -gt 1 ] ; then
873            j=0                                     # BASH LINE NOT NEEDED
874            #BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
875            until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
876              j4=${j}                               # BASH LINE NOT NEEDED
877              if [ X${Buffered} = Xtrue ] ; then
878                IGCM_sys_GetBuffer ${Path_BUF}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
879              elif [ X${Archived} = Xtrue ] ; then
880                IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
881              elif [ X${Tared} = Xtrue ] ; then
882                IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
883              fi
884              (( j=j+1 ))                           # BASH LINE NOT NEEDED
885            done
886          else
887            if [ X${Buffered} = Xtrue ] ; then
888              eval IGCM_sys_GetBuffer \${R_BUF_${comp}_R}/${file_in_Name} ${file_out}
889            elif [ X${Archived} = Xtrue ] ; then
890              eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
891            elif [ X${Tared} = Xtrue ] ; then
892              IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
893            fi
894          fi
895          (( i=i+3 ))
896        done
897      else
898        if [ X${FileName0} != XNONE ] ; then
899          IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
900        else
901          IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
902        fi
903      fi
904    fi
905  done
906
907  NbFiles=$( ls * 2> /dev/null | wc -l )
908  if [ ${NbFiles} -gt 0 ] ; then
909    IGCM_sys_Chmod u+rw *
910  fi
911
912  IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
913}
914
915#=======================================================================
916function IGCM_comp_PeriodStart
917{
918  IGCM_debug_PushStack "IGCM_comp_PeriodStart"
919
920  # Debug Print :
921  echo
922  IGCM_debug_Print 1 "IGCM_comp_PeriodStart"
923  echo
924
925  typeset ExeNameIn ExeNameOut
926  typeset comp compname comptagname
927  for comp in ${config_ListOfComponents[*]} ; do
928    # Define component
929    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
930    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
931
932    # Copy executable for this component
933    eval ExeNameIn=\${config_Executable_${comp}[0]}
934    eval ExeNameOut=\${config_Executable_${comp}[1]}
935
936    # Debug Print
937    IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
938    # UPDATE component
939    ${comp}_PeriodStart 2> /dev/null
940
941  done
942
943  IGCM_debug_PopStack "IGCM_comp_PeriodStart"
944}
945
946#=======================================================================
947function IGCM_comp_modifyDefFile
948{
949#
950# syntax:     IGCM_comp_modifyDefFile  type  filein  key  [value]
951#
952# For example : IGCM_comp_modifyDefFile blocker run.def day_step 1200
953#
954# This function is used to modify a parameter file for a specific variable.
955# The file must be a ".def" file, i.e. with IOIPSL parameter file syntax.
956# This function can be used in the comp.driver files for the components.
957#
958# Arguments:
959# - type   : first argument must be blocker or nonblocker.
960#            For "blocker" case, the variable must be attributed the keyworld AUTO
961#            otherwise this function will exit.
962#            For "nonblocker" case, the user can remove or modify the variable. For
963#            this case, as long as AUTO is not set, no modification will be done.
964# - filein : the file in run directory of .def type in which the variable should be set
965# - key    : the variable to modify
966# - value  : the value to set the key equal to, optional. If value is not set or if
967#            value=DEFAULT, then a default value must be given in filein using syntax :
968#            key= AUTO : DEFAULT=def_value
969#
970    IGCM_debug_PushStack "IGCM_comp_modifyDefFile"
971   
972    # Set local variables and test the arguments
973    if [ $# = 4 ] ; then
974        # Normal case with 4 arguments
975        type=$1 ; filein=$2 ; key=$3 ; value=$4
976    elif [ $# = 3 ] ; then
977        # Normal case with 3 arguments
978        type=$1 ; filein=$2 ;   key=$3; value="DEFAULT"
979    else
980        IGCM_debug_Exit "IGCM_comp_modifyDefFile: Bad number of arguments."
981        return
982    fi
983    IGCM_debug_Print 1 "Entering IGCM_comp_modifyDefFile with arguments: $type $filein $key $value"
984
985    # Test if first argument is correct
986    if [ $type != blocker ] && [ $type != nonblocker ] ; then
987        IGCM_debug_Exit "IGCM_comp_modifyDefFile: Error in first argument must be blocker or nonblocker"
988        return
989    fi
990
991    # Test if the file exist
992    if [ ! -f ${filein} ] ; then
993        IGCM_debug_Exit "IGCM_comp_modifyDefFile: $filein does not exist."
994        return
995    fi
996
997    # Define list of files to test using all files with suffix .def
998    filelist=$( ls *def )
999
1000    # Count number of occurances for the key in all files
1001    nb_occ=$( grep -w $key $filelist |grep -v "#"  |wc -l )
1002
1003    # Test if key is set several times
1004    if [ $nb_occ -gt 1 ] ; then
1005        IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in $filein: Variable=$key is set ${nb_occ} times"
1006        return
1007    fi
1008
1009    # Treatement according to different cases
1010    if [ $nb_occ -eq 0 ] && [ $type = blocker ] ; then
1011        # Stop if the key is never set and the function is blocker
1012        IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in $filein: Variable=$key has been removed but this function is blocker. "
1013        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: restore $filein for variable $key."
1014    elif [ $nb_occ -eq 0 ] && [ $type = nonblocker ] ; then
1015        # The key is not set but it is a nonblocker call so nothing is done.
1016        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key is not set in $filein. This is a nonblocker call so nothing is done."
1017        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: Default value for $key from the model will be used."
1018    elif [ $( grep $key $filein | grep -v "\#"  |wc -l ) = 0 ] ; then
1019        # Variable key is not set in filein, stop.
1020        IGCM_debug_Exit "IGCM_comp_modifyDefFile : Variable $key is not set in correct file. It should be set in $filein."
1021    else
1022        # Read the value of key from filein
1023        if [ X"$( grep $key $filein | grep -v "\#" | grep AUTO )" = "X" ] ; then
1024            # The key variable is not set to AUTO
1025            if [ $type = blocker ] ; then
1026                # Stop because this is a blocker call
1027                IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable $key cannot be modified. It should be set to AUTO."
1028            else
1029                # Do nothing. Suppose that the user did set the variable correct
1030                IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key is set by the user. Nothing done."
1031            fi
1032        else
1033            # The variable key is set to AUTO.
1034
1035            # For option DEFAULT, read default value from file.
1036            if [ X"$value" = XDEFAULT ] || [ X"$value" = X ] ; then
1037                # Case to set DEFAULT value
1038                # Read default value from filein
1039                value=$( grep $key $filein | grep -v "\#" | awk  -F"DEFAULT *=" '{print $2}')
1040
1041                if [ X"$value" = X ] ; then
1042                    IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable $key needs a DEFAULT value in $filein."
1043                    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: The syntax in $filein should be:"
1044                    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key=_AUTO_:DEFAULT=def_value"
1045                    return
1046                fi
1047            fi
1048
1049            # Now change key in filein
1050            sed -e "s/^${key}\ *=.*/${key}= ${value}/" $filein > $filein.tmp
1051            IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: In $filein set $key=$value"
1052            \mv $filein.tmp $filein
1053        fi
1054    fi 
1055}
1056
1057#=======================================================================
1058function IGCM_comp_modifyXmlFile
1059{
1060#
1061# syntax:     IGCM_comp_modifyXmlFile  type  filein  keyid  keyattrib  value
1062#
1063# For example : IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba2 enabled .TRUE.
1064#          or   IGCM_comp_modifyXmlFile blocker iodef.xml using_server NONE false
1065#
1066# This function is used to modify the value for a specific attribute and variable id.
1067# The file must be a of xml syntax.
1068# This function can be used in the comp.driver files for the components.
1069#
1070# Arguments:
1071# - type      : first argument must be blocker, nonblocker or force.
1072#               For "blocker" case, the variable must be attributed the keyworld AUTO
1073#               otherwise this function will exit.
1074#               For "nonblocker" case, the user can remove or modify the variable. For
1075#               this case, as long as AUTO is not set, no modification will be done.
1076#               For "force" case, the variable will be modified even if it is not set to AUTO
1077# - filein    : the file in run directory of .xml type in which the variable should be set
1078# - keyid     : the variable to modify
1079# - keyattrib : the attribute name to modify. If NONE, then the variable itself will be modified
1080# - value     : the value to set in the filein
1081#
1082    IGCM_debug_PushStack "IGCM_comp_modifyXmlFile"
1083   
1084    # Set local variables and test the arguments
1085    if [ $# = 5 ] ; then
1086        # Normal case with 4 arguments
1087        type=$1 ; filein=$2 ; keyid=$3 ; keyattrib=$4 ; value=$5
1088    else
1089        IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Bad number of arguments."
1090        return
1091    fi
1092    IGCM_debug_Print 2 "Entering IGCM_comp_modifyXmlFile with arguments: type=$type file=$filein, id=$keyid attribute=$keyattrib, value=$value"
1093
1094    # Test if first argument is correct
1095    if [ $type != blocker ] && [ $type != nonblocker ] && [ $type != force ] ; then
1096        IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Error in first argument must be blocker, nonblocker or force"
1097        return
1098    fi
1099
1100    # Test if the file exist
1101    if [ ! -f ${filein} ] ; then
1102        IGCM_debug_Exit "IGCM_comp_modifyXmlFile: $filein does not exist."
1103        return
1104    fi
1105
1106    # Test if keyid is set in filein, otherwise exit
1107    if [ $( grep -w $keyid $filein | wc -l ) = 0 ] ; then
1108        # Variable key is not set in filein, stop.
1109        IGCM_debug_Exit "IGCM_comp_modifyXmlFile : $keyid is not set in the file. Bad syntax of $filein file."
1110        return
1111    fi
1112
1113    # Check if AUTO is set on the same line as keyid and keyattrib
1114    if [  $( grep -w $keyid $filein | grep AUTO | wc -l ) = 1 ] ; then
1115        # Modifification will be done
1116        modify=yes
1117    else
1118        if [ $type = blocker ] ; then
1119            # Exit, the variable must be set to AUTO
1120            IGCM_debug_Exit "IGCM_comp_modifyXmlFile : blocker function. The $keyattrib for $keyid must be set to AUTO in $filein."
1121            return
1122        elif [ $type = nonblocker ] ; then
1123            # Nothing will be done
1124            IGCM_debug_Print 1 "Nonblocker nothing is done for ${filein}, id=${keyid} and attribute ${keyattrib}"
1125            modify=no
1126        elif [ $type = force ] ; then
1127            # Force modification
1128            IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile : Attribute=$keyattrib for id=$keyid was not set to AUTO. Modification will be forced."
1129            modify=yes
1130        fi
1131    fi
1132
1133    # Do the modifcation now
1134    if [ $modify = yes ] ; then
1135        if [ $keyattrib = NONE ] ; then
1136            # Case to modify the variable itself
1137            IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting the variable=${value}"
1138            sed -e "s/\(<[^\"]*\"${keyid}\".*>\)\([^<]*\)\(<[^>]*\)/\1${value}\3/" $filein > $filein.tmp
1139        else
1140            # Case to modify the attribute value
1141            IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting attribute to ${keyattrib}=${value}"
1142            sed -e "/id=\"${keyid}\"/s/\(${keyattrib}=\"\)[^\"]*\(\"\)/\1${value}\2/" $filein > $filein.tmp
1143        fi
1144        \mv $filein.tmp $filein 
1145    fi
1146    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1147}
1148
1149#=======================================================================
1150function IGCM_comp_Update
1151{
1152  IGCM_debug_PushStack "IGCM_comp_Update"
1153
1154    # Debug Print :
1155  echo
1156  IGCM_debug_Print 1 "IGCM_comp_Update"
1157  echo
1158
1159  typeset ExeNameIn ExeNameOut
1160  typeset comp compname comptagname
1161  for comp in ${config_ListOfComponents[*]} ; do
1162    # Define component
1163    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1164    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1165
1166    # Copy executable for this component
1167    eval ExeNameIn=\${config_Executable_${comp}[0]}
1168    eval ExeNameOut=\${config_Executable_${comp}[1]}
1169
1170    # If missing executable and DRYRUN is set to 0 or 1  then stop!
1171    if [ ${DRYRUN} -le 1 ] && [ X${ExeNameIn} != X\"\" ] &&  [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
1172      IGCM_debug_Exit "IGCM_comp_Update missing executable ${ExeNameIn}"
1173    fi
1174
1175    if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
1176      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1177      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1178        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1179      fi
1180    elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
1181      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1182      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1183        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1184      fi
1185    fi
1186
1187    # Debug Print
1188    IGCM_debug_Print 1 "Update ${compname} Parameter Files."
1189    # UPDATE component
1190    ${comp}_Update
1191
1192  done
1193
1194  IGCM_debug_PopStack "IGCM_comp_Update"
1195}
1196
1197#=======================================================================
1198function IGCM_comp_Finalize
1199{
1200  IGCM_debug_PushStack "IGCM_comp_Finalize"
1201
1202  # Debug Print :
1203  echo
1204  IGCM_debug_Print 1 "IGCM_comp_Finalize"
1205  echo
1206
1207  typeset ListTextName TextName0
1208  typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
1209  typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
1210  typeset -Z4 j4
1211  #BASH declare j4
1212  typeset list_file nlist_file
1213  typeset compactoutputs
1214
1215  compactoutputs=false
1216  if [ X${JobType} != XRUN ] ; then
1217    compactoutputs=true
1218  elif [ X${config_UserChoices_CompactText} != Xn ] ; then
1219    compactoutputs=true
1220  fi
1221
1222  # Prepare headers for the shell dedicated to offline rebuild
1223  if [ X${AsynchronousRebuild} = Xtrue ] ; then
1224    [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1225    if [ ${DRYRUN} -le 1 ] ; then
1226      echo "#!/bin/ksh                                        " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1227      echo "function IGCM_FlushRebuild                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1228      echo "{                                                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1229      echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1230      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1231      echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1232      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1233      echo "export R_SAVE=${R_SAVE}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1234      echo "export R_BUFR=${R_BUFR}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1235      echo "export R_OUT_KSH=${R_OUT_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1236      echo "export R_BUF_KSH=${R_BUF_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1237      echo "export config_UserChoices_JobName=${config_UserChoices_JobName}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1238      echo "export config_UserChoices_SpaceName=${config_UserChoices_SpaceName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1239    fi
1240  fi
1241
1242  for comp in ${config_ListOfComponents[*]} ; do
1243    # Define component
1244    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1245    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1246
1247    # Debug Print
1248    IGCM_debug_Print 1 "Finalize ${comp} : ${compname} component."
1249    # FINALIZE component
1250    ${comp}_Finalize
1251
1252    card=${SUBMIT_DIR}/COMP/${compname}.card
1253
1254    # Save Output Text files of models
1255    #---------------------------------
1256    IGCM_debug_Print 2 "Save Output Text files for ${comp} : ${compname} component."
1257    IGCM_card_DefineArrayFromOption ${card} OutputText List
1258    ListTextName=${compname}_OutputText_List
1259
1260    eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1261    if [ X${TextName0} != X${NULL_STR} ] ; then
1262      eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1263
1264      (( i=0 ))
1265      until [ $i -eq $NbFiles ]; do
1266        eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1267        eval file_out=${PREFIX}_${file_in}
1268
1269        (( i=i+1 ))
1270
1271        unset list_file
1272        #set +A list_file -- $( ls ${file_in}* | sort 2>/dev/null )
1273        # result for a a1 a10 a2 with file_in=a a a1 a2 a10
1274        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 )
1275        nlist_file=${#list_file[@]}
1276        if [ ${nlist_file} -gt 1 ] ; then
1277          if ( ${compactoutputs} ) ; then
1278            IGCM_debug_Print 2 "Parallelism of Text Output with ${nlist_file} files."
1279            IGCM_debug_Print 2 "Compact files in ${file_out} : " ${list_file[*]}
1280            echo ${list_file[*]} > ${file_out}
1281            echo "" >> ${file_out}
1282
1283            (( i_ = 0 ))
1284            for file in ${list_file[@]}
1285            do
1286              echo "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " >> ${file_out}
1287              echo "| " ${i_} " " ${file} >> ${file_out}
1288              echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " >> ${file_out}
1289              cat ${file} | sed "s/\(.*\)/${i_}\1/" >> ${file_out}
1290              echo "" >> ${file_out}
1291              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1292                  (( i_ = i_ + 1 ))
1293            done
1294            if [ X${Pack} = Xtrue ] ; then
1295              eval IGCM_sys_PutBuffer_Out ${file_out} \${R_BUF_${comp}_D}/${file_out}
1296            else
1297              eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}_D}/${file_out}
1298            fi
1299            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_out}" > /dev/null 2>&1
1300
1301            if ( ${ExecutionFail} ) ; then
1302              IGCM_sys_Cp ${file_out} ${SUBMIT_DIR}/Debug
1303            fi
1304          else
1305            for file in ${list_file[@]}
1306            do
1307              if [ X${Pack} = Xtrue ] ; then
1308                eval IGCM_sys_PutBuffer_Out ${file} \${R_BUF_${comp}_D}/${PREFIX}_${file}
1309              else
1310                eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
1311              fi
1312              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1313
1314              if ( ${ExecutionFail} ) ; then
1315                IGCM_sys_Cp ${file} ${SUBMIT_DIR}/Debug/${PREFIX}_${file}
1316              fi
1317            done
1318          fi
1319        else
1320          if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1321            eval IGCM_sys_Mv ${file_in}* ${file_in}
1322          fi
1323          if [ X${Pack} = Xtrue ] ; then
1324            eval IGCM_sys_PutBuffer_Out ${file_in} \${R_BUF_${comp}_D}/${file_out}
1325          else
1326            eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${file_out}
1327          fi
1328          eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1329
1330          if ( ${ExecutionFail} ) ; then
1331            IGCM_sys_Cp ${file_in} ${SUBMIT_DIR}/Debug/${file_out}
1332          fi
1333        fi
1334      done
1335    fi
1336
1337    # Save Restarts files
1338    #--------------------
1339    IGCM_debug_Print 2 "Save Restart files for ${comp} : ${compname} component."
1340    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
1341    ListFilesName=${compname}_RestartFiles_List
1342    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1343
1344    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
1345      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1346
1347      (( i=0 ))
1348      until [ $i -ge $NbFiles ]; do
1349        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1350        eval file_in=${file_in_}
1351
1352        (( i_ = i+1 ))
1353        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1354        eval file_out=${file_out_}
1355
1356        (( i_ = i+2 ))
1357        eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1358        eval file_outin=${file_outin_}
1359
1360        generic_restart_file_name_in=$(    basename ${file_in} .nc )
1361        generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
1362        generic_restart_file_name_outin=$( basename ${file_outin} .nc )
1363
1364        nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l )
1365        if [ ${nb_restart_file} -gt 1 ] ; then
1366          j=0                                     # BASH LINE NOT NEEDED
1367          # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
1368          until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
1369            j4=${j}                               # BASH LINE NOT NEEDED
1370            if [ X${Pack} = Xtrue ] ; then
1371              eval IGCM_sys_PutBuffer_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_BUF_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1372            else
1373              eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1374            fi
1375            if [ ! ${file_in} = ${file_outin} ] ; then
1376              if ( ${ExitFlag} ) ; then
1377                echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
1378              else
1379                IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
1380              fi
1381            fi
1382            (( j=j+1 ))                           # BASH LINE NOT NEEDED
1383          done
1384        else
1385          if [ X${Pack} = Xtrue ] ; then
1386            eval IGCM_sys_PutBuffer_Rest ${file_in} \${R_BUF_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1387          else
1388            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1389          fi
1390          if [ ! ${file_in} = ${file_outin} ] ; then
1391            if ( ${ExitFlag} ) ; then
1392              echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1393            else
1394              IGCM_sys_Mv ${file_in} ${file_outin}
1395            fi
1396          fi
1397        fi
1398
1399        (( i=i+3 ))
1400      done
1401    else
1402      if [ X${FileName0} != XNONE ] ; then
1403        IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
1404      else
1405        IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
1406      fi
1407    fi
1408
1409    # Save Output files
1410    #------------------
1411    IGCM_debug_Print 2 "Save Output files for ${comp} : ${compname} component."
1412    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
1413    ListFilesName=${compname}_OutputFiles_List
1414    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1415
1416    if [ X${FileName0} != X${NULL_STR} ] ; then
1417      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1418
1419      (( i=0 ))
1420      until [ $i -ge $NbFiles ]; do
1421        SaveOnArchive=true
1422        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1423        eval file_in=${file_in_}
1424        (( i_ = i+1 ))
1425        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1426        eval file_out=${file_out_}
1427        #
1428        # Override file_out path remplacing R_SAVE by R_BUFR
1429        #
1430        if [ X${Pack} = Xtrue ] ; then
1431          file_out=$( echo $file_out | sed "s:^$R_SAVE:$R_BUFR:" )
1432        fi
1433        #
1434        # Not necessarily the best option. /!\ Potential side effects /!\
1435        #
1436        (( i_ = i+2 ))
1437        eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1438        #
1439        generic_file_name=$( basename ${file_in} .nc )
1440        nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
1441        #
1442        if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
1443          IGCM_debug_Print 2 "Parallelism with 1 file. Rebuilding ${file_in} not needed"
1444          IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
1445        elif [ ${nb_rebuild_file} -gt 1 ] ; then
1446          IGCM_debug_Print 2 "Parallelism detected and rebuilding ${file_in} is needed"
1447          if [ X${AsynchronousRebuild} = Xfalse ] ; then
1448            IGCM_debug_Print 2 "Rebuilding ${file_in} online"
1449            IGCM_sys_rebuild ${file_in} ${generic_file_name}_[0-9]*.nc
1450          else
1451            IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
1452            IGCM_sys_Mv ${generic_file_name}_[0-9]*.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1453
1454            # Prepare the shell dedicated to offline rebuild
1455            if [ $DRYRUN -le 1 ]; then
1456              if [ ${file_in} = histstn.nc ] ; then
1457                echo "IGCM_sys_rebuild_station ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1458              else
1459                echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_[0-9]*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1460              fi
1461              echo "IGCM_debug_Verif_Exit_Post" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1462            fi
1463            #
1464            # Load Patch we need to apply and apply
1465            if [ $DRYRUN -le 1 ]; then
1466              if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
1467                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
1468                  echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1469                  echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1470                  echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1471                done
1472              fi
1473            fi
1474            #
1475            if [ $DRYRUN -le 1 ]; then
1476              if [ X${Pack} = Xtrue ] ; then
1477                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1478              else
1479                echo "IGCM_sys_Put_Out ${file_in} ${file_out}           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1480              fi
1481              echo "IGCM_debug_Verif_Exit_Post                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1482              echo "IGCM_sys_Rm ${generic_file_name}_[0-9]*.nc          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1483            fi
1484            SaveOnArchive=false
1485          fi
1486        fi
1487        #
1488        if [ ${SaveOnArchive} = true ] ; then
1489          #
1490          # Rebuild has been done online or it was not needed
1491          #
1492          # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
1493          #
1494          thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
1495          if ( [ ! X${thereisapatch} = X${NULL_STR} ] && [ X${AsynchronousRebuild} = Xtrue ] && [ -f ${file_in} ] ) ; then
1496            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1497            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
1498            #
1499            if [ $DRYRUN -le 1 ]; then
1500              for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
1501                echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1502                echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1503                echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1504              done
1505              #
1506              if [ X${Pack} = Xtrue ] ; then
1507                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1508              else
1509                echo "IGCM_sys_Put_Out ${file_in} ${file_out}         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1510              fi
1511              echo "IGCM_debug_Verif_Exit_Post                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1512              #
1513            fi
1514          else
1515            #
1516            # No Patch, No Asynchronous rebuild, online rebuild has been done or was not needed
1517            #
1518            if [ X${Pack} = Xtrue ] ; then
1519              IGCM_sys_PutBuffer_Out ${file_in} ${file_out}
1520            else
1521              IGCM_sys_Put_Out ${file_in} ${file_out}
1522            fi
1523            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1524            if [ ${nb_rebuild_file} -gt 1 ] ; then
1525              for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
1526                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
1527              done
1528            fi
1529          fi
1530        fi
1531        (( i=i+3 ))
1532      done
1533    fi
1534    echo
1535  done
1536  IGCM_debug_PopStack "IGCM_comp_Finalize"
1537}
Note: See TracBrowser for help on using the repository browser.