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

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

MAF, SD : Correct mistake before saving restart

  • 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.8 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil@ipsl.jussieu.fr Martial.Mancip@ipsl.jussieu.fr
6# $Date$
7# $Author$
8# $Revision$
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11# History:
12# Modification:
13#
14#**************************************************************
15
16#========================================================================
17function IGCM_comp_Initialize
18{
19    IGCM_debug_PushStack "IGCM_comp_Initialize"
20
21    # Debug Print :
22    echo
23    IGCM_debug_Print 1 "IGCM_comp_Initialize :"
24    echo
25
26    typeset comp compname comptagname CompatibilityTag auxprint card_UserChoices first_option
27    for comp in ${config_ListOfComponents[*]} ; do
28        # Debug Print
29        IGCM_debug_Print 1 ${comp}
30        # Define component
31        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
32        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
33        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
34
35        # Read libIGCM compatibility version in ${compname}.card
36        card=${SUBMIT_DIR}/COMP/${compname}.card
37        IGCM_card_DefineVariableFromOption ${card} Compatibility libIGCM
38        eval CompatibilityTag=\${${compname}_Compatibility_libIGCM} > /dev/null 2>&1   
39
40        if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then
41            IGCM_debug_Exit "${compname}.card is not compatible with libIGCM version ${libIGCM_CurrentTag} see libIGCM FAQ http://wiki.ipsl.jussieu.fr/wiki_ipsl/IGCMG/libIGCM/DocUtilisateur/FAQ ."
42        fi
43
44        # Manage component executable
45        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card Executable ${comp}
46
47        # Read component Write Frequency in config.card
48        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} WriteFrequency
49        # Debug Print :
50        eval auxprint=\${config_${comp}_WriteFrequency}
51        IGCM_debug_Print 1 "Write frequency for ${compname} : ${auxprint} "
52        #2> /dev/null
53
54        # Debug Print :
55        IGCM_debug_Print 1 "Initialize following component library :"
56        IGCM_debug_Print 1 ${SUBMIT_DIR}/COMP/${compname}.driver
57        IGCM_debug_Print 3 "With tag : ${comptagname}"
58        # Source component library
59        . ${SUBMIT_DIR}/COMP/${compname}.driver
60
61        # Debug Print
62        IGCM_debug_Print 3 "Initialize ${comp} output directory."
63        # Define Dirs   
64        eval R_OUT_${comp}=${R_SAVE}/${comp}
65        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}}
66
67        eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output
68        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O}
69
70        eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart
71        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R}
72
73        eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug
74        eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D}
75
76        eval R_OUT_${comp}_O_I=\${R_OUT_${comp}_O}/INS
77        eval R_OUT_${comp}_O_H=\${R_OUT_${comp}_O}/HF
78        eval R_OUT_${comp}_O_D=\${R_OUT_${comp}_O}/DA
79        eval R_OUT_${comp}_O_M=\${R_OUT_${comp}_O}/MO
80        eval R_OUT_${comp}_O_Y=\${R_OUT_${comp}_O}/YE
81
82
83        # Read UserChoices section of component card
84        IGCM_debug_Print 1 "DefineArrayFromOption  : ${compname}_UserChoices ${card}"
85        IGCM_card_DefineArrayFromSection ${card} UserChoices
86        eval first_option=\${${compname}_UserChoices[0]} > /dev/null 2>&1
87        if [ X${first_option} != X"Error:" ] ; then
88            eval IGCM_debug_Print 2 "${compname}_UserChoices_Options:" \${${compname}_UserChoices[*]}
89            if [ X${card_UserChoices[0]} != X ] ; then
90                unset card_UserChoices
91            fi
92            eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1
93            typeset option
94            for option in ${card_UserChoices[*]} ; do
95                IGCM_card_DefineVariableFromOption ${card} UserChoices ${option}
96                eval IGCM_debug_Print 3 "${compname}_UserChoices_values: ${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                        nb_restart_file=$(IGCM_sys_Nb_files_archive ${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                    IGCM_sys_Nb_files_archive ${Path_temp}_????.nc
485                    nb_restart_file=$(IGCM_sys_Nb_files_archive ${Path_temp}_????.nc)
486                    IGCM_debug_Print 1 "nb_restart_file=${nb_restart_file}"
487                    if [ ${nb_restart_file} -gt 1 ] ; then
488                        j=0
489                        until [ $j -ge $nb_restart_file ]; do
490                            j4=${j}
491                            eval IGCM_sys_Get \${R_OUT_${comp}_R}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
492                            IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
493                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
494
495                            (( j=j+1 ))
496                        done
497                    else
498                        eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
499                        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
500                    fi
501
502                    (( i=i+3 ))
503                done
504            else
505                if [ X${FileName0} != XNONE ] ; then
506                    IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
507                else
508                    IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
509                fi
510            fi
511        fi
512    done
513    IGCM_sys_Chmod -R u+rw .
514
515    IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
516}
517
518#=======================================================================
519function IGCM_comp_Update
520{
521    IGCM_debug_PushStack "IGCM_comp_Update"
522
523    # Debug Print :
524    echo
525    IGCM_debug_Print 1 "IGCM_comp_Update :"
526    echo
527
528    typeset ExeNameIn ExeNameOut
529    typeset comp compname comptagname
530    for comp in ${config_ListOfComponents[*]} ; do
531        # Define component
532        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
533        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
534
535        # Copy executable for this component
536        eval ExeNameIn=\${config_Executable_${comp}[0]}
537        eval ExeNameOut=\${config_Executable_${comp}[1]}
538        if [ -f ${R_EXE}/${ExeNameIn} ]  ; then
539            eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
540            if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
541                eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
542            fi
543        fi
544
545        # Debug Print
546        IGCM_debug_Print 3 "Update ${compname} Parameter Files."
547        # UPDATE component
548        ${comp}_Update
549
550    done
551
552    IGCM_debug_PopStack "IGCM_comp_Update"
553}
554
555#=======================================================================
556function IGCM_comp_Finalize
557{
558    IGCM_debug_PushStack "IGCM_comp_Finalize"
559
560    # Debug Print :
561    echo
562    IGCM_debug_Print 1 "IGCM_comp_Finalize :"
563    echo
564
565    typeset ListTextName TextName0
566    typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
567    typeset i i_ file_in file_in_ file_out file_out_ generic_file_name nb_rebuild_file
568    typeset -Z4 j4
569    for comp in ${config_ListOfComponents[*]} ; do
570        # Define component
571        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
572        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
573
574        # Debug Print
575        IGCM_debug_Print 1 "Finalize ${compname} component."
576        # FINALIZE component
577        ${comp}_Finalize
578
579        card=${SUBMIT_DIR}/COMP/${compname}.card       
580
581        # Save Restarts files
582        #--------------------
583        IGCM_card_DefineArrayFromOption ${card} RestartFiles List
584        ListFilesName=${compname}_RestartFiles_List
585        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
586       
587        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
588            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
589           
590            (( i=0 ))
591            until [ $i -ge $NbFiles ]; do
592                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
593                eval file_in=${file_in_}
594
595                (( i_ = i+1 ))
596                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
597                eval file_out=${file_out_}
598               
599                generic_restart_file_name_in=$( basename ${file_in} .nc )
600                generic_restart_file_name_out=$( basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
601                       
602                nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l ) 
603                if [ ${nb_restart_file} -gt 1 ] ; then
604                    j=0
605                    until [ $j -ge $nb_restart_file ]; do
606                        j4=${j}
607                        eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
608                        eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_in}_${j4}.nc" > /dev/null 2>&1
609                        (( j=j+1 ))
610                    done
611                else
612                    eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
613                    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
614                fi
615
616                (( i=i+3 ))
617            done
618        else
619            if [ X${FileName0} != XNONE ] ; then
620                IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
621            else
622                IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
623            fi
624        fi
625
626        # Save Output files
627        #------------------
628        IGCM_card_DefineArrayFromOption ${card} OutputFiles List
629        ListFilesName=${compname}_OutputFiles_List
630        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
631
632        if [ X${FileName0} != X${NULL_STR} ] ; then
633            eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
634
635            (( i=0 ))
636            until [ $i -ge $NbFiles ]; do
637                SaveOnArchive=true
638                eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
639                eval file_in=${file_in_}
640                (( i_ = i+1 ))
641                eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
642                eval file_out=${file_out_}
643                #
644                generic_file_name=$( basename ${file_in} .nc )
645                nb_rebuild_file=$( ls | grep "${generic_file_name}[_0-9]*.nc" | wc -l )
646                #
647                if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
648                    IGCM_debug_Print 2 "Parallelism with 1 process. Rebuilding ${file_in} not needed"
649                    IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
650                elif [ ${nb_rebuild_file} -gt 1 ] ; then
651                    IGCM_debug_Print 2 "Parallelism detected rebuilding ${file_in} is needed"
652                    if ( [ X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ X${config_Post_RebuildFrequency} = XNONE ] ) ; then
653                        IGCM_debug_Print 2 "Rebuilding ${file_in} online"
654                        IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
655                    else
656                        IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
657                        [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
658                        IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
659                        # Prepare headers for the shell dedicated to offline rebuild
660                        if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
661                            echo \#!/bin/ksh                               > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
662                            echo function IGCM_FlushRebuild               >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
663                            echo {                                        >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
664                            echo IGCM_debug_PushStack "IGCM_FlushRebuild" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
665                            echo echo                                     >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
666                            echo IGCM_debug_Print 1 "IGCM_FlushRebuild :" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
667                            echo echo                                     >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
668                        fi
669                        # Prepare the shell dedicated to offline rebuild
670                        echo IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
671                        echo IGCM_sys_Put_Out ${file_in} ${file_out}               >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
672                        echo IGCM_sys_Rm ${generic_file_name}_*.nc                 >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
673                        SaveOnArchive=false
674                    fi
675                fi
676                #
677                if [ ${SaveOnArchive} = true ] ; then
678                    IGCM_sys_Put_Out ${file_in} ${file_out}
679                    [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
680                    if [ ${nb_rebuild_file} -gt 1 ] ; then
681                        for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
682                            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
683                        done
684                    fi
685                fi
686                (( i=i+3 ))
687            done
688        fi
689
690        # Save Output Text files of models
691        #---------------------------------
692       
693        IGCM_card_DefineArrayFromOption ${card} OutputText List
694        ListTextName=${compname}_OutputText_List
695       
696        eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
697        if [ X${TextName0} != X${NULL_STR} ] ; then
698            eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
699
700            (( i=0 ))
701            until [ $i -eq $NbFiles ]; do
702                eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
703                (( i=i+1 ))
704
705                nb_text_file=$( ls ${file_in}* 2>/dev/null | wc -l )
706                if [ ${nb_text_file} -gt 1 ] ; then
707                    list_file=$( ls ${file_in}* )
708                    for file in ${list_file}
709                      do
710                      eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
711                      eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
712                    done
713                else
714                    if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
715                        eval IGCM_sys_Mv ${file_in}* ${file_in}
716                    fi
717                    eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${PREFIX}_${file_in}
718                    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
719                fi
720            done
721        fi
722    done
723
724    IGCM_debug_PopStack "IGCM_comp_Finalize"
725}
Note: See TracBrowser for help on using the repository browser.