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

Last change on this file since 387 was 387, checked in by sdipsl, 13 years ago
  • function IGCM_sys_Get_Master on cesium will try 10 times to scp files from master machine. Hopefully the last cesium consolidation
  • function IGCM_config_Check will check chunck2D/3D consistency with TimeSeriesFrequency?.
  • change the way the output from post-processing script was named. We will now have:

-rebuild_fromWorkdir.20051231.out
-create_ts.20051231.2D.out
-create_ts.20051231.3D.out
-atlas_PISCES.19991231.out
-create_ts.20051231.Chunck2D.ATM.POST_1D_histday.out
-create_ts.20051231.Chunck2D.OCE.POST_1D_grid_T.out

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