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

Last change on this file since 884 was 884, checked in by mafoipsl, 11 years ago

add treatment to recognize RESTART file with this pattern : *_20781231_20781231_*.tar. Correction of #152.

  • 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: 53.5 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#========================================================================
15function IGCM_comp_Initialize
16{
17  IGCM_debug_PushStack "IGCM_comp_Initialize"
18
19  # Debug Print :
20  echo
21  IGCM_debug_Print 1 "IGCM_comp_Initialize"
22  echo
23
24  typeset comp compname comptagname CompatibilityTag 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    # Read libIGCM compatibility version in ${compname}.card
36    card=${SUBMIT_DIR}/COMP/${compname}.card
37    IGCM_card_DefineVariableFromOption ${card} Compatibility libIGCM
38
39    eval CompatibilityTag=\${${compname}_Compatibility_libIGCM} > /dev/null 2>&1
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
43
44    # Manage component executable
45    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card Executable ${comp}
46
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
52        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} ${option}
53    done
54    IGCM_debug_Print 3 " Found in section config_${comp} :  ${config_comp[*]} "
55
56    # Debug Print :
57    eval auxprint=\${config_${comp}_WriteFrequency}
58    IGCM_debug_Print 1 "Write frequency for ${compname} : ${auxprint} "
59    #2> /dev/null
60
61    # Debug Print :
62    IGCM_debug_Print 2 "Initialize following component library"
63
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}"
76
77    # Debug Print
78    IGCM_debug_Print 3 "Initialize ${comp} output directory."
79
80    # Define ARCHIVED Dirs
81    eval R_OUT_${comp}=${R_SAVE}/${comp}
82    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}}
83
84    eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output
85    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O}
86
87    eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart
88    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R}
89
90    eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug
91    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D}
92
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
100    if [ ! ${config_Post_PackFrequency} = NONE ] ; then
101      eval R_BUF_${comp}=${R_BUFR}/${comp}
102      eval IGCM_sys_Mkdir \${R_BUF_${comp}}
103
104      eval R_BUF_${comp}_O=\${R_BUF_${comp}}/Output
105      eval IGCM_sys_Mkdir \${R_BUF_${comp}_O}
106
107      eval R_BUF_${comp}_R=\${R_BUF_${comp}}/Restart
108      eval IGCM_sys_Mkdir \${R_BUF_${comp}_R}
109
110      eval R_BUF_${comp}_D=\${R_BUF_${comp}}/Debug
111      eval IGCM_sys_Mkdir \${R_BUF_${comp}_D}
112
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
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
124
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
128        unset card_UserChoices
129      fi
130      eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1
131      IGCM_debug_Print 3 "${compname}_UserChoices_values:"
132      for option in ${card_UserChoices[*]} ; do
133        IGCM_card_DefineVariableFromOption ${card} UserChoices ${option}
134        eval IGCM_debug_Print 3 "${option}=\${${compname}_UserChoices_${option}}"
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
155        #
156        eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
157        #
158        if [ X${flag_post} != XNONE ] ; then
159          #
160          # First of all
161          #
162          IGCM_card_DefineArrayFromSection ${card} ${flag_post}
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_GetInputInitialStateFiles
259{
260  IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles"
261
262  # Debug Print :
263  echo
264  IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles"
265  echo
266
267  # Only the first time step need InitialStateFiles
268  # otherwise it's BoundaryConditions
269  if ( ${FirstInitialize} ) ; then
270    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
271    typeset file_in_ file_in file_out_ file_out do_init
272    for comp in ${config_ListOfComponents[*]} ; do
273      # Initialize
274      do_init="y"
275      # Do we need to bring initial state file for this component
276      if [ "${config_Restarts_OverRule}" = "y" ] ; then
277        eval do_init="n"
278      else
279        # Read component Restarts parameters
280        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
281        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
282        if [ "${do_start}" = "y" ] ; then
283          do_init="n"
284        else
285          do_init="y"
286        fi
287      fi
288
289      if [ "${do_init}" = "y" ] ; then
290        # Define component
291        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
292        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
293
294        # Debug Print :
295        IGCM_debug_Print 3 "Initialisation files ${compname}"
296
297        card=${SUBMIT_DIR}/COMP/${compname}.card
298
299        IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List
300        ListFilesName=${compname}_InitialStateFiles_List
301
302        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
303        if [ X${FileName0} != X${NULL_STR} ] ; then
304          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
305          (( i=0 ))
306          until [ $i -ge $NbFiles ]; do
307            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
308            eval file_in=${file_in_}
309            (( i_ = i+1 ))
310            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
311            eval file_out=${file_out_}
312
313            IGCM_sys_IsFileArchived ${file_in}
314            if [ $? = 0 ] ; then
315              IGCM_sys_Get ${file_in} ${file_out}
316              #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
317            else
318              IGCM_sys_Cp ${file_in} ${file_out}
319            fi
320            (( i=i+2 ))
321          done
322        fi
323      fi
324    done
325  fi
326  IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles"
327}
328
329#=======================================================================
330# Definition of Smooth modulo function
331# usage :
332# IGCM_SmoothModulo StringModulo value
333#
334# StringModulo : A string of min max and modulo like definition of Scilab vectors.
335# [min]:[modulo:][max]
336# where :
337# [] value are optionnals;
338# empty min equal 1
339# empty max equal infinity
340# modulo not given or empty equal 1
341# empty string or just ':' equal always.
342#
343# value : the value to test with the definition
344#
345# return : true(1)/false(0)
346function IGCM_SmoothModulo
347{
348  IGCM_debug_PushStack "IGCM_SmoothModulo"
349  typeset defVector ModValue
350
351  eval set +A defVector -- $( echo "${1}" | \
352    gawk -F ':' '{print ($1 == "" ? 1 : $1) " " (NF==3 ? ($2 == "" ? 1 : $2) : 1) " " (NF==3 ? ($3 == "" ? -1 : $3) : ($2 == "" ? -1 : $2))}' )
353
354  # Save Smooth Min and Max. Needed to call IGCM_sys_Get when appropriate
355  arr[1]=${defVector[0]}
356  arr[2]=${defVector[2]}
357
358  # Test limits :
359  # ${defVector[0]} <= ${2} <= ${defVector[2]}
360  #          or ${defVector[2]} == -1
361  if ( [ ${2} -ge ${defVector[0]} ] && ( [ ${2} -le ${defVector[2]} ] || [ ${defVector[2]} -lt 0 ] ) ) ; then
362    # Test modulo
363    ModValue=$( expr \( ${2} - ${defVector[0]} \) % ${defVector[1]} )
364    if [ ${ModValue} -eq 0 ] ;  then
365      arr[3]=true
366      echo ${arr[@]}
367      IGCM_debug_PopStack "IGCM_SmoothModulo"
368      return 1
369    else
370      arr[3]=false
371      echo ${arr[@]}
372      IGCM_debug_PopStack "IGCM_SmoothModulo"
373      return 0
374    fi
375  else
376    arr[3]=false
377    echo ${arr[@]}
378    IGCM_debug_PopStack "IGCM_SmoothModulo"
379    return 0
380  fi
381}
382
383#=======================================================================
384function IGCM_comp_GetInputSmoothFiles
385{
386  IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles"
387
388  # Debug Print :
389  echo
390  IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles"
391  echo
392
393  typeset comp compname comptagname card ListFilesName FileName0 NbFiles j i i_ i__
394  typeset file_in_ file_in file_out_ file_out ret SmoothDef aux val
395
396  for comp in ${config_ListOfComponents[*]} ; do
397    # Define component
398    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
399    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
400
401    # Debug Print :
402    IGCM_debug_Print 3 "Smooth files ${compname}"
403
404    card=${SUBMIT_DIR}/COMP/${compname}.card
405
406    IGCM_card_DefineArrayFromOption ${card} SmoothFiles List
407    ListFilesName=${compname}_SmoothFiles_List
408    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
409
410    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != X"Section" ] ) ; then
411      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
412
413      (( i=0 ))
414      until [ $i -ge $NbFiles ]; do
415        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
416        eval file_in=${file_in_}
417        (( i_ = i+1 ))
418        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
419        eval file_out=${file_out_}
420
421        # define CumulPeriod definition for this file
422        (( i__ = i+2 ))
423        eval SmoothDef=\${${ListFilesName}[$i__]}
424        IGCM_debug_Print 3 "  ${file_in} ${SmoothDef}"
425        aux=$( IGCM_SmoothModulo ${SmoothDef} ${CumulPeriod} )
426        j=1
427        for val in ${aux} ; do
428          [ ${j} -eq 1 ] && SmoothMin=${val}
429          [ ${j} -eq 2 ] && SmoothMax=${val}
430          [ ${j} -eq 3 ] && ret=${val}
431          (( j=j+1 ))
432        done
433        [ ${SmoothMax} -eq -1 ] && SmoothMax=${CumulPeriod}
434        if ( [ X${ret} = Xtrue ] || ( [ ${Period} -eq 1 ] && [ ${CumulPeriod} -ge ${SmoothMin} ] && [ ${CumulPeriod} -le ${SmoothMax} ] ) ) ; then
435
436          IGCM_sys_IsFileArchived ${file_in}
437          if [ $? = 0 ] ; then
438            IGCM_sys_Get ${file_in} ${file_out}
439            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
440          else
441            IGCM_sys_Cp ${file_in} ${file_out}
442          fi
443        fi
444        (( i=i+3 ))
445      done
446    fi
447  done
448
449  IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
450}
451
452#=======================================================================
453function IGCM_comp_GetInputBoundaryFiles
454{
455  IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
456
457  # Debug Print :
458  echo
459  IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles"
460  echo
461
462  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
463  typeset file_in_ file_in file_out_ file_out
464
465  if [ ${Period} = 1 ]; then
466    ListFixBoundary=" "
467  fi
468
469  for comp in ${config_ListOfComponents[*]} ; do
470
471    # Define component
472    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
473    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
474
475    # Debug Print :
476    IGCM_debug_Print 3 "Boundary files ${compname}"
477
478    card=${SUBMIT_DIR}/COMP/${compname}.card
479
480    IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
481    ListFilesName=${compname}_BoundaryFiles_List
482    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
483
484    if [ X${FileName0} != X${NULL_STR} ] ; then
485      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
486
487      (( i=0 ))
488      until [ $i -ge $NbFiles ]; do
489        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
490        eval file_in=${file_in_}
491        (( i_ = i+1 ))
492        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
493        eval file_out=${file_out_}
494
495        IGCM_sys_IsFileArchived ${file_in}
496        if [ $? = 0 ] ; then
497          IGCM_sys_Get ${file_in} ${file_out}
498          IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
499        else
500          IGCM_sys_Cp ${file_in} ${file_out}
501        fi
502
503        (( i=i+2 ))
504      done
505    fi
506
507    # Get non deleted files
508    if [ ${Period} = 1 ]; then
509
510      IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
511      ListFilesName=${compname}_BoundaryFiles_ListNonDel
512      eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
513
514      if [ X${FileName0} != X${NULL_STR} ] ; then
515        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
516
517        (( i=0 ))
518        until [ $i -ge $NbFiles ]; do
519          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
520          eval file_in=${file_in_}
521          (( i_ = i+1 ))
522          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
523          eval file_out=${file_out_}
524
525          IGCM_sys_IsFileArchived ${file_in}
526          if [ $? = 0 ] ; then
527            IGCM_sys_Get ${file_in} ${file_out}
528            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
529          else
530            IGCM_sys_Cp ${file_in} ${file_out}
531          fi
532
533          if [ X${file_out} != X. ] ; then
534            ListFixBoundary=${ListFixBoundary}" "${file_out}
535          else
536            ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
537          fi
538
539          (( i=i+2 ))
540        done
541      fi
542    fi
543  done
544
545  IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
546}
547
548#=======================================================================
549function IGCM_comp_DelFixeBoundaryFiles
550{
551  IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
552
553  # Debug Print :
554  echo
555  IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles"
556  echo
557
558  ls -l ${ListFixBoundary}
559  rm -f ${ListFixBoundary}
560
561  IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
562}
563
564#=======================================================================
565function IGCM_comp_GetInputParametersFiles
566{
567  IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
568
569  # Debug Print :
570  echo
571  IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles"
572  echo
573
574  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
575  for comp in ${config_ListOfComponents[*]} ; do
576    # Define component
577    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
578    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
579
580    # Debug Print :
581    IGCM_debug_Print 3 "Parameters ${compname}"
582
583    card=${SUBMIT_DIR}/COMP/${compname}.card
584
585    IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
586    ListFilesName=${compname}_ParametersFiles_List
587    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
588
589    if [ X${FileName0} != X${NULL_STR} ] ; then
590      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
591
592      (( i=0 ))
593      until [ $i -ge $NbFiles ]; do
594        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
595        eval file_in=${file_in_}
596        (( i_ = i+1 ))
597        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
598        eval file_out=${file_out_} 
599
600        IGCM_sys_Cp ${file_in} ${file_out} 
601        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
602
603        (( i=i+2 ))
604      done
605    fi
606  done
607
608  IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
609}
610
611#=======================================================================
612function IGCM_comp_GetInputRestartFiles
613{
614  IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
615
616  # Debug Print :
617  echo
618  IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles"
619  echo
620
621  typeset Date_tmp Date_r Path_r do_start CompOldName Path_OUT Path_BUF
622  typeset Buffered Archived Tared PotentialTarFile IsMatching TarFileFound
623  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
624  typeset file_in file_out file_in_ file_out_ file_in_Name
625  typeset -Z4 j4
626  #BASH declare j4
627
628  IsMatching=""
629
630  for comp in ${config_ListOfComponents[*]} ; do
631    # Define component
632    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
633    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
634    #
635    card=${SUBMIT_DIR}/COMP/${compname}.card
636    #
637    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
638    ListFilesName=${compname}_RestartFiles_List
639    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
640
641    # Debug Print :
642    IGCM_debug_Print 3 "restart ${compname}"
643
644    if ( ${FirstInitialize} ) ; then
645
646      if [ "${config_Restarts_OverRule}" = "y" ] ; then
647        eval config_${comp}_Restart="y"
648        eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
649        eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
650        eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
651        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
652        eval CompOldName=${comp}
653      else
654        # Read component Restarts parameters
655        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
656        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
657
658        if [ "${do_start}" = "y" ] ; then
659          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
660          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
661          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
662        else
663          eval config_${comp}_RestartDate=-1
664          eval config_${comp}_RestartJobName=${NULL_STR}
665          eval config_${comp}_RestartPath=${NULL_STR}
666        fi
667
668        eval CompOldName=\${config_${comp}_OldName}
669        if [ X${CompOldName} = X ] ; then
670          eval CompOldName=${comp}
671        fi
672
673        # Reinitialize IsMatching to allow searching for a different tar file for each component.
674        IsMatching=""
675        TarFileFound=""
676      fi
677
678      if [ "${do_start}" = "y" ] ; then
679
680        # Restore Restarts files
681        #-----------------------
682        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
683          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
684
685          (( i=1 ))
686          until [ $i -gt $NbFiles ]; do
687            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
688            eval file_in=${file_in_}
689            (( i_ = i+1 ))
690            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
691            eval file_out=${file_out_}
692
693            eval Date_tmp=\${config_${comp}_RestartDate}
694            Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
695            # will be re-use
696            eval RestartPath=\${config_${comp}_RestartPath}
697            eval RestartJobName=\${config_${comp}_RestartJobName}
698            #
699            Path_r=${RestartPath}/${RestartJobName}/${CompOldName}/Restart
700            file_in_Name=${RestartJobName}_${Date_r}_${file_in}
701
702            extension_in=$( echo ${file_in_Name##*.} )
703            extension_out=$( echo ${file_out##*.} )
704
705            generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
706            generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
707
708            Path_OUT=${Path_r}/${generic_restart_file_name_in}
709
710            if [ $( IGCM_sys_TestFileBuffer ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
711              IGCM_debug_Print 3 "Buffered restart"
712              Buffered=true
713              Archived=false
714              Tared=false
715              nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_OUT}_????.${extension_in})
716            elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
717              IGCM_debug_Print 3 "Archived restart"
718              Buffered=false
719              Archived=true
720              Tared=false
721              nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
722            else
723              IGCM_debug_Print 3 "Tared restart"
724              Buffered=false
725              Archived=false
726              Tared=true
727              # Look after the tar file we want if we did not found it already
728              if [ X${IsMatching} = X ] ; then
729                for PotentialTarFile in $( IGCM_sys_RshArchive "find ${RestartPath}/${RestartJobName}/RESTART -name "${RestartJobName}_*_restart.tar" -print" ) ; do
730                  IsMatching=$( echo ${PotentialTarFile##*/} | \
731                        sed "s:^${RestartJobName}_::" | \
732                        sed "s:\.restart\.tar$::" | \
733                        gawk -F_ -v restartdate=${Date_r} \
734                             '{if (($1 <= restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
735                  if [ ! X${IsMatching} = X ] ; then
736                    TarFileFound=${PotentialTarFile}
737                    break
738                  fi
739                done
740              fi
741              TarFileLocation=$( IGCM_sys_PrepareTaredRestart ${TarFileFound} )
742              IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
743              tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
744              nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
745            fi
746
747            if [ ${nb_restart_file} -gt 1 ] ; then
748              j=0                                      # BASH LINE NOT NEEDED
749              # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
750              until [ $j -ge ${nb_restart_file} ]; do  # BASH LINE NOT NEEDED
751                j4=${j}                                # BASH LINE NOT NEEDED
752                if [ X${Buffered} = Xtrue ] ; then
753                  IGCM_sys_GetBuffer ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
754                elif [ X${Archived} = Xtrue ] ; then
755                  IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
756                elif [ X${Tared} = Xtrue ] ; then
757                  IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
758                fi
759                (( j=j+1 ))                            #BASH LINE NOT NEEDED
760              done
761
762              if [ X${NUM_PROC_OCE} != X ] ; then
763                if [ ${NUM_PROC_OCE} -ne ${nb_restart_file} ] ; then
764                  IGCM_sys_rebuild ${generic_restart_file_name_out}.${extension_out} ${generic_restart_file_name_out}_????.${extension_out}
765                  IGCM_sys_Rm ${generic_restart_file_name_out}_????.${extension_out}
766                fi
767              fi
768            else
769              if [ X${Buffered} = Xtrue ] ; then
770                IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
771              elif [ X${Archived} = Xtrue ] ; then
772                IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
773              elif [ X${Tared} = Xtrue ] ; then
774                IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
775              fi
776            fi
777            (( i=i+3 ))
778          done
779
780        else
781          if [ X${FileName0} != XNONE ] ; then
782            IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
783          else
784            IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
785          fi
786        fi
787      fi
788    elif [ ${Period} -eq 1 ] ; then
789      # if not FirstInitialize and first loop of this job
790
791      # Restore Restarts files
792      #-----------------------
793      if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
794        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
795
796        (( i=1 ))
797        until [ $i -gt $NbFiles ]; do
798          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
799          eval file_in=${file_in_}
800          (( i_ = i+1 ))
801          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
802          eval file_out=${file_out_}
803
804          file_in_Name=${run_Configuration_OldPrefix}_${file_in}
805
806          extension_in=$( echo ${file_in_Name##*.} )
807          extension_out=$( echo ${file_out##*.} )
808
809          generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
810          generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
811
812          eval Path_BUF=\${R_BUF_${comp}_R}/${generic_restart_file_name_in}
813          eval Path_OUT=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
814
815          if [ $( IGCM_sys_TestFileBuffer ${Path_BUF}*.${extension_in} ; echo $? ) = 0 ] ; then
816            IGCM_debug_Print 3 "Buffered restart"
817            Buffered=true
818            Archived=false
819            Tared=false
820            nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_BUF}_????.${extension_in})
821          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
822            IGCM_debug_Print 3 "Archived restart"
823            Buffered=false
824            Archived=true
825            Tared=false
826            nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
827          else
828            IGCM_debug_Print 3 "Tared restart"
829            Buffered=false
830            Archived=false
831            Tared=true
832            # Look after the tar file we want if we did not found it already
833            if [ X${IsMatching} = X ] ; then
834              for PotentialTarFile in $( IGCM_sys_RshArchive "find ${R_SAVE}/RESTART -name "${config_UserChoices_JobName}_*_restart.tar" -print" ) ; do
835                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}}' )
836                if [ ! X${IsMatching} = X ] ; then
837                  TarFileFound=${PotentialTarFile}
838                  break
839                fi
840              done
841            fi
842            TarFileLocation=$( IGCM_sys_PrepareTaredRestart ${TarFileFound} )
843            IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
844            tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
845            nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
846          fi
847
848          if [ ${nb_restart_file} -gt 1 ] ; then
849            j=0                                     # BASH LINE NOT NEEDED
850            #BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
851            until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
852              j4=${j}                               # BASH LINE NOT NEEDED
853              if [ X${Buffered} = Xtrue ] ; then
854                IGCM_sys_GetBuffer ${Path_BUF}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
855              elif [ X${Archived} = Xtrue ] ; then
856                IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
857              elif [ X${Tared} = Xtrue ] ; then
858                IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
859              fi
860              (( j=j+1 ))                           # BASH LINE NOT NEEDED
861            done
862          else
863            if [ X${Buffered} = Xtrue ] ; then
864              eval IGCM_sys_GetBuffer \${R_BUF_${comp}_R}/${file_in_Name} ${file_out}
865            elif [ X${Archived} = Xtrue ] ; then
866              eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
867            elif [ X${Tared} = Xtrue ] ; then
868              IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
869            fi
870          fi
871          (( i=i+3 ))
872        done
873      else
874        if [ X${FileName0} != XNONE ] ; then
875          IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
876        else
877          IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
878        fi
879      fi
880    fi
881  done
882
883  NbFiles=$( ls * 2> /dev/null | wc -l )
884  if [ ${NbFiles} -gt 0 ] ; then
885    IGCM_sys_Chmod u+rw *
886  fi
887
888  IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
889}
890
891#=======================================================================
892function IGCM_comp_PeriodStart
893{
894  IGCM_debug_PushStack "IGCM_comp_PeriodStart"
895
896  # Debug Print :
897  echo
898  IGCM_debug_Print 1 "IGCM_comp_PeriodStart"
899  echo
900
901  typeset ExeNameIn ExeNameOut
902  typeset comp compname comptagname
903  for comp in ${config_ListOfComponents[*]} ; do
904    # Define component
905    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
906    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
907
908    # Copy executable for this component
909    eval ExeNameIn=\${config_Executable_${comp}[0]}
910    eval ExeNameOut=\${config_Executable_${comp}[1]}
911
912    # Debug Print
913    IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
914    # UPDATE component
915    ${comp}_PeriodStart 2> /dev/null
916
917  done
918
919  IGCM_debug_PopStack "IGCM_comp_PeriodStart"
920}
921
922#=======================================================================
923function IGCM_comp_Update
924{
925  IGCM_debug_PushStack "IGCM_comp_Update"
926
927    # Debug Print :
928  echo
929  IGCM_debug_Print 1 "IGCM_comp_Update"
930  echo
931
932  typeset ExeNameIn ExeNameOut
933  typeset comp compname comptagname
934  for comp in ${config_ListOfComponents[*]} ; do
935    # Define component
936    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
937    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
938
939    # Copy executable for this component
940    eval ExeNameIn=\${config_Executable_${comp}[0]}
941    eval ExeNameOut=\${config_Executable_${comp}[1]}
942
943    # If missing executable and DRYRUN is set to 0 or 1  then stop!
944    if [ ${DRYRUN} -le 1 ] && [ X${ExeNameIn} != X\"\" ] &&  [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
945      IGCM_debug_Exit "IGCM_comp_Update missing executable ${ExeNameIn}"
946    fi
947
948    if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
949      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
950      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
951        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
952      fi
953    elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
954      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
955      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
956        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
957      fi
958    fi
959
960    # Debug Print
961    IGCM_debug_Print 1 "Update ${compname} Parameter Files."
962    # UPDATE component
963    ${comp}_Update
964
965  done
966
967  IGCM_debug_PopStack "IGCM_comp_Update"
968}
969
970#=======================================================================
971function IGCM_comp_Finalize
972{
973  IGCM_debug_PushStack "IGCM_comp_Finalize"
974
975  # Debug Print :
976  echo
977  IGCM_debug_Print 1 "IGCM_comp_Finalize"
978  echo
979
980  typeset ListTextName TextName0
981  typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
982  typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
983  typeset -Z4 j4
984  #BASH declare j4
985  typeset list_file nlist_file
986  typeset compactoutputs
987
988  compactoutputs=false
989  if [ X${JobType} != XRUN ] ; then
990    compactoutputs=true
991  elif [ X${config_UserChoices_CompactText} != Xn ] ; then
992    compactoutputs=true
993  fi
994
995  for comp in ${config_ListOfComponents[*]} ; do
996    # Define component
997    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
998    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
999
1000    # Debug Print
1001    IGCM_debug_Print 1 "Finalize ${comp} : ${compname} component."
1002    # FINALIZE component
1003    ${comp}_Finalize
1004
1005    card=${SUBMIT_DIR}/COMP/${compname}.card
1006
1007    # Save Output Text files of models
1008    #---------------------------------
1009    IGCM_debug_Print 2 "Save Output Text files for ${comp} : ${compname} component."
1010    IGCM_card_DefineArrayFromOption ${card} OutputText List
1011    ListTextName=${compname}_OutputText_List
1012
1013    eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1014    if [ X${TextName0} != X${NULL_STR} ] ; then
1015      eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1016
1017      (( i=0 ))
1018      until [ $i -eq $NbFiles ]; do
1019        eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1020        eval file_out=${PREFIX}_${file_in}
1021
1022        (( i=i+1 ))
1023
1024        unset list_file
1025        #set +A list_file -- $( ls ${file_in}* | sort 2>/dev/null )
1026        # result for a a1 a10 a2 with file_in=a a a1 a2 a10
1027        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 )
1028        nlist_file=${#list_file[@]}
1029        if [ ${nlist_file} -gt 1 ] ; then
1030          if ( ${compactoutputs} ) ; then
1031            IGCM_debug_Print 2 "Parallelism of Text Output with ${nlist_file} files."
1032            IGCM_debug_Print 2 "Compact files in ${file_out} : " ${list_file[*]}
1033            echo ${list_file[*]} > ${file_out}
1034            echo "" >> ${file_out}
1035
1036            (( i_ = 0 ))
1037            for file in ${list_file[@]}
1038            do
1039              echo "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " >> ${file_out}
1040              echo "| " ${i_} " " ${file} >> ${file_out}
1041              echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " >> ${file_out}
1042              cat ${file} | sed "s/\(.*\)/${i_}\1/" ${file} >> ${file_out}
1043              echo "" >> ${file_out}
1044              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1045                  (( i_ = i_ + 1 ))
1046            done
1047            if [ X${Pack} = Xtrue ] ; then
1048              eval IGCM_sys_PutBuffer_Out ${file_out} \${R_BUF_${comp}_D}/${file_out}
1049            else
1050              eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}_D}/${file_out}
1051            fi
1052            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_out}" > /dev/null 2>&1
1053
1054            if ( ${ExecutionFail} ) ; then
1055              IGCM_sys_Cp ${file_out} ${SUBMIT_DIR}/Debug
1056            fi
1057          else
1058            for file in ${list_file[@]}
1059            do
1060              if [ X${Pack} = Xtrue ] ; then
1061                eval IGCM_sys_PutBuffer_Out ${file} \${R_BUF_${comp}_D}/${PREFIX}_${file}
1062              else
1063                eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
1064              fi
1065              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1066
1067              if ( ${ExecutionFail} ) ; then
1068                IGCM_sys_Cp ${file} ${SUBMIT_DIR}/Debug/${PREFIX}_${file}
1069              fi
1070            done
1071          fi
1072        else
1073          if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1074            eval IGCM_sys_Mv ${file_in}* ${file_in}
1075          fi
1076          if [ X${Pack} = Xtrue ] ; then
1077            eval IGCM_sys_PutBuffer_Out ${file_in} \${R_BUF_${comp}_D}/${file_out}
1078          else
1079            eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${file_out}
1080          fi
1081          eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1082
1083          if ( ${ExecutionFail} ) ; then
1084            IGCM_sys_Cp ${file_in} ${SUBMIT_DIR}/Debug/${file_out}
1085          fi
1086        fi
1087      done
1088    fi
1089
1090    # Save Restarts files
1091    #--------------------
1092    IGCM_debug_Print 2 "Save Restart files for ${comp} : ${compname} component."
1093    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
1094    ListFilesName=${compname}_RestartFiles_List
1095    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1096
1097    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
1098      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1099
1100      (( i=0 ))
1101      until [ $i -ge $NbFiles ]; do
1102        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1103        eval file_in=${file_in_}
1104
1105        (( i_ = i+1 ))
1106        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1107        eval file_out=${file_out_}
1108
1109        (( i_ = i+2 ))
1110        eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1111        eval file_outin=${file_outin_}
1112
1113        generic_restart_file_name_in=$(    basename ${file_in} .nc )
1114        generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
1115        generic_restart_file_name_outin=$( basename ${file_outin} .nc )
1116
1117        nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l ) 
1118        if [ ${nb_restart_file} -gt 1 ] ; then
1119          j=0                                     # BASH LINE NOT NEEDED
1120          # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
1121          until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
1122            j4=${j}                               # BASH LINE NOT NEEDED
1123            if [ X${Pack} = Xtrue ] ; then
1124              eval IGCM_sys_PutBuffer_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_BUF_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1125            else
1126              eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1127            fi
1128            if [ ! ${file_in} = ${file_outin} ] ; then
1129              if ( ${ExitFlag} ) ; then
1130                echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
1131              else
1132                IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
1133              fi
1134            fi
1135            (( j=j+1 ))                           # BASH LINE NOT NEEDED
1136          done
1137        else
1138          if [ X${Pack} = Xtrue ] ; then
1139            eval IGCM_sys_PutBuffer_Rest ${file_in} \${R_BUF_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1140          else
1141            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1142          fi
1143          if [ ! ${file_in} = ${file_outin} ] ; then
1144            if ( ${ExitFlag} ) ; then
1145              echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1146            else
1147              IGCM_sys_Mv ${file_in} ${file_outin}
1148            fi
1149          fi
1150        fi
1151
1152        (( i=i+3 ))
1153      done
1154    else
1155      if [ X${FileName0} != XNONE ] ; then
1156        IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
1157      else
1158        IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
1159      fi
1160    fi
1161
1162    # Save Output files
1163    #------------------
1164    IGCM_debug_Print 2 "Save Output files for ${comp} : ${compname} component."
1165    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
1166    ListFilesName=${compname}_OutputFiles_List
1167    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1168
1169    if [ X${FileName0} != X${NULL_STR} ] ; then
1170      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1171
1172      (( i=0 ))
1173      until [ $i -ge $NbFiles ]; do
1174        SaveOnArchive=true
1175        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1176        eval file_in=${file_in_}
1177        (( i_ = i+1 ))
1178        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1179        eval file_out=${file_out_}
1180        #
1181        # Override file_out path remplacing R_SAVE by R_BUFR
1182        #
1183        if [ X${Pack} = Xtrue ] ; then
1184          file_out=$( echo $file_out | sed "s:^$R_SAVE:$R_BUFR:" )
1185        fi
1186        #
1187        # Not necessarily the best option. /!\ Potential side effects /!\
1188        #
1189        (( i_ = i+2 ))
1190        eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1191        #
1192        generic_file_name=$( basename ${file_in} .nc )
1193        nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
1194        #
1195        if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
1196          IGCM_debug_Print 2 "Parallelism with 1 file. Rebuilding ${file_in} not needed"
1197          IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
1198        elif [ ${nb_rebuild_file} -gt 1 ] ; then
1199          IGCM_debug_Print 2 "Parallelism detected and rebuilding ${file_in} is needed"
1200          if [ X${AsynchronousRebuild} = Xfalse ] ; then
1201            IGCM_debug_Print 2 "Rebuilding ${file_in} online"
1202            IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
1203          else
1204            IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
1205            [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1206            IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1207
1208            # Prepare headers for the shell dedicated to offline rebuild
1209            if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
1210              if [ $DRYRUN -le 1 ]; then
1211                echo "#!/bin/ksh                                        " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1212                echo "function IGCM_FlushRebuild                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1213                echo "{                                                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1214                echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1215                echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1216                echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1217                echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1218                echo "export R_SAVE=${R_SAVE}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1219                echo "export R_BUFR=${R_BUFR}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1220                echo "export R_OUT_KSH=${R_OUT_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1221                echo "export R_BUF_KSH=${R_BUF_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1222                echo "export config_UserChoices_JobName=${config_UserChoices_JobName}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1223                echo "export config_UserChoices_SpaceName=${config_UserChoices_SpaceName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1224              fi
1225            fi
1226            # Prepare the shell dedicated to offline rebuild
1227            if [ $DRYRUN -le 1 ]; then
1228              if [ ${file_in} = histstn.nc ] ; then
1229                echo "IGCM_sys_rebuild_station ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1230              else
1231                echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1232              fi
1233              echo "IGCM_debug_Verif_Exit_Post" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1234            fi
1235            #
1236            # Load Patch we need to apply and apply
1237            if [ $DRYRUN -le 1 ]; then
1238              if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
1239                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
1240                  echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1241                  echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1242                  echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1243                done
1244              fi
1245            fi
1246            #
1247            if [ $DRYRUN -le 1 ]; then
1248              if [ X${Pack} = Xtrue ] ; then
1249                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1250              else
1251                echo "IGCM_sys_Put_Out ${file_in} ${file_out}           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1252              fi
1253              echo "IGCM_debug_Verif_Exit_Post                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1254              echo "IGCM_sys_Rm ${generic_file_name}_*.nc               " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1255            fi
1256            SaveOnArchive=false
1257          fi
1258        fi
1259        #
1260        if [ ${SaveOnArchive} = true ] ; then
1261          #
1262          # Rebuild has been done online or it was not needed
1263          #
1264          # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
1265          #
1266          thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
1267          if ( [ ! X${thereisapatch} = X${NULL_STR} ] && [ X${AsynchronousRebuild} = Xtrue ] && [ -f ${file_in} ] ) ; then
1268            [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1269            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1270            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
1271            #
1272            if [ $DRYRUN -le 1 ]; then
1273              if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
1274                echo "#!/bin/ksh                                      " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1275                echo "function IGCM_FlushRebuild                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1276                echo "{                                               " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1277                echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1278                echo "echo                                            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1279                echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1280                echo "echo                                            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1281                echo "export R_SAVE=${R_SAVE}                         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1282                echo "export config_UserChoices_JobName=${config_UserChoices_JobName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1283              fi
1284              #
1285              for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
1286                echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1287                echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1288                echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1289              done
1290              #
1291              if [ X${Pack} = Xtrue ] ; then
1292                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1293              else
1294                echo "IGCM_sys_Put_Out ${file_in} ${file_out}         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1295              fi
1296              echo "IGCM_debug_Verif_Exit_Post                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1297              #
1298            fi
1299          else
1300            #
1301            # No Patch, No Asynchronous rebuild, online rebuild has been done or was not needed
1302            #
1303            if [ X${Pack} = Xtrue ] ; then
1304              IGCM_sys_PutBuffer_Out ${file_in} ${file_out}
1305            else
1306              IGCM_sys_Put_Out ${file_in} ${file_out}
1307            fi
1308            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1309            if [ ${nb_rebuild_file} -gt 1 ] ; then
1310              for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
1311                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
1312              done
1313            fi
1314          fi
1315        fi
1316        (( i=i+3 ))
1317      done
1318    fi
1319    echo
1320  done
1321  IGCM_debug_PopStack "IGCM_comp_Finalize"
1322}
Note: See TracBrowser for help on using the repository browser.