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

Last change on this file since 422 was 422, checked in by mmaipsl, 13 years ago

Marie-Alice has seen my last commit on protection of chmod was wrong. Sorry.

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