source: tags/libIGCM_v1_1/libIGCM_comp/libIGCM_comp.ksh @ 1137

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

MM: correct Date, Author and Revision svn properties.

  • 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: 20.6 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: ${card_UserChoices[*]}"
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#=======================================================================
200function IGCM_comp_GetInputBoundaryFiles
201{
202    IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
203
204    # Debug Print :
205    echo
206    IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles :"
207    echo
208
209    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
210    typeset file_in_ file_in file_out_ file_out
211
212    if [ ${Period} = 1 ]; then
213        ListFixBoundary=" "
214    fi
215
216    for comp in ${config_ListOfComponents[*]} ; do
217
218        echo "-----"
219        # Define component
220        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
221        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
222
223        # Debug Print :
224        IGCM_debug_Print 3 "Boundary files ${compname}"
225
226        card=${SUBMIT_DIR}/COMP/${compname}.card
227
228        IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
229        ListFilesName=${compname}_BoundaryFiles_List
230        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
231
232        if [ X${FileName0} != X${NULL_STR} ] ; then
233            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
234
235            (( i=0 ))
236            until [ $i -ge $NbFiles ]; do
237                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
238                eval file_in=${file_in_}
239                (( i_ = i+1 ))
240                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
241                eval file_out=${file_out_}
242
243                IGCM_sys_Get ${file_in} ${file_out}
244
245                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
246
247                (( i=i+2 ))
248            done
249        fi
250
251        # Get non deleted files
252        if [ ${Period} = 1 ]; then
253
254            IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
255            ListFilesName=${compname}_BoundaryFiles_ListNonDel
256            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
257           
258            if [ X${FileName0} != X${NULL_STR} ] ; then
259                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
260               
261                (( i=0 ))
262                until [ $i -ge $NbFiles ]; do
263                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
264                    eval file_in=${file_in_}
265                    (( i_ = i+1 ))
266                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
267                    eval file_out=${file_out_}
268
269                    IGCM_sys_Get ${file_in} ${file_out}
270
271                    if [ X${file_out} != X. ] ; then
272                        ListFixBoundary=${ListFixBoundary}" "${file_out}
273                    else
274                        ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
275                    fi
276
277                    (( i=i+2 ))
278                done
279            fi
280        fi
281    done
282   
283    IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
284}
285
286#=======================================================================
287function IGCM_comp_DelFixeBoundaryFiles
288{
289    IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
290
291    # Debug Print :
292    echo
293    IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles :"
294    echo
295
296    ls -l ${ListFixBoundary}
297    rm -f ${ListFixBoundary}
298
299    IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
300}
301
302#=======================================================================
303function IGCM_comp_GetInputParametersFiles
304{
305    IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
306
307    # Debug Print :
308    echo
309    IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles :"
310    echo
311
312    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
313    for comp in ${config_ListOfComponents[*]} ; do
314        # Define component
315        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
316        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
317
318        # Debug Print :
319        IGCM_debug_Print 3 "Parameters ${compname}"
320
321        card=${SUBMIT_DIR}/COMP/${compname}.card       
322
323        IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
324        ListFilesName=${compname}_ParametersFiles_List
325        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
326
327        if [ X${FileName0} != X${NULL_STR} ] ; then
328            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
329
330            (( i=0 ))
331            until [ $i -ge $NbFiles ]; do
332                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
333                eval file_in=${file_in_}
334                (( i_ = i+1 ))
335                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
336                eval file_out=${file_out_} 
337
338                IGCM_sys_Cp ${file_in} ${file_out} 
339
340                IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
341
342                (( i=i+2 ))
343            done
344        fi
345    done
346
347    IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
348}
349
350#=======================================================================
351function IGCM_comp_GetInputRestartFiles
352{
353    IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
354
355    # Debug Print :
356    echo
357    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles :"
358    echo
359
360    typeset Date_tmp Date_r Path_r do_start CompOldName
361    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
362    typeset file_in file_out file_in_ file_out_ file_in_Name
363
364    for comp in ${config_ListOfComponents[*]} ; do
365        # Define component
366        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
367        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
368
369        # Debug Print :
370        IGCM_debug_Print 3 "restart ${compname}"
371
372        card=${SUBMIT_DIR}/COMP/${compname}.card       
373
374        if ( ${FirstInitialize} ) ; then
375
376            if [ "${config_Restarts_OverRule}" = "y" ] ; then
377                eval config_${comp}_Restart="y"
378                eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
379                eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
380                eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
381                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
382                eval CompOldName=${comp}
383            else
384                # Read component Restarts parameters
385                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
386                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
387
388                if [ "${do_start}" = "y" ] ; then
389                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
390                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
391                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
392                else
393                    eval config_${comp}_RestartDate=-1
394                    eval config_${comp}_RestartJobName=${NULL_STR}
395                    eval config_${comp}_RestartPath=${NULL_STR}
396                fi
397                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} OldName
398                eval CompOldName=\${config_${comp}_OldName}
399                if [ X${CompOldName} = X ] ; then
400                    eval CompOldName=${comp}
401                fi
402            fi
403
404            if [ "${do_start}" = "y" ] ; then
405
406                IGCM_card_DefineArrayFromOption ${card} RestartFiles List
407                ListFilesName=${compname}_RestartFiles_List
408                eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
409               
410                if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
411                    eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
412
413                    (( i=1 ))
414                    until [ $i -gt $NbFiles ]; do
415                        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
416                        eval file_in=${file_in_}
417
418                        (( i_ = i+1 ))
419                        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
420                        eval file_out=${file_out_}
421                       
422                        eval Date_tmp=\${config_${comp}_RestartDate}
423                        Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
424                        eval Path_r=\${config_${comp}_RestartPath}/\${config_${comp}_RestartJobName}/${CompOldName}/Restart
425                        eval file_in_Name=\${config_${comp}_RestartJobName}_${Date_r}_${file_in}
426
427                        eval IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out} 
428
429                        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
430               
431                        (( i=i+3 ))
432                    done
433                else
434                    if [ X${FileName0} != XNONE ] ; then
435                        IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
436                    else
437                        IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
438                    fi
439                fi
440            fi
441        else
442            # if not FirstInitialize
443
444            # Restore Restarts files
445            #-----------------------
446            IGCM_card_DefineArrayFromOption ${card} RestartFiles List
447            ListFilesName=${compname}_RestartFiles_List
448            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
449           
450            if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
451                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
452
453                (( i=1 ))
454                until [ $i -gt $NbFiles ]; do
455                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
456                    eval file_in=${file_in_}
457                    (( i_ = i+1 ))
458                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
459                    eval file_out=${file_out_}
460                   
461                    file_in_Name=${run_Configuration_OldPrefix}_${file_in}
462                    eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
463
464                    IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
465
466                    (( i=i+3 ))
467                done
468            else
469                if [ X${FileName0} != XNONE ] ; then
470                    IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
471                else
472                    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
473                fi
474            fi
475        fi
476    done
477    IGCM_sys_Chmod -R u+rw .
478
479    IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
480}
481
482#=======================================================================
483function IGCM_comp_Update
484{
485    IGCM_debug_PushStack "IGCM_comp_Update"
486
487    # Debug Print :
488    echo
489    IGCM_debug_Print 1 "IGCM_comp_Update :"
490    echo
491
492    typeset ExeNameIn ExeNameOut
493    typeset comp compname comptagname
494    for comp in ${config_ListOfComponents[*]} ; do
495        # Define component
496        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
497        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
498
499        # Copy executable for this component
500        eval ExeNameIn=\${config_Executable_${comp}[0]}
501        eval ExeNameOut=\${config_Executable_${comp}[1]}
502        if [ -f ${R_EXE}/${ExeNameIn} ]  ; then
503            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
504            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
505                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
506            fi
507        fi
508
509        # Debug Print
510        IGCM_debug_Print 3 "Update ${compname} Parameter Files."
511        # UPDATE component
512        ${comp}_Update
513
514    done
515
516    IGCM_debug_PopStack "IGCM_comp_Update"
517}
518
519#=======================================================================
520function IGCM_comp_Finalize
521{
522    IGCM_debug_PushStack "IGCM_comp_Finalize"
523
524    # Debug Print :
525    echo
526    IGCM_debug_Print 1 "IGCM_comp_Finalize :"
527    echo
528
529    typeset ListTextName TextName0
530    typeset comp compname comptagname card ListFilesName FileName0 NbFiles
531    typeset i i_ file_in file_in_ file_out file_out_ generic_file_name nb_rebuild_file
532    for comp in ${config_ListOfComponents[*]} ; do
533        # Define component
534        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
535        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
536
537        # Debug Print
538        IGCM_debug_Print 1 "Finalize ${compname} component."
539        # FINALIZE component
540        ${comp}_Finalize
541
542        card=${SUBMIT_DIR}/COMP/${compname}.card       
543
544        # Save Restarts files
545        #--------------------
546        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
547        ListFilesName=${compname}_RestartFiles_List
548        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
549       
550        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
551            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
552           
553            (( i=0 ))
554            until [ $i -ge $NbFiles ]; do
555                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
556                eval file_in=${file_in_}
557
558                (( i_ = i+1 ))
559                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
560                eval file_out=${file_out_}
561               
562                eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
563
564                eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
565
566                (( i=i+3 ))
567            done
568        else
569            if [ X${FileName0} != XNONE ] ; then
570                IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
571            else
572                IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
573            fi
574        fi
575
576        # Save Output files
577        #------------------
578        IGCM_card_DefineArrayFromOption ${card} OutputFiles List
579        ListFilesName=${compname}_OutputFiles_List
580        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
581
582        if [ X${FileName0} != X${NULL_STR} ] ; then
583            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
584
585            (( i=0 ))
586            until [ $i -ge $NbFiles ]; do
587                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
588                eval file_in=${file_in_}
589                (( i_ = i+1 ))
590                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
591                eval file_out=${file_out_}
592
593                generic_file_name=$( basename ${file_in} .nc )
594                nb_rebuild_file=$( ls | grep "${generic_file_name}[_0-9]*.nc" | wc -l )
595                if [ ${nb_rebuild_file} -gt 1 ] ; then
596                    IGCM_debug_Print 2 "Rebuilding  ${file_in}"
597                    IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
598                    # DEBUG Rebuild :
599                    #eval IGCM_sys_Cp ${generic_file_name}_*.nc \${R_OUT_${comp}_O_M}/
600                elif [ -f ${generic_file_name}_0000.nc ] ; then
601                    IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
602                fi
603
604                IGCM_sys_Put_Out ${file_in} ${file_out}
605                if [ $? -eq 0 ] ; then
606                    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
607                    if [ ${nb_rebuild_file} -gt 1 ] ; then
608                        eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( ls | grep "${generic_file_name}_[0-9]*.nc" ) > /dev/null 2>&1
609                    fi
610                fi
611                (( i=i+3 ))
612            done
613        fi
614
615        # Save Output Text files of models
616        #---------------------------------
617       
618        IGCM_card_DefineArrayFromOption ${card} OutputText List
619        ListTextName=${compname}_OutputText_List
620       
621        eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
622        if [ X${TextName0} != X${NULL_STR} ] ; then
623            eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
624
625            (( i=0 ))
626            until [ $i -eq $NbFiles ]; do
627                eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
628                (( i=i+1 ))
629
630                nb_text_file=$( ls ${file_in}* 2>/dev/null | wc -l )
631                if [ ${nb_text_file} -gt 1 ] ; then
632                    list_file=$( ls ${file_in}* )
633                    for file in ${list_file}
634                      do
635                      eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
636                      eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
637                    done
638                else
639                    if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
640                        eval IGCM_sys_Mv ${file_in}* ${file_in}
641                    fi
642                    eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${PREFIX}_${file_in}
643                    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
644                fi
645            done
646        fi
647    done
648
649    IGCM_debug_PopStack "IGCM_comp_Finalize"
650}
Note: See TracBrowser for help on using the repository browser.