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

Last change on this file since 1166 was 1166, checked in by sdipsl, 9 years ago

the metrics template need more information
create IGCM_comp_modifyFile function to simply replace pattern in files
code cleanup

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