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

Last change on this file since 1538 was 1538, checked in by aclsce, 4 years ago

Modified to not use restart files for XIOS in case of dr2xmlIPSL=true

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