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

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