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

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

SD : - Tweak IGCM_sys_RshArchive function for non IDRIS machine

  • Comment out parallel restart case / work only in parallel not in sequential
  • 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: 25.1 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 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#                       IGCM_sys_RshArchive ls ${Path_temp}_????.nc 2>/dev/null | wc -l
433#                       nb_restart_file=$( IGCM_sys_RshArchive ls ${Path_temp}_????.nc 2>/dev/null | wc -l )
434
435#                       if [ ${nb_restart_file} -gt 2 ] ; then
436#                           j=0
437#                           until [ $j -ge $nb_restart_file ]; do
438#                               j4=${j}
439#                               eval IGCM_sys_Get ${Path_r}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
440#                               IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
441#                               eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
442#                               (( j=j+1 ))
443#                           done
444#                       else
445                            eval IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out} 
446                            IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
447#                       fi
448               
449                        (( i=i+3 ))
450                    done
451                else
452                    if [ X${FileName0} != XNONE ] ; then
453                        IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
454                    else
455                        IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
456                    fi
457                fi
458            fi
459        else
460            # if not FirstInitialize
461
462            # Restore Restarts files
463            #-----------------------
464            IGCM_card_DefineArrayFromOption ${card} RestartFiles List
465            ListFilesName=${compname}_RestartFiles_List
466            eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
467           
468            if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
469                eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
470
471                (( i=1 ))
472                until [ $i -gt $NbFiles ]; do
473                    eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
474                    eval file_in=${file_in_}
475                    (( i_ = i+1 ))
476                    eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
477                    eval file_out=${file_out_}
478                   
479                    file_in_Name=${run_Configuration_OldPrefix}_${file_in}
480
481                    generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
482                    generic_restart_file_name_out=$( basename ${file_out} .nc )
483
484                    eval Path_temp=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
485                    IGCM_debug_Print 1 "TEST RshArchive"
486#                   IGCM_sys_RshArchive ls ${Path_temp}_????.nc 2>/dev/null | wc -l
487#                   nb_restart_file=$( IGCM_sys_RshArchive ls ${Path_temp}_????.nc 2>/dev/null | wc -l )
488#                   IGCM_debug_Print 1 "nb_restart_file=${nb_restart_file}"
489#                   if [ ${nb_restart_file} -gt 2 ] ; then
490#                       j=0
491#                       until [ $j -ge $nb_restart_file ]; do
492#                           j4=${j}
493#                           eval IGCM_sys_Get \${R_OUT_${comp}_R}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
494#                           IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
495#                           eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
496#
497#                           (( j=j+1 ))
498#                       done
499#                   else
500                        eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
501                        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
502#                   fi
503
504                    (( i=i+3 ))
505                done
506            else
507                if [ X${FileName0} != XNONE ] ; then
508                    IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
509                else
510                    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
511                fi
512            fi
513        fi
514    done
515    IGCM_sys_Chmod -R u+rw .
516
517    IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
518}
519
520#=======================================================================
521function IGCM_comp_Update
522{
523    IGCM_debug_PushStack "IGCM_comp_Update"
524
525    # Debug Print :
526    echo
527    IGCM_debug_Print 1 "IGCM_comp_Update :"
528    echo
529
530    typeset ExeNameIn ExeNameOut
531    typeset comp compname comptagname
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        # Copy executable for this component
538        eval ExeNameIn=\${config_Executable_${comp}[0]}
539        eval ExeNameOut=\${config_Executable_${comp}[1]}
540        if [ -f ${R_EXE}/${ExeNameIn} ]  ; then
541            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
542            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
543                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
544            fi
545        fi
546
547        # Debug Print
548        IGCM_debug_Print 3 "Update ${compname} Parameter Files."
549        # UPDATE component
550        ${comp}_Update
551
552    done
553
554    IGCM_debug_PopStack "IGCM_comp_Update"
555}
556
557#=======================================================================
558function IGCM_comp_Finalize
559{
560    IGCM_debug_PushStack "IGCM_comp_Finalize"
561
562    # Debug Print :
563    echo
564    IGCM_debug_Print 1 "IGCM_comp_Finalize :"
565    echo
566
567    typeset ListTextName TextName0
568    typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
569    typeset i i_ file_in file_in_ file_out file_out_ generic_file_name nb_rebuild_file
570    typeset -Z4 j4
571    for comp in ${config_ListOfComponents[*]} ; do
572        # Define component
573        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
574        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
575
576        # Debug Print
577        IGCM_debug_Print 1 "Finalize ${compname} component."
578        # FINALIZE component
579        ${comp}_Finalize
580
581        card=${SUBMIT_DIR}/COMP/${compname}.card       
582
583        # Save Restarts files
584        #--------------------
585        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
586        ListFilesName=${compname}_RestartFiles_List
587        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
588       
589        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
590            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
591           
592            (( i=0 ))
593            until [ $i -ge $NbFiles ]; do
594                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
595                eval file_in=${file_in_}
596
597                (( i_ = i+1 ))
598                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
599                eval file_out=${file_out_}
600               
601                generic_restart_file_name_in=$( basename ${file_in} .nc )
602                generic_restart_file_name_out=$( basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
603                       
604#               nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l )
605#               IGCM_debug_Print 1 "TEST RshArchive"
606#               IGCM_debug_Print 1 "nb_restart_file=${nb_restart_file}"
607#               if [ ${nb_restart_file} -gt 2 ] ; then
608#                   j=0
609#                   until [ $j -ge $nb_restart_file ]; do
610#                       j4=${j}
611#                       eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
612#                       eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_in}_${j4}.nc" > /dev/null 2>&1
613#                       (( j=j+1 ))
614#                   done
615#               else
616                    eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
617                    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
618#               fi
619
620                (( i=i+3 ))
621            done
622        else
623            if [ X${FileName0} != XNONE ] ; then
624                IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
625            else
626                IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
627            fi
628        fi
629
630        # Save Output files
631        #------------------
632        IGCM_card_DefineArrayFromOption ${card} OutputFiles List
633        ListFilesName=${compname}_OutputFiles_List
634        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
635
636        if [ X${FileName0} != X${NULL_STR} ] ; then
637            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
638
639            (( i=0 ))
640            until [ $i -ge $NbFiles ]; do
641                SaveOnArchive=true
642                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
643                eval file_in=${file_in_}
644                (( i_ = i+1 ))
645                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
646                eval file_out=${file_out_}
647                #
648                generic_file_name=$( basename ${file_in} .nc )
649                nb_rebuild_file=$( ls | grep "${generic_file_name}[_0-9]*.nc" | wc -l )
650                #
651                if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
652                    IGCM_debug_Print 2 "Parallelism with 1 process. Rebuilding ${file_in} not needed"
653                    IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
654                elif [ ${nb_rebuild_file} -gt 1 ] ; then
655                    IGCM_debug_Print 2 "Parallelism detected rebuilding ${file_in} is needed"
656                    if ( [ X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ X${config_Post_RebuildFrequency} = XNONE ] ) ; then
657                        IGCM_debug_Print 2 "Rebuilding ${file_in} online"
658                        IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
659                    else
660                        IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
661                        [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
662                        IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
663                        # Prepare headers for the shell dedicated to offline rebuild
664                        if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
665                            echo \#!/bin/ksh                               > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
666                            echo function IGCM_FlushRebuild               >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
667                            echo {                                        >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
668                            echo IGCM_debug_PushStack "IGCM_FlushRebuild" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
669                            echo echo                                     >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
670                            echo IGCM_debug_Print 1 "IGCM_FlushRebuild :" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
671                            echo echo                                     >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
672                        fi
673                        # Prepare the shell dedicated to offline rebuild
674                        echo IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
675                        echo IGCM_sys_Put_Out ${file_in} ${file_out}               >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
676                        echo IGCM_sys_Rm ${generic_file_name}_*.nc                 >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
677                        SaveOnArchive=false
678                    fi
679                fi
680                #
681                if [ ${SaveOnArchive} = true ] ; then
682                    IGCM_sys_Put_Out ${file_in} ${file_out}
683                    [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
684                    if [ ${nb_rebuild_file} -gt 1 ] ; then
685                        for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
686                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
687                        done
688                    fi
689                fi
690                (( i=i+3 ))
691            done
692        fi
693
694        # Save Output Text files of models
695        #---------------------------------
696       
697        IGCM_card_DefineArrayFromOption ${card} OutputText List
698        ListTextName=${compname}_OutputText_List
699       
700        eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
701        if [ X${TextName0} != X${NULL_STR} ] ; then
702            eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
703
704            (( i=0 ))
705            until [ $i -eq $NbFiles ]; do
706                eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
707                (( i=i+1 ))
708
709                nb_text_file=$( ls ${file_in}* 2>/dev/null | wc -l )
710                if [ ${nb_text_file} -gt 1 ] ; then
711                    list_file=$( ls ${file_in}* )
712                    for file in ${list_file}
713                      do
714                      eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
715                      eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
716                    done
717                else
718                    if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
719                        eval IGCM_sys_Mv ${file_in}* ${file_in}
720                    fi
721                    eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${PREFIX}_${file_in}
722                    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
723                fi
724            done
725        fi
726    done
727
728    IGCM_debug_PopStack "IGCM_comp_Finalize"
729}
Note: See TracBrowser for help on using the repository browser.