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

Last change on this file since 1645 was 1645, checked in by aclsce, 4 months ago

Added modifications to run with no access to IDRIS STORE from computing nodes.
Use of TMPSTORE to handle the writing/reading of restart files of running simulations.
Use of OLDSTORE to handle reading of restart files of old simulations.
The new STORE is only used from post-treatment jobs.
Temporary solution waiting for the split of computing Job into pre-treatment job + computing Job.

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