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

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