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

Last change on this file since 414 was 414, checked in by sdipsl, 13 years ago
  • Bug fix : AA_create_se & AA_create_multi_se.

: SmoothFile : SmoothMax? not well handle
: monitoring lauch by 2D/3D TsTask?. Better solution will come

  • 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: 39.0 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 i j
25    for comp in ${config_ListOfComponents[*]} ; do
26        # Debug Print
27        IGCM_debug_Print 1 ${comp}
28        # Define component
29        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
30        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
31        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
32
33        # Read libIGCM compatibility version in ${compname}.card
34        card=${SUBMIT_DIR}/COMP/${compname}.card
35        IGCM_card_DefineVariableFromOption ${card} Compatibility libIGCM
36        eval CompatibilityTag=\${${compname}_Compatibility_libIGCM} > /dev/null 2>&1   
37
38        if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then
39            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 ."
40        fi
41
42        # Manage component executable
43        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card Executable ${comp}
44
45        # Read component Write Frequency in config.card
46        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} WriteFrequency
47        # Debug Print :
48        eval auxprint=\${config_${comp}_WriteFrequency}
49        IGCM_debug_Print 1 "Write frequency for ${compname} : ${auxprint} "
50        #2> /dev/null
51
52        # Debug Print :
53        IGCM_debug_Print 1 "Initialize following component library :"
54        IGCM_debug_Print 1 ${SUBMIT_DIR}/COMP/${compname}.driver
55        IGCM_debug_Print 3 "With tag : ${comptagname}"
56        # Source component library
57        . ${SUBMIT_DIR}/COMP/${compname}.driver
58
59        # Debug Print
60        IGCM_debug_Print 3 "Initialize ${comp} output directory."
61        # Define Dirs   
62        eval R_OUT_${comp}=${R_SAVE}/${comp}
63        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}}
64
65        eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output
66        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O}
67
68        eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart
69        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R}
70
71        eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug
72        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D}
73
74        eval R_OUT_${comp}_O_I=\${R_OUT_${comp}_O}/INS
75        eval R_OUT_${comp}_O_H=\${R_OUT_${comp}_O}/HF
76        eval R_OUT_${comp}_O_D=\${R_OUT_${comp}_O}/DA
77        eval R_OUT_${comp}_O_M=\${R_OUT_${comp}_O}/MO
78        eval R_OUT_${comp}_O_Y=\${R_OUT_${comp}_O}/YE
79
80        # Read UserChoices section of component card
81        IGCM_debug_Print 1 "DefineArrayFromSection : ${compname}_UserChoices ${card}"
82        IGCM_card_DefineArrayFromSection ${card} UserChoices
83        eval first_option=\${${compname}_UserChoices[0]} > /dev/null 2>&1
84        if [ X${first_option} != X"Error:" ] ; then
85            eval IGCM_debug_Print 2 "${compname}_UserChoices_Options:" \${${compname}_UserChoices[*]}
86            if [ X${card_UserChoices[0]} != X ] ; then
87                unset card_UserChoices
88            fi
89            eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1
90            typeset option
91            for option in ${card_UserChoices[*]} ; do
92                IGCM_card_DefineVariableFromOption ${card} UserChoices ${option}
93                eval IGCM_debug_Print 3 "${compname}_UserChoices_values: ${option} \${card_UserChoices_${option}}"
94            done
95        fi
96
97        # Read and Build Output File stuff
98        IGCM_debug_Print 1 "DefineArrayFromOption  : ${compname}_OutputFiles ${card}"
99        IGCM_card_DefineArrayFromOption ${card} OutputFiles List
100        ListFilesName=${compname}_OutputFiles_List
101        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
102        #
103        if [ X${FileName0} != X${NULL_STR} ] ; then
104            #
105            #IGCM_debug_Print 1 "Component      : ${compname}"
106            #
107            # INITIALISATION
108            #
109            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
110            #
111            i=2
112            #
113            until [ $i -ge $NbFiles ]; do
114                #
115                eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
116                #
117                if [ X${flag_post} != XNONE ] ; then
118                    #
119                    # First of all
120                    #
121                    IGCM_card_DefineArrayFromSection ${card} ${flag_post}
122                    #
123                    # Seasonal case : If option Seasonal is not found (old cards) put SEASONAL ON by default
124                    #
125                    # variable option allready typeset above
126                    for option in $( eval echo \${${compname}_${flag_post}[*]} ) ; do
127                        if [ ${option} = Seasonal ] ; then
128                            FoundSeasonal=true
129                            IGCM_card_DefineVariableFromOption ${card} ${flag_post} Seasonal
130                        fi
131                    done
132                    #
133                    if [ ! X${FoundSeasonal} = Xtrue ] ; then
134                        eval ${compname}_${flag_post}_Seasonal=ON
135                    fi
136                    #
137                    if [ $( eval echo \${${compname}_${flag_post}_Seasonal} ) = ON ] ; then
138                        Seasonal=true
139                    fi
140                   
141                    # Dimension = vide si vieille card.
142                    IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars
143                    IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches
144                    if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not found ${flag_post}" ] ; then
145                        # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob.
146                        ListDimension[0]=2D
147                        ListDimension[1]=3D
148                        TimeSeries=false
149                        iLoop=${#ListDimension[*]}
150                        j=0
151                        until [ $j -ge ${iLoop} ]; do
152                            Dimension=${ListDimension[${j}]}
153                            IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension}
154                            IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension}
155                            #
156                            # Time series WITHOUT chunk
157                            #
158                            if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
159                                if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then
160                                    IGCM_debug_Print 3 "${Dimension} time series activated for ${flag_post}"
161                                    eval TimeSeries${Dimension}=true
162                                fi
163                            fi
164                            #
165                            # Time series WITH chunk
166                            #
167                            if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
168                                chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} )
169                                if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
170                                    IGCM_debug_Print 3 "${Dimension} time series activated with chunck for ${flag_post}"
171                                    eval TimeSeriesChunck${Dimension}=true
172                                    eval set +A CHUNCK${Dimension}_COMP \${CHUNCK${Dimension}_COMP[*]} ${comp}
173                                    eval set +A CHUNCK${Dimension}_FLAG \${CHUNCK${Dimension}_FLAG[*]} ${i}
174                                    eval set +A CHUNCK${Dimension}_NAME \${CHUNCK${Dimension}_NAME[*]} ${flag_post}
175                                    eval set +A CHUNCK${Dimension}_SIZE \${CHUNCK${Dimension}_SIZE[*]} ${chunck_size}
176                                fi
177                            fi
178                            (( j=j+1 ))
179                        done
180                    else
181                        ListDimension[0]=""
182                        TimeSeries=true
183                        TimeSeries2D=false
184                        TimeSeries3D=false
185                        TimeSeriesChunck2D=false
186                        TimeSeriesChunck3D=false
187                    fi
188                fi
189                (( i=i+3 ))
190            done
191        fi
192        # Debug Print
193        IGCM_debug_Print 3 "Initialize ${compname} with driver."
194        # INIT component
195        ${comp}_Initialize
196        echo
197    done
198    echo "-----"
199    echo
200    IGCM_debug_Print 1 "DefineArrayFromOption  : ListOfComponents"
201    IGCM_debug_PrintVariables 3 config_ListOfComponents
202
203    IGCM_debug_PopStack "IGCM_comp_Initialize"
204}
205
206#=======================================================================
207function IGCM_comp_PrepareDeletedFiles
208{
209    IGCM_debug_PushStack "IGCM_comp_PrepareDeletedFiles" $@
210   
211    if [ X${2} != X. ] ; then
212        eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${2} ) > /dev/null 2>&1
213    else
214        eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${1} ) > /dev/null 2>&1
215    fi
216
217    IGCM_debug_PopStack "IGCM_comp_PrepareDeletedFiles"
218}
219
220#=======================================================================
221function IGCM_comp_GetInputInitialStateFiles
222{
223    IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles"
224
225    # Debug Print :
226    echo
227    IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles :"
228    echo
229
230    # Only the first time step need InitialStateFiles
231    # otherwise it's BoundaryConditions
232    if ( ${FirstInitialize} ) ; then
233      typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
234      typeset file_in_ file_in file_out_ file_out do_init
235      for comp in ${config_ListOfComponents[*]} ; do
236          # Initialize
237          do_init="y"
238          # Do we need to bring initial state file for this component
239          if [ "${config_Restarts_OverRule}" = "y" ] ; then
240              eval do_init="n"
241          else
242              # Read component Restarts parameters
243              IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
244              eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
245              if [ "${do_start}" = "y" ] ; then
246                    do_init="n"
247              else
248                    do_init="y"
249              fi
250          fi
251
252          if [ "${do_init}" = "y" ] ; then
253              # Define component
254              eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
255              eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
256
257              # Debug Print :
258              IGCM_debug_Print 3 "Initialisation files ${compname}"
259
260              card=${SUBMIT_DIR}/COMP/${compname}.card
261
262              IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List
263              ListFilesName=${compname}_InitialStateFiles_List
264
265              eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
266              if [ X${FileName0} != X${NULL_STR} ] ; then
267                  eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
268                  (( i=0 ))
269                  until [ $i -ge $NbFiles ]; do
270                      eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
271                      eval file_in=${file_in_}
272                      (( i_ = i+1 ))
273                      eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
274                      eval file_out=${file_out_}
275                     
276                      IGCM_sys_Get ${file_in} ${file_out}
277                      #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
278
279                      (( i=i+2 ))
280                  done
281              fi
282          fi
283      done
284    fi
285    IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles"
286}
287
288#=======================================================================
289# Definition of Smooth modulo function
290# usage :
291# IGCM_SmoothModulo StringModulo value
292#
293# StringModulo : A string of min max and modulo like definition of Scilab vectors.
294# [min]:[modulo:][max]
295# where :
296# [] value are optionnals;
297# empty min equal 1
298# empty max equal infinity
299# modulo not given or empty equal 1
300# empty string or just ':' equal always.
301#
302# value : the value to test with the definition
303#
304# return : true(1)/false(0)
305function IGCM_SmoothModulo
306{
307    IGCM_debug_PushStack "IGCM_SmoothModulo"
308
309    set -vx
310    typeset defVector ModValue
311
312    eval set +A defVector -- $( echo "${1}" | \
313        gawk -F ':' '{print ($1 == "" ? 1 : $1) " " (NF==3 ? ($2 == "" ? 1 : $2) : 1) " " (NF==3 ? ($3 == "" ? -1 : $3) : ($2 == "" ? -1 : $2))}' )
314
315    # Save Smooth Min and Max. Needed to call IGCM_sys_Get when appropriate
316    arr[1]=${defVector[0]}
317    arr[2]=${defVector[2]}
318
319    # Test limits :
320    # ${defVector[0]} <= ${2} <= ${defVector[2]}
321    #                                      or ${defVector[2]} == -1
322    if ( [ ${2} -ge ${defVector[0]} ] && \
323         ( [ ${2} -le ${defVector[2]} ] || \
324           [ ${defVector[2]} -lt 0 ] ) ) ; then
325        # Test modulo
326        ModValue=$( expr \( ${2} - ${defVector[0]} \) % ${defVector[1]} )
327        if [ ${ModValue} -eq 0 ] ;  then
328            arr[3]=true
329            echo ${arr[@]}
330            IGCM_debug_PopStack "IGCM_SmoothModulo"
331            return 1
332        else
333            arr[3]=false
334            echo ${arr[@]}
335            IGCM_debug_PopStack "IGCM_SmoothModulo"
336            return 0
337        fi
338    else
339        arr[3]=false
340        echo ${arr[@]}
341        IGCM_debug_PopStack "IGCM_SmoothModulo"
342        return 0
343    fi
344}
345
346#=======================================================================
347function IGCM_comp_GetInputSmoothFiles
348{
349    IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles"
350
351    set -vx
352
353    # Debug Print :
354    echo
355    IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles :"
356    echo
357
358    typeset comp compname comptagname card ListFilesName FileName0 NbFiles j i i_ i__
359    typeset file_in_ file_in file_out_ file_out ret SmoothDef aux val
360
361    for comp in ${config_ListOfComponents[*]} ; do
362        echo "-----"
363        # Define component
364        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
365        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
366
367        # Debug Print :
368        IGCM_debug_Print 3 "Smooth files ${compname}"
369
370        card=${SUBMIT_DIR}/COMP/${compname}.card
371
372        IGCM_card_DefineArrayFromOption ${card} SmoothFiles List
373        ListFilesName=${compname}_SmoothFiles_List
374        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
375
376        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != X"Section" ] ) ; then
377            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
378
379            (( i=0 ))
380            until [ $i -ge $NbFiles ]; do
381                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
382                eval file_in=${file_in_}
383                (( i_ = i+1 ))
384                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
385                eval file_out=${file_out_}
386
387                # define CumulPeriod definition for this file
388                (( i__ = i+2 ))
389                eval SmoothDef=\${${ListFilesName}[$i__]}
390                IGCM_debug_Print 3 "  ${file_in} ${SmoothDef}"
391                aux=$( IGCM_SmoothModulo ${SmoothDef} ${CumulPeriod} )
392                j=1
393                for val in ${aux} ; do
394                    [ ${j} -eq 1 ] && SmoothMin=${val}
395                    [ ${j} -eq 2 ] && SmoothMax=${val}
396                    [ ${j} -eq 3 ] && ret=${val}
397                    (( j=j+1 ))
398                done
399                [ ${SmoothMax} -eq -1 ] && SmoothMax=${CumulPeriod}
400                if ( [ X${ret} = Xtrue ] || ( [ ${Period} -eq 1 ] && [ ${CumulPeriod} -ge ${SmoothMin} ] && [ ${CumulPeriod} -le ${SmoothMax} ] ) ) ; then
401                #if ( [ X${ret} = Xtrue ] || [ ${Period} -eq 1 ] ) ; then
402                    IGCM_sys_Get ${file_in} ${file_out}
403                    #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
404                fi
405                (( i=i+3 ))
406            done
407        fi
408    done
409   
410    IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
411}
412
413#=======================================================================
414function IGCM_comp_GetInputBoundaryFiles
415{
416    IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
417
418    # Debug Print :
419    echo
420    IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles :"
421    echo
422
423    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
424    typeset file_in_ file_in file_out_ file_out
425
426    if [ ${Period} = 1 ]; then
427        ListFixBoundary=" "
428    fi
429
430    for comp in ${config_ListOfComponents[*]} ; do
431
432        echo "-----"
433        # Define component
434        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
435        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
436
437        # Debug Print :
438        IGCM_debug_Print 3 "Boundary files ${compname}"
439
440        card=${SUBMIT_DIR}/COMP/${compname}.card
441
442        IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
443        ListFilesName=${compname}_BoundaryFiles_List
444        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
445
446        if [ X${FileName0} != X${NULL_STR} ] ; then
447            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
448
449            (( i=0 ))
450            until [ $i -ge $NbFiles ]; do
451                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
452                eval file_in=${file_in_}
453                (( i_ = i+1 ))
454                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
455                eval file_out=${file_out_}
456
457                IGCM_sys_Get ${file_in} ${file_out}
458                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
459
460                (( i=i+2 ))
461            done
462        fi
463
464        # Get non deleted files
465        if [ ${Period} = 1 ]; then
466
467            IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
468            ListFilesName=${compname}_BoundaryFiles_ListNonDel
469            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
470           
471            if [ X${FileName0} != X${NULL_STR} ] ; then
472                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
473               
474                (( i=0 ))
475                until [ $i -ge $NbFiles ]; do
476                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
477                    eval file_in=${file_in_}
478                    (( i_ = i+1 ))
479                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
480                    eval file_out=${file_out_}
481
482                    IGCM_sys_Get ${file_in} ${file_out}
483
484                    if [ X${file_out} != X. ] ; then
485                        ListFixBoundary=${ListFixBoundary}" "${file_out}
486                    else
487                        ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
488                    fi
489
490                    (( i=i+2 ))
491                done
492            fi
493        fi
494    done
495   
496    IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
497}
498
499#=======================================================================
500function IGCM_comp_DelFixeBoundaryFiles
501{
502    IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
503
504    # Debug Print :
505    echo
506    IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles :"
507    echo
508
509    ls -l ${ListFixBoundary}
510    rm -f ${ListFixBoundary}
511
512    IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
513}
514
515#=======================================================================
516function IGCM_comp_GetInputParametersFiles
517{
518    IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
519
520    # Debug Print :
521    echo
522    IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles :"
523    echo
524
525    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
526    for comp in ${config_ListOfComponents[*]} ; do
527        # Define component
528        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
529        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
530
531        # Debug Print :
532        IGCM_debug_Print 3 "Parameters ${compname}"
533
534        card=${SUBMIT_DIR}/COMP/${compname}.card       
535
536        IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
537        ListFilesName=${compname}_ParametersFiles_List
538        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
539
540        if [ X${FileName0} != X${NULL_STR} ] ; then
541            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
542
543            (( i=0 ))
544            until [ $i -ge $NbFiles ]; do
545                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
546                eval file_in=${file_in_}
547                (( i_ = i+1 ))
548                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
549                eval file_out=${file_out_} 
550
551                IGCM_sys_Cp ${file_in} ${file_out} 
552                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
553
554                (( i=i+2 ))
555            done
556        fi
557    done
558
559    IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
560}
561
562#=======================================================================
563function IGCM_comp_GetInputRestartFiles
564{
565    IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
566
567    # Debug Print :
568    echo
569    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles :"
570    echo
571
572    typeset Date_tmp Date_r Path_r do_start CompOldName Path_temp
573    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
574    typeset file_in file_out file_in_ file_out_ file_in_Name
575    typeset -Z4 j4
576
577    for comp in ${config_ListOfComponents[*]} ; do
578        # Define component
579        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
580        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
581        #
582        card=${SUBMIT_DIR}/COMP/${compname}.card
583        #
584        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
585        ListFilesName=${compname}_RestartFiles_List
586        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
587
588        # Debug Print :
589        IGCM_debug_Print 3 "restart ${compname}"
590
591        if ( ${FirstInitialize} ) ; then
592
593            if [ "${config_Restarts_OverRule}" = "y" ] ; then
594                eval config_${comp}_Restart="y"
595                eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
596                eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
597                eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
598                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
599                eval CompOldName=${comp}
600            else
601                # Read component Restarts parameters
602                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
603                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
604
605                if [ "${do_start}" = "y" ] ; then
606                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
607                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
608                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
609                else
610                    eval config_${comp}_RestartDate=-1
611                    eval config_${comp}_RestartJobName=${NULL_STR}
612                    eval config_${comp}_RestartPath=${NULL_STR}
613                fi
614                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} OldName
615                eval CompOldName=\${config_${comp}_OldName}
616                if [ X${CompOldName} = X ] ; then
617                    eval CompOldName=${comp}
618                fi
619            fi
620
621            if [ "${do_start}" = "y" ] ; then
622
623                if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
624                    eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
625
626                    (( i=1 ))
627                    until [ $i -gt $NbFiles ]; do
628                        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
629                        eval file_in=${file_in_}
630
631                        (( i_ = i+1 ))
632                        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
633                        eval file_out=${file_out_}
634                       
635                        eval Date_tmp=\${config_${comp}_RestartDate}
636                        Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
637                        eval Path_r=\${config_${comp}_RestartPath}/\${config_${comp}_RestartJobName}/${CompOldName}/Restart
638                        eval file_in_Name=\${config_${comp}_RestartJobName}_${Date_r}_${file_in}
639
640                        generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
641                        generic_restart_file_name_out=$( basename ${file_out} .nc )
642                       
643                        eval Path_temp=\${Path_r}/${generic_restart_file_name_in}
644                        nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc)
645
646                        if [ ${nb_restart_file} -gt 1 ] ; then
647                            j=0
648                            until [ $j -ge $nb_restart_file ]; do
649                                j4=${j}
650                                eval IGCM_sys_Get ${Path_r}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
651                                #IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
652                                #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
653                                (( j=j+1 ))
654                            done
655                        else
656                            eval IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out} 
657                            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
658                        fi
659               
660                        (( i=i+3 ))
661                    done
662                else
663                    if [ X${FileName0} != XNONE ] ; then
664                        IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
665                    else
666                        IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
667                    fi
668                fi
669            fi
670        elif [ ${Period} -eq 1 ] ; then
671            # if not FirstInitialize and first loop of this job
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                    file_in_Name=${run_Configuration_OldPrefix}_${file_in}
687
688                    generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
689                    generic_restart_file_name_out=$( basename ${file_out} .nc )
690
691                    eval Path_temp=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
692                    nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc)
693
694                    if [ ${nb_restart_file} -gt 1 ] ; then
695                        j=0
696                        until [ $j -ge $nb_restart_file ]; do
697                            j4=${j}
698                            eval IGCM_sys_Get \${R_OUT_${comp}_R}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
699                            #IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
700                            #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
701
702                            (( j=j+1 ))
703                        done
704                    else
705                        eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
706                        #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
707                    fi
708
709                    (( i=i+3 ))
710                done
711            else
712                if [ X${FileName0} != XNONE ] ; then
713                    IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
714                else
715                    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
716                fi
717            fi
718        fi
719    done
720    IGCM_sys_Chmod u+rw *
721
722    IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
723}
724
725#=======================================================================
726function IGCM_comp_PeriodStart
727{
728    IGCM_debug_PushStack "IGCM_comp_PeriodStart"
729
730    # Debug Print :
731    echo
732    IGCM_debug_Print 1 "IGCM_comp_PeriodStart :"
733    echo
734
735    typeset ExeNameIn ExeNameOut
736    typeset comp compname comptagname
737    for comp in ${config_ListOfComponents[*]} ; do
738        # Define component
739        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
740        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
741
742        # Copy executable for this component
743        eval ExeNameIn=\${config_Executable_${comp}[0]}
744        eval ExeNameOut=\${config_Executable_${comp}[1]}
745
746        # Debug Print
747        IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
748        # UPDATE component
749        ${comp}_PeriodStart 2> /dev/null
750
751    done
752
753    IGCM_debug_PopStack "IGCM_comp_PeriodStart"
754}
755
756#=======================================================================
757function IGCM_comp_Update
758{
759    IGCM_debug_PushStack "IGCM_comp_Update"
760
761    # Debug Print :
762    echo
763    IGCM_debug_Print 1 "IGCM_comp_Update :"
764    echo
765
766    typeset ExeNameIn ExeNameOut
767    typeset comp compname comptagname
768    for comp in ${config_ListOfComponents[*]} ; do
769        # Define component
770        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
771        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
772
773        # Copy executable for this component
774        eval ExeNameIn=\${config_Executable_${comp}[0]}
775        eval ExeNameOut=\${config_Executable_${comp}[1]}
776
777        # If missing executable then stop!
778        #if [ ! X${ExeNameIn} = X ] && [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
779        #    IGCM_debug_Exit "IGCM_comp_Update missing executable ${ExeNameIn}"
780        #fi
781
782        if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
783            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
784            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
785                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
786            fi
787        elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
788            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
789            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
790                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
791            fi
792        fi
793
794        # Debug Print
795        IGCM_debug_Print 3 "Update ${compname} Parameter Files."
796        # UPDATE component
797        ${comp}_Update
798
799    done
800
801    IGCM_debug_PopStack "IGCM_comp_Update"
802}
803
804#=======================================================================
805function IGCM_comp_Finalize
806{
807    IGCM_debug_PushStack "IGCM_comp_Finalize"
808
809    # Debug Print :
810    echo
811    IGCM_debug_Print 1 "IGCM_comp_Finalize :"
812    echo
813
814    typeset ListTextName TextName0
815    typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
816    typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
817    typeset -Z4 j4
818    for comp in ${config_ListOfComponents[*]} ; do
819        # Define component
820        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
821        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
822
823        # Debug Print
824        IGCM_debug_Print 1 "Finalize ${compname} component."
825        # FINALIZE component
826        ${comp}_Finalize
827
828        card=${SUBMIT_DIR}/COMP/${compname}.card       
829
830        # Save Restarts files
831        #--------------------
832        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
833        ListFilesName=${compname}_RestartFiles_List
834        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
835       
836        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
837            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
838           
839            (( i=0 ))
840            until [ $i -ge $NbFiles ]; do
841                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
842                eval file_in=${file_in_}
843
844                (( i_ = i+1 ))
845                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
846                eval file_out=${file_out_}
847
848                (( i_ = i+2 ))
849                eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
850                eval file_outin=${file_outin_}
851
852                generic_restart_file_name_in=$(    basename ${file_in} .nc )
853                generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
854                generic_restart_file_name_outin=$( basename ${file_outin} .nc )
855                       
856                nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l ) 
857                if [ ${nb_restart_file} -gt 1 ] ; then
858                    j=0
859                    until [ $j -ge $nb_restart_file ]; do
860                        j4=${j}
861                        eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
862                        if [ ! ${file_in} = ${file_outin} ] ; then
863                            if ( ${ExitFlag} ) ; then
864                                echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
865                            else
866                                IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
867                            fi
868                        fi
869                        #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_in}_${j4}.nc" > /dev/null 2>&1
870                        (( j=j+1 ))
871                    done
872                else
873                    eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
874                    if [ ! ${file_in} = ${file_outin} ] ; then
875                        if ( ${ExitFlag} ) ; then
876                            echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
877                        else
878                            IGCM_sys_Mv ${file_in} ${file_outin}
879                        fi
880                    fi
881                    #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
882                fi
883
884                (( i=i+3 ))
885            done
886        else
887            if [ X${FileName0} != XNONE ] ; then
888                IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
889            else
890                IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
891            fi
892        fi
893
894        # Save Output files
895        #------------------
896        IGCM_card_DefineArrayFromOption ${card} OutputFiles List
897        ListFilesName=${compname}_OutputFiles_List
898        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
899
900        if [ X${FileName0} != X${NULL_STR} ] ; then
901            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
902
903            (( i=0 ))
904            until [ $i -ge $NbFiles ]; do
905                SaveOnArchive=true
906                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
907                eval file_in=${file_in_}
908                (( i_ = i+1 ))
909                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
910                eval file_out=${file_out_}
911                (( i_ = i+2 ))
912                eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
913                #
914                generic_file_name=$( basename ${file_in} .nc )
915                nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
916                #
917                if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
918                    IGCM_debug_Print 2 "Parallelism with 1 process. Rebuilding ${file_in} not needed"
919                    IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
920                elif [ ${nb_rebuild_file} -gt 1 ] ; then
921                    IGCM_debug_Print 2 "Parallelism detected rebuilding ${file_in} is needed"
922                    if ( [ X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ X${config_Post_RebuildFrequency} = XNONE ] ) ; then
923                        IGCM_debug_Print 2 "Rebuilding ${file_in} online"
924                        IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
925                    else
926                        IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
927                        [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
928                        IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
929
930                        # Prepare headers for the shell dedicated to offline rebuild
931                        if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
932                            if [ $DRYRUN -le 1 ]; then
933                            echo "#!/bin/ksh                                          " > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
934                            echo "function IGCM_FlushRebuild                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
935                            echo "{                                                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
936                            echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
937                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
938                            echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
939                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
940                            echo "export R_SAVE=${R_SAVE}                             " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
941                            echo "export config_UserChoices_JobName=${config_UserChoices_JobName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
942                            fi
943                        fi
944                        # Prepare the shell dedicated to offline rebuild
945                        if [ $DRYRUN -le 1 ]; then
946                            echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
947                            echo "IGCM_debug_Verif_Exit_Post                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
948                        fi
949                        #
950                        # Load Patch we need to apply and apply
951                        if [ $DRYRUN -le 1 ]; then
952                            if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
953                                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
954                                    echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
955                                    echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
956                                    echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
957                                done
958                            fi
959                        fi
960                        #
961                        if [ $DRYRUN -le 1 ]; then
962                            echo "IGCM_sys_Put_Out ${file_in} ${file_out}                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
963                            echo "IGCM_debug_Verif_Exit_Post                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
964                            echo "IGCM_sys_Rm ${generic_file_name}_*.nc                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
965                        fi
966                        SaveOnArchive=false
967                    fi
968                fi
969                #
970                if [ ${SaveOnArchive} = true ] ; then
971                    #
972                    # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
973                    #
974                    thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
975                   
976                    if ( [ ! X${thereisapatch} =  X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = X ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
977                        if [ -f ${file_in} ] ; then
978                            [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
979
980                            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
981                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
982                            #
983                            if [ $DRYRUN -le 1 ]; then
984                                if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
985                                    echo "#!/bin/ksh                                          " > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
986                                    echo "function IGCM_FlushRebuild                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
987                                    echo "{                                                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
988                                    echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
989                                    echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
990                                    echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
991                                    echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
992                                fi
993                                #
994                                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
995                                    echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh    " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
996                                    echo "IGCM_${Patch} ${file_in}                            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
997                                    echo "IGCM_debug_Verif_Exit_Post                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
998                                done
999                                #
1000                                echo "IGCM_sys_Put_Out ${file_in} ${file_out}                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1001                                echo "IGCM_debug_Verif_Exit_Post                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1002                                #
1003                            fi
1004                        fi
1005                    else
1006                        [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1007                        if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
1008                            echo "#!/bin/ksh                                          " > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1009                            echo "function IGCM_FlushRebuild                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1010                            echo "{                                                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1011                            echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1012                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1013                            echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1014                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1015                        fi
1016
1017                        IGCM_sys_Put_Out ${file_in} ${file_out}
1018                        [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1019                        if [ ${nb_rebuild_file} -gt 1 ] ; then
1020                            for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
1021                                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
1022                            done
1023                        fi
1024                    fi
1025                fi
1026                (( i=i+3 ))
1027            done
1028        fi
1029
1030        # Save Output Text files of models
1031        #---------------------------------
1032       
1033        IGCM_card_DefineArrayFromOption ${card} OutputText List
1034        ListTextName=${compname}_OutputText_List
1035       
1036        eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1037        if [ X${TextName0} != X${NULL_STR} ] ; then
1038            eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1039
1040            (( i=0 ))
1041            until [ $i -eq $NbFiles ]; do
1042                eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1043                (( i=i+1 ))
1044
1045                nb_text_file=$( ls ${file_in}* 2>/dev/null | wc -l )
1046                if [ ${nb_text_file} -gt 1 ] ; then
1047                    list_file=$( ls ${file_in}* )
1048                    for file in ${list_file}
1049                      do
1050                      eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
1051                      eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1052                    done
1053                else
1054                    if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1055                        eval IGCM_sys_Mv ${file_in}* ${file_in}
1056                    fi
1057                    eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${PREFIX}_${file_in}
1058                    [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1059                fi
1060            done
1061        fi
1062    done
1063
1064    IGCM_debug_PopStack "IGCM_comp_Finalize"
1065}
Note: See TracBrowser for help on using the repository browser.