source: branches/SmoothFiles/libIGCM_comp/libIGCM_comp.ksh @ 8

Last change on this file since 8 was 8, checked in by mmaipsl, 16 years ago

MM: Add SmoothFiles? with last commit (r6) corrections.

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Date Author Revision
File size: 23.8 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil@ipsl.jussieu.fr Martial.Mancip@ipsl.jussieu.fr
6# $Date$
7# $Author$
8# $Revision$
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11# History:
12# Modification:
13#
14#**************************************************************
15
16#========================================================================
17function IGCM_comp_Initialize
18{
19    IGCM_debug_PushStack "IGCM_comp_Initialize"
20
21    # Debug Print :
22    echo
23    IGCM_debug_Print 1 "IGCM_comp_Initialize :"
24    echo
25
26    typeset comp compname comptagname CompatibilityTag auxprint card_UserChoices first_option
27    for comp in ${config_ListOfComponents[*]} ; do
28        # Debug Print
29        IGCM_debug_Print 1 ${comp}
30        # Define component
31        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
32        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
33        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
34
35        # Read libIGCM compatibility version in ${compname}.card
36        card=${SUBMIT_DIR}/COMP/${compname}.card
37        IGCM_card_DefineVariableFromOption ${card} Compatibility libIGCM
38        eval CompatibilityTag=\${${compname}_Compatibility_libIGCM} > /dev/null 2>&1   
39
40        if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then
41            IGCM_debug_Exit "${compname}.card is not compatible with libIGCM version ${libIGCM_CurrentTag} see libIGCM FAQ http://wiki.ipsl.jussieu.fr/wiki_ipsl/IGCMG/libIGCM/DocUtilisateur/FAQ ."
42        fi
43
44        # Manage component executable
45        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card Executable ${comp}
46
47        # Read component Write Frequency in config.card
48        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} WriteFrequency
49        # Debug Print :
50        eval auxprint=\${config_${comp}_WriteFrequency}
51        IGCM_debug_Print 1 "Write frequency for ${compname} : ${auxprint} "
52        #2> /dev/null
53
54        # Debug Print :
55        IGCM_debug_Print 1 "Initialize following component library :"
56        IGCM_debug_Print 1 ${SUBMIT_DIR}/COMP/${compname}.driver
57        IGCM_debug_Print 3 "With tag : ${comptagname}"
58        # Source component library
59        . ${SUBMIT_DIR}/COMP/${compname}.driver
60
61        # Debug Print
62        IGCM_debug_Print 3 "Initialize ${comp} output directory."
63        # Define Dirs   
64        eval R_OUT_${comp}=${R_SAVE}/${comp}
65        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}}
66
67        eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output
68        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O}
69
70        eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart
71        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R}
72
73        eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug
74        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D}
75
76        eval R_OUT_${comp}_O_I=\${R_OUT_${comp}_O}/INS
77        eval R_OUT_${comp}_O_H=\${R_OUT_${comp}_O}/HF
78        eval R_OUT_${comp}_O_D=\${R_OUT_${comp}_O}/DA
79        eval R_OUT_${comp}_O_M=\${R_OUT_${comp}_O}/MO
80        eval R_OUT_${comp}_O_Y=\${R_OUT_${comp}_O}/YE
81
82
83        # Read UserChoices section of component card
84        IGCM_debug_Print 1 "DefineArrayFromOption  : ${compname}_UserChoices ${card}"
85        IGCM_card_DefineArrayFromSection ${card} UserChoices
86        eval first_option=\${${compname}_UserChoices[0]} > /dev/null 2>&1
87        if [ X${first_option} != X"Error:" ] ; then
88            eval IGCM_debug_Print 2 "${compname}_UserChoices_Options:" \${${compname}_UserChoices[*]}
89            if [ X${card_UserChoices[0]} != X ] ; then
90                unset card_UserChoices
91            fi
92            eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1
93            typeset option
94            for option in ${card_UserChoices[*]} ; do
95                IGCM_card_DefineVariableFromOption ${card} UserChoices ${option}
96                eval IGCM_debug_Print 3 "${compname}_UserChoices_values: ${option} \${card_UserChoices_${option}}"
97            done
98        fi
99
100        # Debug Print
101        IGCM_debug_Print 3 "Initialize ${compname} with driver."
102        # INIT component
103        ${comp}_Initialize
104        echo
105    done
106    echo "-----"
107
108    echo
109    IGCM_debug_Print 1 "DefineArrayFromOption  : ListOfComponents"
110    IGCM_debug_PrintVariables 3 config_ListOfComponents
111
112    IGCM_debug_PopStack "IGCM_comp_Initialize"
113}
114
115#=======================================================================
116function IGCM_comp_PrepareDeletedFiles
117{
118    IGCM_debug_PushStack "IGCM_comp_PrepareDeletedFiles" $@
119   
120    if [ X${2} != X. ] ; then
121        eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${2} ) > /dev/null 2>&1
122    else
123        eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${1} ) > /dev/null 2>&1
124    fi
125
126    IGCM_debug_PopStack "IGCM_comp_PrepareDeletedFiles"
127}
128
129#=======================================================================
130function IGCM_comp_GetInputInitialStateFiles
131{
132    IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles"
133
134    # Debug Print :
135    echo
136    IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles :"
137    echo
138
139    # Only the first time step need InitialStateFiles
140    # otherwise it's BoundaryConditions
141    if ( ${FirstInitialize} ) ; then
142      typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
143      typeset file_in_ file_in file_out_ file_out do_init
144      for comp in ${config_ListOfComponents[*]} ; do
145          # Initialize
146          do_init="y"
147          # Do we need to bring initial state file for this component
148          if [ "${config_Restarts_OverRule}" = "y" ] ; then
149              eval do_init="n"
150          else
151              # Read component Restarts parameters
152              IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
153              eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
154              if [ "${do_start}" = "y" ] ; then
155                    do_init="n"
156              else
157                    do_init="y"
158              fi
159          fi
160
161          if [ "${do_init}" = "y" ] ; then
162              # Define component
163              eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
164              eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
165
166              # Debug Print :
167              IGCM_debug_Print 3 "Initialisation files ${compname}"
168
169              card=${SUBMIT_DIR}/COMP/${compname}.card
170
171              IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List
172              ListFilesName=${compname}_InitialStateFiles_List
173
174              eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
175              if [ X${FileName0} != X${NULL_STR} ] ; then
176                  eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
177
178                  (( i=0 ))
179                  until [ $i -ge $NbFiles ]; do
180                      eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
181                      eval file_in=${file_in_}
182                      (( i_ = i+1 ))
183                      eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
184                      eval file_out=${file_out_}
185                     
186                      IGCM_sys_Get ${file_in} ${file_out}
187
188                      IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
189
190                      (( i=i+2 ))
191                  done
192              fi
193          fi
194      done
195    fi
196    IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles"
197}
198
199#=======================================================================
200# Definition of Smooth modulo function
201# usage :
202# IGCM_SmoothModulo StringModulo value
203#
204# StringModulo : A string of min max and modulo like definition of Scilab vectors.
205# [min]:[modulo:][max]
206# where :
207# [] value are optionnals;
208# empty min equal 1
209# empty max equal infinity
210# modulo not given or empty equal 1
211# empty string or just ':' equal always.
212#
213# value : the value to test with the definition
214#
215# return : true(1)/false(0)
216function IGCM_SmoothModulo
217{
218    IGCM_debug_PushStack "IGCM_SmoothModulo"
219    typeset defVector ModValue
220
221    eval set +A defVector -- $( echo "${1}" | \
222        awk -F ':' '{print ($1 == "" ? 1 : $1) " " (NF==3 ? ($2 == "" ? 1 : $2) : 1) " " (NF==3 ? ($3 == "" ? -1 : $3) : ($2 == "" ? -1 : $2))}' )
223
224    # Test limits :
225    # ${defVector[0]} <= ${2} <= ${defVector[2]}
226    #                                      or ${defVector[2]} == -1
227    if ( [ ${2} -ge ${defVector[0]} ] && \
228         ( [ ${2} -le ${defVector[2]} ] || \
229           [ ${defVector[2]} -lt 0 ] ) ) ; then
230
231        # Test modulo
232        ModValue=$( expr \( ${2} - ${defVector[0]} \) % ${defVector[1]} )
233        if [ ${ModValue} -eq 0 ] ;  then
234            echo true
235            IGCM_debug_PopStack "IGCM_SmoothModulo"
236            return 1
237        else
238            echo false
239            IGCM_debug_PopStack "IGCM_SmoothModulo"
240            return 0
241        fi
242    else
243        echo false
244        IGCM_debug_PopStack "IGCM_SmoothModulo"
245        return 0
246    fi
247}
248
249#=======================================================================
250function IGCM_comp_GetInputSmoothFiles
251{
252    IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles"
253
254    # Debug Print :
255    echo
256    IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles :"
257    echo
258
259    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ i__
260    typeset file_in_ file_in file_out_ file_out ret SmoothDef
261
262    for comp in ${config_ListOfComponents[*]} ; do
263
264        echo "-----"
265        # Define component
266        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
267        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
268
269        # Debug Print :
270        IGCM_debug_Print 3 "Smooth files ${compname}"
271
272        card=${SUBMIT_DIR}/COMP/${compname}.card
273
274        IGCM_card_DefineArrayFromOption ${card} SmoothFiles List
275        ListFilesName=${compname}_SmoothFiles_List
276        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
277
278        if [ X${FileName0} != X${NULL_STR} ] ; then
279            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
280
281            (( i=0 ))
282            until [ $i -ge $NbFiles ]; do
283
284                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
285                eval file_in=${file_in_}
286                (( i_ = i+1 ))
287                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
288                eval file_out=${file_out_}
289
290                # define CumulPeriod definition for this file
291                (( i__ = i+2 ))
292                eval SmoothDef=\${${ListFilesName}[$i__]}
293                IGCM_debug_Print 3 "  ${file_in} ${SmoothDef}"
294                eval ret=$( IGCM_SmoothModulo ${SmoothDef} ${CumulPeriod} )
295                if [ X${ret} = Xtrue ] ; then
296                    IGCM_sys_Get ${file_in} ${file_out}
297
298                    IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
299                fi
300                (( i=i+3 ))
301            done
302        fi
303    done
304   
305    IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
306}
307
308#=======================================================================
309function IGCM_comp_GetInputBoundaryFiles
310{
311    IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
312
313    # Debug Print :
314    echo
315    IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles :"
316    echo
317
318    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
319    typeset file_in_ file_in file_out_ file_out
320
321    if [ ${Period} = 1 ]; then
322        ListFixBoundary=" "
323    fi
324
325    for comp in ${config_ListOfComponents[*]} ; do
326
327        echo "-----"
328        # Define component
329        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
330        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
331
332        # Debug Print :
333        IGCM_debug_Print 3 "Boundary files ${compname}"
334
335        card=${SUBMIT_DIR}/COMP/${compname}.card
336
337        IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
338        ListFilesName=${compname}_BoundaryFiles_List
339        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
340
341        if [ X${FileName0} != X${NULL_STR} ] ; then
342            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
343
344            (( i=0 ))
345            until [ $i -ge $NbFiles ]; do
346                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
347                eval file_in=${file_in_}
348                (( i_ = i+1 ))
349                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
350                eval file_out=${file_out_}
351
352                IGCM_sys_Get ${file_in} ${file_out}
353
354                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
355
356                (( i=i+2 ))
357            done
358        fi
359
360        # Get non deleted files
361        if [ ${Period} = 1 ]; then
362
363            IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
364            ListFilesName=${compname}_BoundaryFiles_ListNonDel
365            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
366           
367            if [ X${FileName0} != X${NULL_STR} ] ; 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                    IGCM_sys_Get ${file_in} ${file_out}
379
380                    if [ X${file_out} != X. ] ; then
381                        ListFixBoundary=${ListFixBoundary}" "${file_out}
382                    else
383                        ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
384                    fi
385
386                    (( i=i+2 ))
387                done
388            fi
389        fi
390    done
391   
392    IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
393}
394
395#=======================================================================
396function IGCM_comp_DelFixeBoundaryFiles
397{
398    IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
399
400    # Debug Print :
401    echo
402    IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles :"
403    echo
404
405    ls -l ${ListFixBoundary}
406    rm -f ${ListFixBoundary}
407
408    IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
409}
410
411#=======================================================================
412function IGCM_comp_GetInputParametersFiles
413{
414    IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
415
416    # Debug Print :
417    echo
418    IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles :"
419    echo
420
421    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
422    for comp in ${config_ListOfComponents[*]} ; do
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 "Parameters ${compname}"
429
430        card=${SUBMIT_DIR}/COMP/${compname}.card       
431
432        IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
433        ListFilesName=${compname}_ParametersFiles_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_Cp ${file_in} ${file_out} 
448
449                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
450
451                (( i=i+2 ))
452            done
453        fi
454    done
455
456    IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
457}
458
459#=======================================================================
460function IGCM_comp_GetInputRestartFiles
461{
462    IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
463
464    # Debug Print :
465    echo
466    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles :"
467    echo
468
469    typeset Date_tmp Date_r Path_r do_start CompOldName
470    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
471    typeset file_in file_out file_in_ file_out_ file_in_Name
472
473    for comp in ${config_ListOfComponents[*]} ; do
474        # Define component
475        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
476        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
477
478        # Debug Print :
479        IGCM_debug_Print 3 "restart ${compname}"
480
481        card=${SUBMIT_DIR}/COMP/${compname}.card       
482
483        if ( ${FirstInitialize} ) ; then
484
485            if [ "${config_Restarts_OverRule}" = "y" ] ; then
486                eval config_${comp}_Restart="y"
487                eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
488                eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
489                eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
490                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
491                eval CompOldName=${comp}
492            else
493                # Read component Restarts parameters
494                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
495                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
496
497                if [ "${do_start}" = "y" ] ; then
498                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
499                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
500                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
501                else
502                    eval config_${comp}_RestartDate=-1
503                    eval config_${comp}_RestartJobName=${NULL_STR}
504                    eval config_${comp}_RestartPath=${NULL_STR}
505                fi
506                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} OldName
507                eval CompOldName=\${config_${comp}_OldName}
508                if [ X${CompOldName} = X ] ; then
509                    eval CompOldName=${comp}
510                fi
511            fi
512
513            if [ "${do_start}" = "y" ] ; then
514
515                IGCM_card_DefineArrayFromOption ${card} RestartFiles List
516                ListFilesName=${compname}_RestartFiles_List
517                eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
518               
519                if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
520                    eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
521
522                    (( i=1 ))
523                    until [ $i -gt $NbFiles ]; do
524                        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
525                        eval file_in=${file_in_}
526
527                        (( i_ = i+1 ))
528                        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
529                        eval file_out=${file_out_}
530                       
531                        eval Date_tmp=\${config_${comp}_RestartDate}
532                        Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
533                        eval Path_r=\${config_${comp}_RestartPath}/\${config_${comp}_RestartJobName}/${CompOldName}/Restart
534                        eval file_in_Name=\${config_${comp}_RestartJobName}_${Date_r}_${file_in}
535
536                        eval IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out} 
537
538                        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
539               
540                        (( i=i+3 ))
541                    done
542                else
543                    if [ X${FileName0} != XNONE ] ; then
544                        IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
545                    else
546                        IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
547                    fi
548                fi
549            fi
550        else
551            # if not FirstInitialize
552
553            # Restore Restarts files
554            #-----------------------
555            IGCM_card_DefineArrayFromOption ${card} RestartFiles List
556            ListFilesName=${compname}_RestartFiles_List
557            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
558           
559            if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
560                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
561
562                (( i=1 ))
563                until [ $i -gt $NbFiles ]; do
564                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
565                    eval file_in=${file_in_}
566                    (( i_ = i+1 ))
567                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
568                    eval file_out=${file_out_}
569                   
570                    file_in_Name=${run_Configuration_OldPrefix}_${file_in}
571                    eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
572
573                    IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
574
575                    (( i=i+3 ))
576                done
577            else
578                if [ X${FileName0} != XNONE ] ; then
579                    IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
580                else
581                    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
582                fi
583            fi
584        fi
585    done
586    IGCM_sys_Chmod -R u+rw .
587
588    IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
589}
590
591#=======================================================================
592function IGCM_comp_Update
593{
594    IGCM_debug_PushStack "IGCM_comp_Update"
595
596    # Debug Print :
597    echo
598    IGCM_debug_Print 1 "IGCM_comp_Update :"
599    echo
600
601    typeset ExeNameIn ExeNameOut
602    typeset comp compname comptagname
603    for comp in ${config_ListOfComponents[*]} ; do
604        # Define component
605        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
606        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
607
608        # Copy executable for this component
609        eval ExeNameIn=\${config_Executable_${comp}[0]}
610        eval ExeNameOut=\${config_Executable_${comp}[1]}
611        if [ -f ${R_EXE}/${ExeNameIn} ]  ; then
612            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
613            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
614                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
615            fi
616        fi
617
618        # Debug Print
619        IGCM_debug_Print 3 "Update ${compname} Parameter Files."
620        # UPDATE component
621        ${comp}_Update
622
623    done
624
625    IGCM_debug_PopStack "IGCM_comp_Update"
626}
627
628#=======================================================================
629function IGCM_comp_Finalize
630{
631    IGCM_debug_PushStack "IGCM_comp_Finalize"
632
633    # Debug Print :
634    echo
635    IGCM_debug_Print 1 "IGCM_comp_Finalize :"
636    echo
637
638    typeset ListTextName TextName0
639    typeset comp compname comptagname card ListFilesName FileName0 NbFiles
640    typeset i i_ file_in file_in_ file_out file_out_ generic_file_name nb_rebuild_file
641    for comp in ${config_ListOfComponents[*]} ; do
642        # Define component
643        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
644        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
645
646        # Debug Print
647        IGCM_debug_Print 1 "Finalize ${compname} component."
648        # FINALIZE component
649        ${comp}_Finalize
650
651        card=${SUBMIT_DIR}/COMP/${compname}.card       
652
653        # Save Restarts files
654        #--------------------
655        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
656        ListFilesName=${compname}_RestartFiles_List
657        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
658       
659        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
660            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
661           
662            (( i=0 ))
663            until [ $i -ge $NbFiles ]; do
664                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
665                eval file_in=${file_in_}
666
667                (( i_ = i+1 ))
668                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
669                eval file_out=${file_out_}
670               
671                eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
672
673                eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
674
675                (( i=i+3 ))
676            done
677        else
678            if [ X${FileName0} != XNONE ] ; then
679                IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
680            else
681                IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
682            fi
683        fi
684
685        # Save Output files
686        #------------------
687        IGCM_card_DefineArrayFromOption ${card} OutputFiles List
688        ListFilesName=${compname}_OutputFiles_List
689        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
690
691        if [ X${FileName0} != X${NULL_STR} ] ; then
692            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
693
694            (( i=0 ))
695            until [ $i -ge $NbFiles ]; do
696                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
697                eval file_in=${file_in_}
698                (( i_ = i+1 ))
699                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
700                eval file_out=${file_out_}
701
702                generic_file_name=$( basename ${file_in} .nc )
703                nb_rebuild_file=$( ls | grep "${generic_file_name}[_0-9]*.nc" | wc -l )
704                if [ ${nb_rebuild_file} -gt 1 ] ; then
705                    IGCM_debug_Print 2 "Rebuilding  ${file_in}"
706                    IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
707                    # DEBUG Rebuild :
708                    #eval IGCM_sys_Cp ${generic_file_name}_*.nc \${R_OUT_${comp}_O_M}/
709                elif [ -f ${generic_file_name}_0000.nc ] ; then
710                    IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
711                fi
712
713                IGCM_sys_Put_Out ${file_in} ${file_out}
714                if [ $? -eq 0 ] ; then
715                    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
716                    if [ ${nb_rebuild_file} -gt 1 ] ; then
717                        eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( ls | grep "${generic_file_name}_[0-9]*.nc" ) > /dev/null 2>&1
718                    fi
719                fi
720                (( i=i+3 ))
721            done
722        fi
723
724        # Save Output Text files of models
725        #---------------------------------
726       
727        IGCM_card_DefineArrayFromOption ${card} OutputText List
728        ListTextName=${compname}_OutputText_List
729       
730        eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
731        if [ X${TextName0} != X${NULL_STR} ] ; then
732            eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
733
734            (( i=0 ))
735            until [ $i -eq $NbFiles ]; do
736                eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
737                (( i=i+1 ))
738
739                nb_text_file=$( ls ${file_in}* 2>/dev/null | wc -l )
740                if [ ${nb_text_file} -gt 1 ] ; then
741                    list_file=$( ls ${file_in}* )
742                    for file in ${list_file}
743                      do
744                      eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
745                      eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
746                    done
747                else
748                    if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
749                        eval IGCM_sys_Mv ${file_in}* ${file_in}
750                    fi
751                    eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${PREFIX}_${file_in}
752                    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
753                fi
754            done
755        fi
756    done
757
758    IGCM_debug_PopStack "IGCM_comp_Finalize"
759}
Note: See TracBrowser for help on using the repository browser.