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

Last change on this file since 1580 was 1580, checked in by acosce, 15 months ago

remove test on IPSLCM config for CMIP6 workflow - not useful for redhat8

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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