source: tags/libIGCM_v1_3/libIGCM_comp/libIGCM_comp.ksh @ 1456

Last change on this file since 1456 was 100, checked in by sdipsl, 15 years ago

Bugfix when printing UserChoices? from component card

  • 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: 24.7 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil@ipsl.jussieu.fr Martial.Mancip@ipsl.jussieu.fr
6# $Date$
7# $Author$
8# $Revision$
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11# History:
12# Modification:
13#
14#**************************************************************
15
16#========================================================================
17function IGCM_comp_Initialize
18{
19    IGCM_debug_PushStack "IGCM_comp_Initialize"
20
21    # Debug Print :
22    echo
23    IGCM_debug_Print 1 "IGCM_comp_Initialize :"
24    echo
25
26    typeset comp compname comptagname CompatibilityTag auxprint card_UserChoices first_option
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#=======================================================================
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 Path_temp
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    typeset -Z4 j4
364
365    for comp in ${config_ListOfComponents[*]} ; do
366        # Define component
367        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
368        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
369
370        # Debug Print :
371        IGCM_debug_Print 3 "restart ${compname}"
372
373        card=${SUBMIT_DIR}/COMP/${compname}.card       
374
375        if ( ${FirstInitialize} ) ; then
376
377            if [ "${config_Restarts_OverRule}" = "y" ] ; then
378                eval config_${comp}_Restart="y"
379                eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
380                eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
381                eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
382                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
383                eval CompOldName=${comp}
384            else
385                # Read component Restarts parameters
386                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
387                eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
388
389                if [ "${do_start}" = "y" ] ; then
390                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
391                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
392                    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
393                else
394                    eval config_${comp}_RestartDate=-1
395                    eval config_${comp}_RestartJobName=${NULL_STR}
396                    eval config_${comp}_RestartPath=${NULL_STR}
397                fi
398                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} OldName
399                eval CompOldName=\${config_${comp}_OldName}
400                if [ X${CompOldName} = X ] ; then
401                    eval CompOldName=${comp}
402                fi
403            fi
404
405            if [ "${do_start}" = "y" ] ; then
406
407                IGCM_card_DefineArrayFromOption ${card} RestartFiles List
408                ListFilesName=${compname}_RestartFiles_List
409                eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
410               
411                if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
412                    eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
413
414                    (( i=1 ))
415                    until [ $i -gt $NbFiles ]; do
416                        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
417                        eval file_in=${file_in_}
418
419                        (( i_ = i+1 ))
420                        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
421                        eval file_out=${file_out_}
422                       
423                        eval Date_tmp=\${config_${comp}_RestartDate}
424                        Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
425                        eval Path_r=\${config_${comp}_RestartPath}/\${config_${comp}_RestartJobName}/${CompOldName}/Restart
426                        eval file_in_Name=\${config_${comp}_RestartJobName}_${Date_r}_${file_in}
427
428                        generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
429                        generic_restart_file_name_out=$( basename ${file_out} .nc )
430                       
431                        eval Path_temp=\${Path_r}/${generic_restart_file_name_in}
432                        nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc)
433
434                        if [ ${nb_restart_file} -gt 1 ] ; then
435                            j=0
436                            until [ $j -ge $nb_restart_file ]; do
437                                j4=${j}
438                                eval IGCM_sys_Get ${Path_r}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
439                                IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
440                                eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
441                                (( j=j+1 ))
442                            done
443                        else
444                            eval IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out} 
445                            IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
446                        fi
447               
448                        (( i=i+3 ))
449                    done
450                else
451                    if [ X${FileName0} != XNONE ] ; then
452                        IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
453                    else
454                        IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
455                    fi
456                fi
457            fi
458        else
459            # if not FirstInitialize
460
461            # Restore Restarts files
462            #-----------------------
463            IGCM_card_DefineArrayFromOption ${card} RestartFiles List
464            ListFilesName=${compname}_RestartFiles_List
465            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
466           
467            if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
468                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
469
470                (( i=1 ))
471                until [ $i -gt $NbFiles ]; do
472                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
473                    eval file_in=${file_in_}
474                    (( i_ = i+1 ))
475                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
476                    eval file_out=${file_out_}
477                   
478                    file_in_Name=${run_Configuration_OldPrefix}_${file_in}
479
480                    generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
481                    generic_restart_file_name_out=$( basename ${file_out} .nc )
482
483                    eval Path_temp=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
484                    nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc)
485
486                    if [ ${nb_restart_file} -gt 1 ] ; then
487                        j=0
488                        until [ $j -ge $nb_restart_file ]; do
489                            j4=${j}
490                            eval IGCM_sys_Get \${R_OUT_${comp}_R}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
491                            IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
492                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
493
494                            (( j=j+1 ))
495                        done
496                    else
497                        eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
498                        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
499                    fi
500
501                    (( i=i+3 ))
502                done
503            else
504                if [ X${FileName0} != XNONE ] ; then
505                    IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
506                else
507                    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
508                fi
509            fi
510        fi
511    done
512    IGCM_sys_Chmod u+rw *
513
514    IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
515}
516
517#=======================================================================
518function IGCM_comp_Update
519{
520    IGCM_debug_PushStack "IGCM_comp_Update"
521
522    # Debug Print :
523    echo
524    IGCM_debug_Print 1 "IGCM_comp_Update :"
525    echo
526
527    typeset ExeNameIn ExeNameOut
528    typeset comp compname comptagname
529    for comp in ${config_ListOfComponents[*]} ; do
530        # Define component
531        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
532        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
533
534        # Copy executable for this component
535        eval ExeNameIn=\${config_Executable_${comp}[0]}
536        eval ExeNameOut=\${config_Executable_${comp}[1]}
537        if [ -f ${R_EXE}/${ExeNameIn} ]  ; then
538            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
539            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
540                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
541            fi
542        fi
543
544        # Debug Print
545        IGCM_debug_Print 3 "Update ${compname} Parameter Files."
546        # UPDATE component
547        ${comp}_Update
548
549    done
550
551    IGCM_debug_PopStack "IGCM_comp_Update"
552}
553
554#=======================================================================
555function IGCM_comp_Finalize
556{
557    IGCM_debug_PushStack "IGCM_comp_Finalize"
558
559    # Debug Print :
560    echo
561    IGCM_debug_Print 1 "IGCM_comp_Finalize :"
562    echo
563
564    typeset ListTextName TextName0
565    typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
566    typeset i i_ file_in file_in_ file_out file_out_ generic_file_name nb_rebuild_file
567    typeset -Z4 j4
568    for comp in ${config_ListOfComponents[*]} ; do
569        # Define component
570        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
571        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
572
573        # Debug Print
574        IGCM_debug_Print 1 "Finalize ${compname} component."
575        # FINALIZE component
576        ${comp}_Finalize
577
578        card=${SUBMIT_DIR}/COMP/${compname}.card       
579
580        # Save Restarts files
581        #--------------------
582        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
583        ListFilesName=${compname}_RestartFiles_List
584        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
585       
586        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
587            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
588           
589            (( i=0 ))
590            until [ $i -ge $NbFiles ]; do
591                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
592                eval file_in=${file_in_}
593
594                (( i_ = i+1 ))
595                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
596                eval file_out=${file_out_}
597               
598                generic_restart_file_name_in=$( basename ${file_in} .nc )
599                generic_restart_file_name_out=$( basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
600                       
601                nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l ) 
602                if [ ${nb_restart_file} -gt 1 ] ; then
603                    j=0
604                    until [ $j -ge $nb_restart_file ]; do
605                        j4=${j}
606                        eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
607                        eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_in}_${j4}.nc" > /dev/null 2>&1
608                        (( j=j+1 ))
609                    done
610                else
611                    eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
612                    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
613                fi
614
615                (( i=i+3 ))
616            done
617        else
618            if [ X${FileName0} != XNONE ] ; then
619                IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
620            else
621                IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
622            fi
623        fi
624
625        # Save Output files
626        #------------------
627        IGCM_card_DefineArrayFromOption ${card} OutputFiles List
628        ListFilesName=${compname}_OutputFiles_List
629        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
630
631        if [ X${FileName0} != X${NULL_STR} ] ; then
632            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
633
634            (( i=0 ))
635            until [ $i -ge $NbFiles ]; do
636                SaveOnArchive=true
637                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
638                eval file_in=${file_in_}
639                (( i_ = i+1 ))
640                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
641                eval file_out=${file_out_}
642                #
643                generic_file_name=$( basename ${file_in} .nc )
644                nb_rebuild_file=$( ls | grep "^${generic_file_name}[_0-9]*.nc" | wc -l )
645                #
646                if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
647                    IGCM_debug_Print 2 "Parallelism with 1 process. Rebuilding ${file_in} not needed"
648                    IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
649                elif [ ${nb_rebuild_file} -gt 1 ] ; then
650                    IGCM_debug_Print 2 "Parallelism detected rebuilding ${file_in} is needed"
651                    if ( [ X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ X${config_Post_RebuildFrequency} = XNONE ] ) ; then
652                        IGCM_debug_Print 2 "Rebuilding ${file_in} online"
653                        IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
654                    else
655                        IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
656                        [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
657                        IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
658                        # Prepare headers for the shell dedicated to offline rebuild
659                        if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
660                            echo \#!/bin/ksh                               > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
661                            echo function IGCM_FlushRebuild               >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
662                            echo {                                        >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
663                            echo IGCM_debug_PushStack "IGCM_FlushRebuild" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
664                            echo echo                                     >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
665                            echo IGCM_debug_Print 1 "IGCM_FlushRebuild"   >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
666                            echo echo                                     >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
667                        fi
668                        # Prepare the shell dedicated to offline rebuild
669                        echo IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
670                        echo IGCM_sys_Put_Out ${file_in} ${file_out}               >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
671                        echo IGCM_sys_Rm ${generic_file_name}_*.nc                 >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
672                        SaveOnArchive=false
673                    fi
674                fi
675                #
676                if [ ${SaveOnArchive} = true ] ; then
677                    IGCM_sys_Put_Out ${file_in} ${file_out}
678                    [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
679                    if [ ${nb_rebuild_file} -gt 1 ] ; then
680                        for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
681                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
682                        done
683                    fi
684                fi
685                (( i=i+3 ))
686            done
687        fi
688
689        # Save Output Text files of models
690        #---------------------------------
691       
692        IGCM_card_DefineArrayFromOption ${card} OutputText List
693        ListTextName=${compname}_OutputText_List
694       
695        eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
696        if [ X${TextName0} != X${NULL_STR} ] ; then
697            eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
698
699            (( i=0 ))
700            until [ $i -eq $NbFiles ]; do
701                eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
702                (( i=i+1 ))
703
704                nb_text_file=$( ls ${file_in}* 2>/dev/null | wc -l )
705                if [ ${nb_text_file} -gt 1 ] ; then
706                    list_file=$( ls ${file_in}* )
707                    for file in ${list_file}
708                      do
709                      eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
710                      eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
711                    done
712                else
713                    if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
714                        eval IGCM_sys_Mv ${file_in}* ${file_in}
715                    fi
716                    eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${PREFIX}_${file_in}
717                    [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
718                fi
719            done
720        fi
721    done
722
723    IGCM_debug_PopStack "IGCM_comp_Finalize"
724}
Note: See TracBrowser for help on using the repository browser.