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

Last change on this file since 309 was 309, checked in by mafoipsl, 14 years ago

Use TMPDIR for mercure again. Correct CompletedFlag? initialisation. Delete useless echo. Correct 1st line or rebuild.ksh.

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