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

Last change on this file since 413 was 412, checked in by sdipsl, 13 years ago
  • Bug fix due to the scope of function variables.

Doing aux=$( myfunction ) : this makes the function be called in a separate ksh process, which cannot dynamically share variables back to the parent shell.

  • 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: 38.9 KB
RevLine 
[2]1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
[373]5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
[2]9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#========================================================================
15function IGCM_comp_Initialize
16{
17    IGCM_debug_PushStack "IGCM_comp_Initialize"
18
19    # Debug Print :
20    echo
21    IGCM_debug_Print 1 "IGCM_comp_Initialize :"
22    echo
23
[155]24    typeset comp compname comptagname CompatibilityTag auxprint card_UserChoices first_option i j
[2]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
[149]81        IGCM_debug_Print 1 "DefineArrayFromSection : ${compname}_UserChoices ${card}"
[2]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}
[100]93                eval IGCM_debug_Print 3 "${compname}_UserChoices_values: ${option} \${card_UserChoices_${option}}"
[2]94            done
95        fi
96
[149]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
[365]110            #
[155]111            i=2
[149]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
[239]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                   
[149]141                    # Dimension = vide si vieille card.
142                    IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars
143                    IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches
[247]144                    if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not found ${flag_post}" ] ; then
[149]145                        # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob.
[152]146                        ListDimension[0]=2D
147                        ListDimension[1]=3D
[149]148                        TimeSeries=false
[152]149                        iLoop=${#ListDimension[*]}
[155]150                        j=0
151                        until [ $j -ge ${iLoop} ]; do
152                            Dimension=${ListDimension[${j}]}
[149]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
[380]160                                    IGCM_debug_Print 3 "${Dimension} time series activated for ${flag_post}"
[149]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}} )
[237]169                                if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
[380]170                                    IGCM_debug_Print 3 "${Dimension} time series activated with chunck for ${flag_post}"
[149]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}
[387]174                                    eval set +A CHUNCK${Dimension}_NAME \${CHUNCK${Dimension}_NAME[*]} ${flag_post}
[149]175                                    eval set +A CHUNCK${Dimension}_SIZE \${CHUNCK${Dimension}_SIZE[*]} ${chunck_size}
176                                fi
177                            fi
[155]178                            (( j=j+1 ))
[149]179                        done
180                    else
[152]181                        ListDimension[0]=""
[149]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
[2]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}
[159]277                      #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
[2]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#=======================================================================
[247]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"
[412]308
309    set -vx
[247]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
[412]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
[247]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
[412]328            arr[3]=true
329            echo ${arr[@]}
[247]330            IGCM_debug_PopStack "IGCM_SmoothModulo"
331            return 1
332        else
[412]333            arr[3]=false
334            echo ${arr[@]}
[247]335            IGCM_debug_PopStack "IGCM_SmoothModulo"
336            return 0
337        fi
338    else
[412]339        arr[3]=false
340        echo ${arr[@]}
[247]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
[412]351    set -vx
352
[247]353    # Debug Print :
354    echo
355    IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles :"
356    echo
357
[412]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
[247]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
[270]376        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != X"Section" ] ) ; then
[247]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}"
[412]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                if ( [ X${ret} = Xtrue ] || ( [ ${Period} -eq 1 ] && [ ${CumulPeriod} -ge ${SmoothMin} ] && [ ${CumulPeriod} -le ${SmoothMax} ] ) ) ; then
[247]400                    IGCM_sys_Get ${file_in} ${file_out}
[260]401                    #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
[247]402                fi
403                (( i=i+3 ))
404            done
405        fi
406    done
407   
408    IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
409}
410
411#=======================================================================
[2]412function IGCM_comp_GetInputBoundaryFiles
413{
414    IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
415
416    # Debug Print :
417    echo
418    IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles :"
419    echo
420
421    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
422    typeset file_in_ file_in file_out_ file_out
423
424    if [ ${Period} = 1 ]; then
425        ListFixBoundary=" "
426    fi
427
428    for comp in ${config_ListOfComponents[*]} ; do
429
430        echo "-----"
431        # Define component
432        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
433        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
434
435        # Debug Print :
436        IGCM_debug_Print 3 "Boundary files ${compname}"
437
438        card=${SUBMIT_DIR}/COMP/${compname}.card
439
440        IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
441        ListFilesName=${compname}_BoundaryFiles_List
442        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
443
444        if [ X${FileName0} != X${NULL_STR} ] ; then
445            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
446
447            (( i=0 ))
448            until [ $i -ge $NbFiles ]; do
449                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
450                eval file_in=${file_in_}
451                (( i_ = i+1 ))
452                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
453                eval file_out=${file_out_}
454
455                IGCM_sys_Get ${file_in} ${file_out}
456                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
457
458                (( i=i+2 ))
459            done
460        fi
461
462        # Get non deleted files
463        if [ ${Period} = 1 ]; then
464
465            IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
466            ListFilesName=${compname}_BoundaryFiles_ListNonDel
467            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
468           
469            if [ X${FileName0} != X${NULL_STR} ] ; then
470                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
471               
472                (( i=0 ))
473                until [ $i -ge $NbFiles ]; do
474                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
475                    eval file_in=${file_in_}
476                    (( i_ = i+1 ))
477                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
478                    eval file_out=${file_out_}
479
480                    IGCM_sys_Get ${file_in} ${file_out}
481
482                    if [ X${file_out} != X. ] ; then
483                        ListFixBoundary=${ListFixBoundary}" "${file_out}
484                    else
485                        ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
486                    fi
487
488                    (( i=i+2 ))
489                done
490            fi
491        fi
492    done
493   
494    IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
495}
496
497#=======================================================================
498function IGCM_comp_DelFixeBoundaryFiles
499{
500    IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
501
502    # Debug Print :
503    echo
504    IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles :"
505    echo
506
507    ls -l ${ListFixBoundary}
508    rm -f ${ListFixBoundary}
509
510    IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
511}
512
513#=======================================================================
514function IGCM_comp_GetInputParametersFiles
515{
516    IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
517
518    # Debug Print :
519    echo
520    IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles :"
521    echo
522
523    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
524    for comp in ${config_ListOfComponents[*]} ; do
525        # Define component
526        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
527        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
528
529        # Debug Print :
530        IGCM_debug_Print 3 "Parameters ${compname}"
531
532        card=${SUBMIT_DIR}/COMP/${compname}.card       
533
534        IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
535        ListFilesName=${compname}_ParametersFiles_List
536        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
537
538        if [ X${FileName0} != X${NULL_STR} ] ; then
539            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
540
541            (( i=0 ))
542            until [ $i -ge $NbFiles ]; do
543                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
544                eval file_in=${file_in_}
545                (( i_ = i+1 ))
546                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
547                eval file_out=${file_out_} 
548
549                IGCM_sys_Cp ${file_in} ${file_out} 
550                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
551
552                (( i=i+2 ))
553            done
554        fi
555    done
556
557    IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
558}
559
560#=======================================================================
561function IGCM_comp_GetInputRestartFiles
562{
563    IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
564
565    # Debug Print :
566    echo
567    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles :"
568    echo
569
[38]570    typeset Date_tmp Date_r Path_r do_start CompOldName Path_temp
[2]571    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
572    typeset file_in file_out file_in_ file_out_ file_in_Name
[38]573    typeset -Z4 j4
[2]574
575    for comp in ${config_ListOfComponents[*]} ; do
576        # Define component
577        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
578        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
[151]579        #
580        card=${SUBMIT_DIR}/COMP/${compname}.card
581        #
582        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
583        ListFilesName=${compname}_RestartFiles_List
584        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
[2]585
586        # Debug Print :
587        IGCM_debug_Print 3 "restart ${compname}"
588
589        if ( ${FirstInitialize} ) ; then
590
591            if [ "${config_Restarts_OverRule}" = "y" ] ; then
592                eval config_${comp}_Restart="y"
593                eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
594                eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
595                eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
596                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
597                eval CompOldName=${comp}
598            else
599                # Read component Restarts parameters
600                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
601                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
602
603                if [ "${do_start}" = "y" ] ; then
604                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
605                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
606                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
607                else
608                    eval config_${comp}_RestartDate=-1
609                    eval config_${comp}_RestartJobName=${NULL_STR}
610                    eval config_${comp}_RestartPath=${NULL_STR}
611                fi
612                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} OldName
613                eval CompOldName=\${config_${comp}_OldName}
614                if [ X${CompOldName} = X ] ; then
615                    eval CompOldName=${comp}
616                fi
617            fi
618
619            if [ "${do_start}" = "y" ] ; then
620
621                if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
622                    eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
623
624                    (( i=1 ))
625                    until [ $i -gt $NbFiles ]; do
626                        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
627                        eval file_in=${file_in_}
628
629                        (( i_ = i+1 ))
630                        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
631                        eval file_out=${file_out_}
632                       
633                        eval Date_tmp=\${config_${comp}_RestartDate}
634                        Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
635                        eval Path_r=\${config_${comp}_RestartPath}/\${config_${comp}_RestartJobName}/${CompOldName}/Restart
636                        eval file_in_Name=\${config_${comp}_RestartJobName}_${Date_r}_${file_in}
637
[38]638                        generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
639                        generic_restart_file_name_out=$( basename ${file_out} .nc )
640                       
641                        eval Path_temp=\${Path_r}/${generic_restart_file_name_in}
[67]642                        nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc)
[2]643
[41]644                        if [ ${nb_restart_file} -gt 1 ] ; then
645                            j=0
646                            until [ $j -ge $nb_restart_file ]; do
647                                j4=${j}
648                                eval IGCM_sys_Get ${Path_r}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
[151]649                                #IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
650                                #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
[41]651                                (( j=j+1 ))
652                            done
653                        else
[38]654                            eval IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out} 
[151]655                            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
[41]656                        fi
[2]657               
658                        (( i=i+3 ))
659                    done
660                else
661                    if [ X${FileName0} != XNONE ] ; then
662                        IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
663                    else
664                        IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
665                    fi
666                fi
667            fi
[151]668        elif [ ${Period} -eq 1 ] ; then
669            # if not FirstInitialize and first loop of this job
[2]670
671            # Restore Restarts files
672            #-----------------------
673            if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
674                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
675
676                (( i=1 ))
677                until [ $i -gt $NbFiles ]; do
678                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
679                    eval file_in=${file_in_}
680                    (( i_ = i+1 ))
681                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
682                    eval file_out=${file_out_}
683                   
684                    file_in_Name=${run_Configuration_OldPrefix}_${file_in}
685
[38]686                    generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
687                    generic_restart_file_name_out=$( basename ${file_out} .nc )
[2]688
[38]689                    eval Path_temp=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
[67]690                    nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc)
691
[41]692                    if [ ${nb_restart_file} -gt 1 ] ; then
693                        j=0
694                        until [ $j -ge $nb_restart_file ]; do
695                            j4=${j}
696                            eval IGCM_sys_Get \${R_OUT_${comp}_R}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
[151]697                            #IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
698                            #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
[41]699
700                            (( j=j+1 ))
701                        done
702                    else
[38]703                        eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
[151]704                        #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
[41]705                    fi
[38]706
[2]707                    (( i=i+3 ))
708                done
709            else
710                if [ X${FileName0} != XNONE ] ; then
711                    IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
712                else
713                    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
714                fi
715            fi
716        fi
717    done
[92]718    IGCM_sys_Chmod u+rw *
[2]719
720    IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
721}
722
723#=======================================================================
[269]724function IGCM_comp_PeriodStart
725{
726    IGCM_debug_PushStack "IGCM_comp_PeriodStart"
727
728    # Debug Print :
729    echo
730    IGCM_debug_Print 1 "IGCM_comp_PeriodStart :"
731    echo
732
733    typeset ExeNameIn ExeNameOut
734    typeset comp compname comptagname
735    for comp in ${config_ListOfComponents[*]} ; do
736        # Define component
737        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
738        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
739
740        # Copy executable for this component
741        eval ExeNameIn=\${config_Executable_${comp}[0]}
742        eval ExeNameOut=\${config_Executable_${comp}[1]}
743
744        # Debug Print
745        IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
746        # UPDATE component
747        ${comp}_PeriodStart 2> /dev/null
748
749    done
750
751    IGCM_debug_PopStack "IGCM_comp_PeriodStart"
752}
753
754#=======================================================================
[2]755function IGCM_comp_Update
756{
757    IGCM_debug_PushStack "IGCM_comp_Update"
758
759    # Debug Print :
760    echo
761    IGCM_debug_Print 1 "IGCM_comp_Update :"
762    echo
763
764    typeset ExeNameIn ExeNameOut
765    typeset comp compname comptagname
766    for comp in ${config_ListOfComponents[*]} ; do
767        # Define component
768        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
769        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
770
771        # Copy executable for this component
772        eval ExeNameIn=\${config_Executable_${comp}[0]}
773        eval ExeNameOut=\${config_Executable_${comp}[1]}
[151]774
[236]775        # If missing executable then stop!
[237]776        #if [ ! X${ExeNameIn} = X ] && [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
777        #    IGCM_debug_Exit "IGCM_comp_Update missing executable ${ExeNameIn}"
778        #fi
[236]779
[151]780        if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
[2]781            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
782            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
783                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
[151]784            fi
785        elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
786            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
787            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
788                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
789            fi
[2]790        fi
791
792        # Debug Print
793        IGCM_debug_Print 3 "Update ${compname} Parameter Files."
794        # UPDATE component
795        ${comp}_Update
796
797    done
798
799    IGCM_debug_PopStack "IGCM_comp_Update"
800}
801
802#=======================================================================
803function IGCM_comp_Finalize
804{
805    IGCM_debug_PushStack "IGCM_comp_Finalize"
806
807    # Debug Print :
808    echo
809    IGCM_debug_Print 1 "IGCM_comp_Finalize :"
810    echo
811
812    typeset ListTextName TextName0
[22]813    typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
[151]814    typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
[38]815    typeset -Z4 j4
[2]816    for comp in ${config_ListOfComponents[*]} ; do
817        # Define component
818        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
819        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
820
821        # Debug Print
822        IGCM_debug_Print 1 "Finalize ${compname} component."
823        # FINALIZE component
824        ${comp}_Finalize
825
826        card=${SUBMIT_DIR}/COMP/${compname}.card       
827
828        # Save Restarts files
829        #--------------------
830        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
831        ListFilesName=${compname}_RestartFiles_List
832        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
833       
834        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
835            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
836           
837            (( i=0 ))
838            until [ $i -ge $NbFiles ]; do
839                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
840                eval file_in=${file_in_}
841
842                (( i_ = i+1 ))
843                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
844                eval file_out=${file_out_}
[151]845
846                (( i_ = i+2 ))
847                eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
848                eval file_outin=${file_outin_}
849
850                generic_restart_file_name_in=$(    basename ${file_in} .nc )
851                generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
852                generic_restart_file_name_outin=$( basename ${file_outin} .nc )
[38]853                       
[42]854                nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l ) 
[41]855                if [ ${nb_restart_file} -gt 1 ] ; then
856                    j=0
857                    until [ $j -ge $nb_restart_file ]; do
858                        j4=${j}
859                        eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
[296]860                        if [ ! ${file_in} = ${file_outin} ] ; then
861                            if ( ${ExitFlag} ) ; then
862                                echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
863                            else
864                                IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
865                            fi
866                        fi
[151]867                        #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_in}_${j4}.nc" > /dev/null 2>&1
[41]868                        (( j=j+1 ))
869                    done
870                else
[38]871                    eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
[296]872                    if [ ! ${file_in} = ${file_outin} ] ; then
873                        if ( ${ExitFlag} ) ; then
874                            echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
875                        else
876                            IGCM_sys_Mv ${file_in} ${file_outin}
877                        fi
878                    fi
[151]879                    #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
[41]880                fi
[2]881
882                (( i=i+3 ))
883            done
884        else
885            if [ X${FileName0} != XNONE ] ; then
886                IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
887            else
888                IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
889            fi
890        fi
891
892        # Save Output files
893        #------------------
894        IGCM_card_DefineArrayFromOption ${card} OutputFiles List
895        ListFilesName=${compname}_OutputFiles_List
896        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
897
898        if [ X${FileName0} != X${NULL_STR} ] ; then
899            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
900
901            (( i=0 ))
902            until [ $i -ge $NbFiles ]; do
[22]903                SaveOnArchive=true
[2]904                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
905                eval file_in=${file_in_}
906                (( i_ = i+1 ))
907                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
908                eval file_out=${file_out_}
[149]909                (( i_ = i+2 ))
910                eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
[22]911                #
[2]912                generic_file_name=$( basename ${file_in} .nc )
[306]913                nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
[22]914                #
915                if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
916                    IGCM_debug_Print 2 "Parallelism with 1 process. Rebuilding ${file_in} not needed"
[2]917                    IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
[22]918                elif [ ${nb_rebuild_file} -gt 1 ] ; then
919                    IGCM_debug_Print 2 "Parallelism detected rebuilding ${file_in} is needed"
920                    if ( [ X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ X${config_Post_RebuildFrequency} = XNONE ] ) ; then
921                        IGCM_debug_Print 2 "Rebuilding ${file_in} online"
922                        IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
923                    else
924                        IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
[34]925                        [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
[22]926                        IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
[149]927
[238]928                        # Prepare headers for the shell dedicated to offline rebuild
[22]929                        if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
[238]930                            if [ $DRYRUN -le 1 ]; then
[309]931                            echo "#!/bin/ksh                                          " > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[296]932                            echo "function IGCM_FlushRebuild                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
933                            echo "{                                                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[306]934                            echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[296]935                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[306]936                            echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[296]937                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[380]938                            echo "export R_SAVE=${R_SAVE}                             " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
939                            echo "export config_UserChoices_JobName=${config_UserChoices_JobName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[238]940                            fi
[22]941                        fi
942                        # Prepare the shell dedicated to offline rebuild
[238]943                        if [ $DRYRUN -le 1 ]; then
[296]944                            echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[409]945                            echo "IGCM_debug_Verif_Exit_Post                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[238]946                        fi
[149]947                        #
948                        # Load Patch we need to apply and apply
[238]949                        if [ $DRYRUN -le 1 ]; then
950                            if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
951                                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
[296]952                                    echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
953                                    echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[409]954                                    echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[238]955                                done
956                            fi
[149]957                        fi
958                        #
[238]959                        if [ $DRYRUN -le 1 ]; then
[296]960                            echo "IGCM_sys_Put_Out ${file_in} ${file_out}                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[409]961                            echo "IGCM_debug_Verif_Exit_Post                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[296]962                            echo "IGCM_sys_Rm ${generic_file_name}_*.nc                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[238]963                        fi
[22]964                        SaveOnArchive=false
965                    fi
[2]966                fi
[22]967                #
968                if [ ${SaveOnArchive} = true ] ; then
[149]969                    #
970                    # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
971                    #
[307]972                    thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
973                   
974                    if ( [ ! X${thereisapatch} =  X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = X ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
[149]975                        if [ -f ${file_in} ] ; then
[307]976                            [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
977
[149]978                            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
979                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
980                            #
[238]981                            if [ $DRYRUN -le 1 ]; then
[307]982                                if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
[318]983                                    echo "#!/bin/ksh                                          " > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[307]984                                    echo "function IGCM_FlushRebuild                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
985                                    echo "{                                                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
986                                    echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
987                                    echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
988                                    echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
989                                    echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
990                                fi
991                                #
[238]992                                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
[296]993                                    echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh    " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
994                                    echo "IGCM_${Patch} ${file_in}                            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[409]995                                    echo "IGCM_debug_Verif_Exit_Post                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[238]996                                done
997                                #
[296]998                                echo "IGCM_sys_Put_Out ${file_in} ${file_out}                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[409]999                                echo "IGCM_debug_Verif_Exit_Post                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[238]1000                                #
1001                            fi
[149]1002                        fi
1003                    else
[307]1004                        [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1005                        if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
[318]1006                            echo "#!/bin/ksh                                          " > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[307]1007                            echo "function IGCM_FlushRebuild                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1008                            echo "{                                                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1009                            echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1010                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1011                            echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1012                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1013                        fi
1014
[149]1015                        IGCM_sys_Put_Out ${file_in} ${file_out}
1016                        [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1017                        if [ ${nb_rebuild_file} -gt 1 ] ; then
1018                            for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
1019                                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
1020                            done
1021                        fi
[2]1022                    fi
1023                fi
1024                (( i=i+3 ))
1025            done
1026        fi
1027
1028        # Save Output Text files of models
1029        #---------------------------------
1030       
1031        IGCM_card_DefineArrayFromOption ${card} OutputText List
1032        ListTextName=${compname}_OutputText_List
1033       
1034        eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1035        if [ X${TextName0} != X${NULL_STR} ] ; then
1036            eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1037
1038            (( i=0 ))
1039            until [ $i -eq $NbFiles ]; do
1040                eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1041                (( i=i+1 ))
1042
1043                nb_text_file=$( ls ${file_in}* 2>/dev/null | wc -l )
1044                if [ ${nb_text_file} -gt 1 ] ; then
1045                    list_file=$( ls ${file_in}* )
1046                    for file in ${list_file}
1047                      do
1048                      eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
1049                      eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1050                    done
1051                else
1052                    if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1053                        eval IGCM_sys_Mv ${file_in}* ${file_in}
1054                    fi
1055                    eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${PREFIX}_${file_in}
[52]1056                    [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
[2]1057                fi
1058            done
1059        fi
1060    done
1061
1062    IGCM_debug_PopStack "IGCM_comp_Finalize"
1063}
Note: See TracBrowser for help on using the repository browser.