source: tags/libIGCM_v3.0_beta1/libIGCM_comp/libIGCM_comp.ksh @ 1399

Last change on this file since 1399 was 1399, checked in by sdipsl, 7 years ago

CMIP6 workflow. Merging trunk into branch 'branch' r:1375:1398

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