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

Last change on this file since 1446 was 1446, checked in by sdipsl, 6 years ago
  • Adhoc exception for CMIP6 : exclude XIOS from the restart overrule mechanism.
  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

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

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

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

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

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

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

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