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

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