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

Last change on this file since 457 was 457, checked in by sdipsl, 13 years ago
  • Bugfix on titane. Exe files has never been saved and ExeFileSize? in the run.card has always been false. Due to ExeSize? variable scope, decalare local to a function but assigned in another function. It works by chance on some machine, because ExeSize? is not initialized...
  • Bugfix of the revision [433]. out_orchidee was always save in SUBMIT_DIR.
  • Now if a job fail : all concatenated debug files (OutputTextFiles?) will be place in SUBMIT_DIR/Debug for convenience.
  • Continuation of [431], concatenate text files following numerical instead of alphabetical order. MAF.
  • Cosmetic and verbosty has been revisited.
  • 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: 40.5 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 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
37        eval CompatibilityTag=\${${compname}_Compatibility_libIGCM} > /dev/null 2>&1   
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 2 "Initialize following component library"
54        IGCM_debug_Print 2 ${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 2 "DefineArrayFromSection : ${compname}_UserChoices ${card}"
82        IGCM_card_DefineArrayFromSection ${card} UserChoices
83        eval first_option=\${${compname}_UserChoices[0]} > /dev/null 2>&1
84        # If section is not empty we define corresponding variables
85        if [ X${first_option} != X"Error:" ] ; then
86            eval IGCM_debug_Print 3 "${compname}_UserChoices_Options:" \${${compname}_UserChoices[*]}
87            if [ X${card_UserChoices[0]} != X ] ; then
88                unset card_UserChoices
89            fi
90            eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1
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 2 "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
199    IGCM_debug_PopStack "IGCM_comp_Initialize"
200}
201
202#=======================================================================
203function IGCM_comp_PrepareDeletedFiles
204{
205    IGCM_debug_PushStack "IGCM_comp_PrepareDeletedFiles" $@
206   
207    if [ X${2} != X. ] ; then
208        eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${2} ) > /dev/null 2>&1
209    else
210        eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${1} ) > /dev/null 2>&1
211    fi
212
213    IGCM_debug_PopStack "IGCM_comp_PrepareDeletedFiles"
214}
215
216#=======================================================================
217function IGCM_comp_GetInputInitialStateFiles
218{
219    IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles"
220
221    # Debug Print :
222    echo
223    IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles"
224    echo
225
226    # Only the first time step need InitialStateFiles
227    # otherwise it's BoundaryConditions
228    if ( ${FirstInitialize} ) ; then
229      typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
230      typeset file_in_ file_in file_out_ file_out do_init
231      for comp in ${config_ListOfComponents[*]} ; do
232          # Initialize
233          do_init="y"
234          # Do we need to bring initial state file for this component
235          if [ "${config_Restarts_OverRule}" = "y" ] ; then
236              eval do_init="n"
237          else
238              # Read component Restarts parameters
239              IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
240              eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
241              if [ "${do_start}" = "y" ] ; then
242                    do_init="n"
243              else
244                    do_init="y"
245              fi
246          fi
247
248          if [ "${do_init}" = "y" ] ; then
249              # Define component
250              eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
251              eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
252
253              # Debug Print :
254              IGCM_debug_Print 3 "Initialisation files ${compname}"
255
256              card=${SUBMIT_DIR}/COMP/${compname}.card
257
258              IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List
259              ListFilesName=${compname}_InitialStateFiles_List
260
261              eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
262              if [ X${FileName0} != X${NULL_STR} ] ; then
263                  eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
264                  (( i=0 ))
265                  until [ $i -ge $NbFiles ]; do
266                      eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
267                      eval file_in=${file_in_}
268                      (( i_ = i+1 ))
269                      eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
270                      eval file_out=${file_out_}
271                     
272                      IGCM_sys_Get ${file_in} ${file_out}
273                      #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
274
275                      (( i=i+2 ))
276                  done
277              fi
278          fi
279      done
280    fi
281    IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles"
282}
283
284#=======================================================================
285# Definition of Smooth modulo function
286# usage :
287# IGCM_SmoothModulo StringModulo value
288#
289# StringModulo : A string of min max and modulo like definition of Scilab vectors.
290# [min]:[modulo:][max]
291# where :
292# [] value are optionnals;
293# empty min equal 1
294# empty max equal infinity
295# modulo not given or empty equal 1
296# empty string or just ':' equal always.
297#
298# value : the value to test with the definition
299#
300# return : true(1)/false(0)
301function IGCM_SmoothModulo
302{
303    IGCM_debug_PushStack "IGCM_SmoothModulo"
304    typeset defVector ModValue
305
306    eval set +A defVector -- $( echo "${1}" | \
307        gawk -F ':' '{print ($1 == "" ? 1 : $1) " " (NF==3 ? ($2 == "" ? 1 : $2) : 1) " " (NF==3 ? ($3 == "" ? -1 : $3) : ($2 == "" ? -1 : $2))}' )
308
309    # Save Smooth Min and Max. Needed to call IGCM_sys_Get when appropriate
310    arr[1]=${defVector[0]}
311    arr[2]=${defVector[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        # Test modulo
320        ModValue=$( expr \( ${2} - ${defVector[0]} \) % ${defVector[1]} )
321        if [ ${ModValue} -eq 0 ] ;  then
322            arr[3]=true
323            echo ${arr[@]}
324            IGCM_debug_PopStack "IGCM_SmoothModulo"
325            return 1
326        else
327            arr[3]=false
328            echo ${arr[@]}
329            IGCM_debug_PopStack "IGCM_SmoothModulo"
330            return 0
331        fi
332    else
333        arr[3]=false
334        echo ${arr[@]}
335        IGCM_debug_PopStack "IGCM_SmoothModulo"
336        return 0
337    fi
338}
339
340#=======================================================================
341function IGCM_comp_GetInputSmoothFiles
342{
343    IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles"
344
345    # Debug Print :
346    echo
347    IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles"
348    echo
349
350    typeset comp compname comptagname card ListFilesName FileName0 NbFiles j i i_ i__
351    typeset file_in_ file_in file_out_ file_out ret SmoothDef aux val
352
353    for comp in ${config_ListOfComponents[*]} ; do
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                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
373                eval file_in=${file_in_}
374                (( i_ = i+1 ))
375                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
376                eval file_out=${file_out_}
377
378                # define CumulPeriod definition for this file
379                (( i__ = i+2 ))
380                eval SmoothDef=\${${ListFilesName}[$i__]}
381                IGCM_debug_Print 3 "  ${file_in} ${SmoothDef}"
382                aux=$( IGCM_SmoothModulo ${SmoothDef} ${CumulPeriod} )
383                j=1
384                for val in ${aux} ; do
385                    [ ${j} -eq 1 ] && SmoothMin=${val}
386                    [ ${j} -eq 2 ] && SmoothMax=${val}
387                    [ ${j} -eq 3 ] && ret=${val}
388                    (( j=j+1 ))
389                done
390                [ ${SmoothMax} -eq -1 ] && SmoothMax=${CumulPeriod}
391                if ( [ X${ret} = Xtrue ] || ( [ ${Period} -eq 1 ] && [ ${CumulPeriod} -ge ${SmoothMin} ] && [ ${CumulPeriod} -le ${SmoothMax} ] ) ) ; then
392                #if ( [ X${ret} = Xtrue ] || [ ${Period} -eq 1 ] ) ; then
393                    IGCM_sys_Get ${file_in} ${file_out}
394                    #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
395                fi
396                (( i=i+3 ))
397            done
398        fi
399    done
400   
401    IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
402}
403
404#=======================================================================
405function IGCM_comp_GetInputBoundaryFiles
406{
407    IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
408
409    # Debug Print :
410    echo
411    IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles"
412    echo
413
414    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
415    typeset file_in_ file_in file_out_ file_out
416
417    if [ ${Period} = 1 ]; then
418        ListFixBoundary=" "
419    fi
420
421    for comp in ${config_ListOfComponents[*]} ; do
422
423        # Define component
424        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
425        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
426
427        # Debug Print :
428        IGCM_debug_Print 3 "Boundary files ${compname}"
429
430        card=${SUBMIT_DIR}/COMP/${compname}.card
431
432        IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
433        ListFilesName=${compname}_BoundaryFiles_List
434        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
435
436        if [ X${FileName0} != X${NULL_STR} ] ; then
437            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
438
439            (( i=0 ))
440            until [ $i -ge $NbFiles ]; do
441                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
442                eval file_in=${file_in_}
443                (( i_ = i+1 ))
444                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
445                eval file_out=${file_out_}
446
447                IGCM_sys_Get ${file_in} ${file_out}
448                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
449
450                (( i=i+2 ))
451            done
452        fi
453
454        # Get non deleted files
455        if [ ${Period} = 1 ]; then
456
457            IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
458            ListFilesName=${compname}_BoundaryFiles_ListNonDel
459            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
460           
461            if [ X${FileName0} != X${NULL_STR} ] ; then
462                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
463               
464                (( i=0 ))
465                until [ $i -ge $NbFiles ]; do
466                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
467                    eval file_in=${file_in_}
468                    (( i_ = i+1 ))
469                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
470                    eval file_out=${file_out_}
471
472                    IGCM_sys_Get ${file_in} ${file_out}
473
474                    if [ X${file_out} != X. ] ; then
475                        ListFixBoundary=${ListFixBoundary}" "${file_out}
476                    else
477                        ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
478                    fi
479
480                    (( i=i+2 ))
481                done
482            fi
483        fi
484    done
485   
486    IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
487}
488
489#=======================================================================
490function IGCM_comp_DelFixeBoundaryFiles
491{
492    IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
493
494    # Debug Print :
495    echo
496    IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles"
497    echo
498
499    ls -l ${ListFixBoundary}
500    rm -f ${ListFixBoundary}
501
502    IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
503}
504
505#=======================================================================
506function IGCM_comp_GetInputParametersFiles
507{
508    IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
509
510    # Debug Print :
511    echo
512    IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles"
513    echo
514
515    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
516    for comp in ${config_ListOfComponents[*]} ; do
517        # Define component
518        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
519        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
520
521        # Debug Print :
522        IGCM_debug_Print 3 "Parameters ${compname}"
523
524        card=${SUBMIT_DIR}/COMP/${compname}.card       
525
526        IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
527        ListFilesName=${compname}_ParametersFiles_List
528        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
529
530        if [ X${FileName0} != X${NULL_STR} ] ; then
531            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
532
533            (( i=0 ))
534            until [ $i -ge $NbFiles ]; do
535                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
536                eval file_in=${file_in_}
537                (( i_ = i+1 ))
538                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
539                eval file_out=${file_out_} 
540
541                IGCM_sys_Cp ${file_in} ${file_out} 
542                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
543
544                (( i=i+2 ))
545            done
546        fi
547    done
548
549    IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
550}
551
552#=======================================================================
553function IGCM_comp_GetInputRestartFiles
554{
555    IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
556
557    # Debug Print :
558    echo
559    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles"
560    echo
561
562    typeset Date_tmp Date_r Path_r do_start CompOldName Path_temp
563    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
564    typeset file_in file_out file_in_ file_out_ file_in_Name
565    typeset -Z4 j4
566
567    for comp in ${config_ListOfComponents[*]} ; do
568        # Define component
569        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
570        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
571        #
572        card=${SUBMIT_DIR}/COMP/${compname}.card
573        #
574        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
575        ListFilesName=${compname}_RestartFiles_List
576        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
577
578        # Debug Print :
579        IGCM_debug_Print 3 "restart ${compname}"
580
581        if ( ${FirstInitialize} ) ; then
582
583            if [ "${config_Restarts_OverRule}" = "y" ] ; then
584                eval config_${comp}_Restart="y"
585                eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
586                eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
587                eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
588                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
589                eval CompOldName=${comp}
590            else
591                # Read component Restarts parameters
592                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
593                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
594
595                if [ "${do_start}" = "y" ] ; then
596                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
597                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
598                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
599                else
600                    eval config_${comp}_RestartDate=-1
601                    eval config_${comp}_RestartJobName=${NULL_STR}
602                    eval config_${comp}_RestartPath=${NULL_STR}
603                fi
604                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} OldName
605                eval CompOldName=\${config_${comp}_OldName}
606                if [ X${CompOldName} = X ] ; then
607                    eval CompOldName=${comp}
608                fi
609            fi
610
611            if [ "${do_start}" = "y" ] ; then
612
613                if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
614                    eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
615
616                    (( i=1 ))
617                    until [ $i -gt $NbFiles ]; do
618                        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
619                        eval file_in=${file_in_}
620
621                        (( i_ = i+1 ))
622                        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
623                        eval file_out=${file_out_}
624                       
625                        eval Date_tmp=\${config_${comp}_RestartDate}
626                        Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
627                        eval Path_r=\${config_${comp}_RestartPath}/\${config_${comp}_RestartJobName}/${CompOldName}/Restart
628                        eval file_in_Name=\${config_${comp}_RestartJobName}_${Date_r}_${file_in}
629
630                        generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
631                        generic_restart_file_name_out=$( basename ${file_out} .nc )
632                       
633                        eval Path_temp=\${Path_r}/${generic_restart_file_name_in}
634                        nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc)
635
636                        if [ ${nb_restart_file} -gt 1 ] ; then
637                            j=0
638                            until [ $j -ge $nb_restart_file ]; do
639                                j4=${j}
640                                eval IGCM_sys_Get ${Path_r}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
641                                #IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
642                                #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
643                                (( j=j+1 ))
644                            done
645                        else
646                            eval IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out} 
647                            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
648                        fi
649               
650                        (( i=i+3 ))
651                    done
652                else
653                    if [ X${FileName0} != XNONE ] ; then
654                        IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
655                    else
656                        IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
657                    fi
658                fi
659            fi
660        elif [ ${Period} -eq 1 ] ; then
661            # if not FirstInitialize and first loop of this job
662
663            # Restore Restarts files
664            #-----------------------
665            if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
666                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
667
668                (( i=1 ))
669                until [ $i -gt $NbFiles ]; do
670                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
671                    eval file_in=${file_in_}
672                    (( i_ = i+1 ))
673                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
674                    eval file_out=${file_out_}
675                   
676                    file_in_Name=${run_Configuration_OldPrefix}_${file_in}
677
678                    generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
679                    generic_restart_file_name_out=$( basename ${file_out} .nc )
680
681                    eval Path_temp=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
682                    nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc)
683
684                    if [ ${nb_restart_file} -gt 1 ] ; then
685                        j=0
686                        until [ $j -ge $nb_restart_file ]; do
687                            j4=${j}
688                            eval IGCM_sys_Get \${R_OUT_${comp}_R}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
689                            #IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
690                            #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
691
692                            (( j=j+1 ))
693                        done
694                    else
695                        eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
696                        #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
697                    fi
698
699                    (( i=i+3 ))
700                done
701            else
702                if [ X${FileName0} != XNONE ] ; then
703                    IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
704                else
705                    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
706                fi
707            fi
708        fi
709    done
710
711    typeset NbFichs
712    NbFiles=$( ls * 2> /dev/null | wc -l )
713    if [ ${NbFiles} -gt 0 ] ; then
714        IGCM_sys_Chmod u+rw *
715    fi
716
717    IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
718}
719
720#=======================================================================
721function IGCM_comp_PeriodStart
722{
723    IGCM_debug_PushStack "IGCM_comp_PeriodStart"
724
725    # Debug Print :
726    echo
727    IGCM_debug_Print 1 "IGCM_comp_PeriodStart"
728    echo
729
730    typeset ExeNameIn ExeNameOut
731    typeset comp compname comptagname
732    for comp in ${config_ListOfComponents[*]} ; do
733        # Define component
734        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
735        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
736
737        # Copy executable for this component
738        eval ExeNameIn=\${config_Executable_${comp}[0]}
739        eval ExeNameOut=\${config_Executable_${comp}[1]}
740
741        # Debug Print
742        IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
743        # UPDATE component
744        ${comp}_PeriodStart 2> /dev/null
745
746    done
747
748    IGCM_debug_PopStack "IGCM_comp_PeriodStart"
749}
750
751#=======================================================================
752function IGCM_comp_Update
753{
754    IGCM_debug_PushStack "IGCM_comp_Update"
755
756    # Debug Print :
757    echo
758    IGCM_debug_Print 1 "IGCM_comp_Update"
759    echo
760
761    typeset ExeNameIn ExeNameOut
762    typeset comp compname comptagname
763    for comp in ${config_ListOfComponents[*]} ; do
764        # Define component
765        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
766        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
767
768        # Copy executable for this component
769        eval ExeNameIn=\${config_Executable_${comp}[0]}
770        eval ExeNameOut=\${config_Executable_${comp}[1]}
771
772        # If missing executable then stop!
773        #if [ ! X${ExeNameIn} = X ] && [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
774        #    IGCM_debug_Exit "IGCM_comp_Update missing executable ${ExeNameIn}"
775        #fi
776
777        if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
778            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
779            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
780                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
781            fi
782        elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
783            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
784            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
785                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
786            fi
787        fi
788
789        # Debug Print
790        IGCM_debug_Print 1 "Update ${compname} Parameter Files."
791        # UPDATE component
792        ${comp}_Update
793
794    done
795
796    IGCM_debug_PopStack "IGCM_comp_Update"
797}
798
799#=======================================================================
800function IGCM_comp_Finalize
801{
802    IGCM_debug_PushStack "IGCM_comp_Finalize"
803
804    # Debug Print :
805    echo
806    IGCM_debug_Print 1 "IGCM_comp_Finalize"
807    echo
808
809    typeset ListTextName TextName0
810    typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
811    typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
812    typeset -Z4 j4
813    typeset list_file nlist_file
814    typeset compactoutputs
815
816    compactoutputs=false
817    if [ X${JobType} != XRUN ] ; then
818        compactoutputs=true
819    elif [ X${config_UserChoices_CompactText} != Xn ] ; then
820        compactoutputs=true
821    fi
822
823    for comp in ${config_ListOfComponents[*]} ; do
824        # Define component
825        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
826        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
827
828        # Debug Print
829        IGCM_debug_Print 1 "Finalize ${compname} component."
830        # FINALIZE component
831        ${comp}_Finalize
832
833        card=${SUBMIT_DIR}/COMP/${compname}.card       
834
835        # Save Restarts files
836        #--------------------
837        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
838        ListFilesName=${compname}_RestartFiles_List
839        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
840       
841        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
842            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
843           
844            (( i=0 ))
845            until [ $i -ge $NbFiles ]; do
846                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
847                eval file_in=${file_in_}
848
849                (( i_ = i+1 ))
850                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
851                eval file_out=${file_out_}
852
853                (( i_ = i+2 ))
854                eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
855                eval file_outin=${file_outin_}
856
857                generic_restart_file_name_in=$(    basename ${file_in} .nc )
858                generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
859                generic_restart_file_name_outin=$( basename ${file_outin} .nc )
860                       
861                nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l ) 
862                if [ ${nb_restart_file} -gt 1 ] ; then
863                    j=0
864                    until [ $j -ge $nb_restart_file ]; do
865                        j4=${j}
866                        eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
867                        if [ ! ${file_in} = ${file_outin} ] ; then
868                            if ( ${ExitFlag} ) ; then
869                                echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
870                            else
871                                IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
872                            fi
873                        fi
874                        #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_in}_${j4}.nc" > /dev/null 2>&1
875                        (( j=j+1 ))
876                    done
877                else
878                    eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
879                    if [ ! ${file_in} = ${file_outin} ] ; then
880                        if ( ${ExitFlag} ) ; then
881                            echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
882                        else
883                            IGCM_sys_Mv ${file_in} ${file_outin}
884                        fi
885                    fi
886                    #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
887                fi
888
889                (( i=i+3 ))
890            done
891        else
892            if [ X${FileName0} != XNONE ] ; then
893                IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
894            else
895                IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
896            fi
897        fi
898
899        # Save Output files
900        #------------------
901        IGCM_card_DefineArrayFromOption ${card} OutputFiles List
902        ListFilesName=${compname}_OutputFiles_List
903        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
904
905        if [ X${FileName0} != X${NULL_STR} ] ; then
906            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
907
908            (( i=0 ))
909            until [ $i -ge $NbFiles ]; do
910                SaveOnArchive=true
911                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
912                eval file_in=${file_in_}
913                (( i_ = i+1 ))
914                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
915                eval file_out=${file_out_}
916                (( i_ = i+2 ))
917                eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
918                #
919                generic_file_name=$( basename ${file_in} .nc )
920                nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
921                #
922                if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
923                    IGCM_debug_Print 2 "Parallelism with 1 process. Rebuilding ${file_in} not needed"
924                    IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
925                elif [ ${nb_rebuild_file} -gt 1 ] ; then
926                    IGCM_debug_Print 2 "Parallelism detected rebuilding ${file_in} is needed"
927                    if ( [ X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ X${config_Post_RebuildFrequency} = XNONE ] ) ; then
928                        IGCM_debug_Print 2 "Rebuilding ${file_in} online"
929                        IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
930                    else
931                        IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
932                        [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
933                        IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
934
935                        # Prepare headers for the shell dedicated to offline rebuild
936                        if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
937                            if [ $DRYRUN -le 1 ]; then
938                            echo "#!/bin/ksh                                          " > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
939                            echo "function IGCM_FlushRebuild                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
940                            echo "{                                                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
941                            echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
942                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
943                            echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
944                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
945                            echo "export R_SAVE=${R_SAVE}                             " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
946                            echo "export config_UserChoices_JobName=${config_UserChoices_JobName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
947                            fi
948                        fi
949                        # Prepare the shell dedicated to offline rebuild
950                        if [ $DRYRUN -le 1 ]; then
951                            echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
952                            echo "IGCM_debug_Verif_Exit_Post                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
953                        fi
954                        #
955                        # Load Patch we need to apply and apply
956                        if [ $DRYRUN -le 1 ]; then
957                            if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
958                                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
959                                    echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
960                                    echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
961                                    echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
962                                done
963                            fi
964                        fi
965                        #
966                        if [ $DRYRUN -le 1 ]; then
967                            echo "IGCM_sys_Put_Out ${file_in} ${file_out}                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
968                            echo "IGCM_debug_Verif_Exit_Post                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
969                            echo "IGCM_sys_Rm ${generic_file_name}_*.nc                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
970                        fi
971                        SaveOnArchive=false
972                    fi
973                fi
974                #
975                if [ ${SaveOnArchive} = true ] ; then
976                    #
977                    # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
978                    #
979                    thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
980                   
981                    if ( [ ! X${thereisapatch} =  X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = X ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
982                        if [ -f ${file_in} ] ; then
983                            [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
984
985                            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
986                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
987                            #
988                            if [ $DRYRUN -le 1 ]; then
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                                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
1000                                    echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh    " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1001                                    echo "IGCM_${Patch} ${file_in}                            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1002                                    echo "IGCM_debug_Verif_Exit_Post                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1003                                done
1004                                #
1005                                echo "IGCM_sys_Put_Out ${file_in} ${file_out}                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1006                                echo "IGCM_debug_Verif_Exit_Post                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1007                                #
1008                            fi
1009                        fi
1010                    else
1011                        [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1012                        if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
1013                            echo "#!/bin/ksh                                          " > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1014                            echo "function IGCM_FlushRebuild                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1015                            echo "{                                                   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1016                            echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1017                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1018                            echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1019                            echo "echo                                                " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1020                        fi
1021
1022                        IGCM_sys_Put_Out ${file_in} ${file_out}
1023                        [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1024                        if [ ${nb_rebuild_file} -gt 1 ] ; then
1025                            for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
1026                                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
1027                            done
1028                        fi
1029                    fi
1030                fi
1031                (( i=i+3 ))
1032            done
1033        fi
1034
1035        # Save Output Text files of models
1036        #---------------------------------
1037       
1038        IGCM_card_DefineArrayFromOption ${card} OutputText List
1039        ListTextName=${compname}_OutputText_List
1040       
1041        eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1042        if [ X${TextName0} != X${NULL_STR} ] ; then
1043            eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1044
1045            (( i=0 ))
1046            until [ $i -eq $NbFiles ]; do
1047                eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1048                (( i=i+1 ))
1049
1050                unset list_file
1051                #set +A list_file -- $( ls ${file_in}* | sort 2>/dev/null )
1052                set +A list_file -- $( for i in $(ls ${file_in}* 2>/dev/null | sed "s/${file_in}//" | sort -n) ; do ls ${file_in}$i ; done )
1053                nlist_file=${#list_file[@]}
1054                if [ ${nlist_file} -gt 1 ] ; then
1055                    if ( ${compactoutputs} ) ; then
1056                        eval file_out=${PREFIX}_${file_in}
1057
1058                        IGCM_debug_Print 2 "Parallelism of Text Output with ${nlist_file} files."
1059                        IGCM_debug_Print 2 "Compact files in ${file_out} : " ${list_file[*]}
1060                        echo ${list_file[*]} > ${file_out}
1061                        echo "" >> ${file_out}
1062                       
1063                        (( i_ = 0 ))
1064                        for file in ${list_file[@]}
1065                        do
1066                            echo "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " >> ${file_out}
1067                            echo "| " ${i_} " " ${file} >> ${file_out}
1068                            echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " >> ${file_out}
1069                            cat ${file} | sed "s/\(.*\)/${i_}\1/" ${file} >> ${file_out}
1070                            echo "" >> ${file_out}
1071                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1072                            (( i_ = i_ + 1 ))
1073                        done
1074                        eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}_D}/${file_out}
1075                        eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_out}" > /dev/null 2>&1
1076
1077                        if ( ${ExecutionFail} ) ; then
1078                            IGCM_sys_Cp ${file_out} ${SUBMIT_DIR}/Debug
1079                        fi
1080                    else
1081                        for file in ${list_file[@]}
1082                        do
1083                            eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
1084                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1085                        done
1086                        if ( ${ExecutionFail} ) ; then
1087                            IGCM_sys_Cp ${file} ${SUBMIT_DIR}/Debug/${PREFIX}_${file}
1088                        fi
1089                    fi
1090                else
1091                    if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1092                        eval IGCM_sys_Mv ${file_in}* ${file_in}
1093                    fi
1094                    eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${PREFIX}_${file_in}
1095                    [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1096
1097                    if ( ${ExecutionFail} ) ; then
1098                        IGCM_sys_Cp ${file_in} ${SUBMIT_DIR}/Debug/${PREFIX}_${file_in}
1099                    fi
1100                fi
1101            done
1102        fi
1103    done
1104
1105    IGCM_debug_PopStack "IGCM_comp_Finalize"
1106}
Note: See TracBrowser for help on using the repository browser.