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

Last change on this file since 809 was 809, checked in by sdipsl, 11 years ago

Activate IGCM_sys_Chmod from DRYRUN=3 and add BoundaryFiles? list in FileToBeDeleted list at each Period.
Whitespace cleanup (from emacs macro) on libIGCM_sys_iitm.ksh
see #105

  • 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 Revision Author Date
File size: 52.5 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#========================================================================
15function IGCM_comp_Initialize
16{
17  IGCM_debug_PushStack "IGCM_comp_Initialize"
18
19  # Debug Print :
20  echo
21  IGCM_debug_Print 1 "IGCM_comp_Initialize"
22  echo
23
24  typeset comp compname comptagname CompatibilityTag auxprint card_UserChoices first_option option i j
25  for comp in ${config_ListOfComponents[*]} ; do
26
27    # Define component
28    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
29    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
30    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
31
32    # Debug Print
33    IGCM_debug_Print 1 "Initialize ${comp} : ${compname} component."
34
35    # Read libIGCM compatibility version in ${compname}.card
36    card=${SUBMIT_DIR}/COMP/${compname}.card
37    IGCM_card_DefineVariableFromOption ${card} Compatibility libIGCM
38
39    eval CompatibilityTag=\${${compname}_Compatibility_libIGCM} > /dev/null 2>&1
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 2 "Initialize following component library"
56
57    # Source drivers in directory DRIVER if it exist
58    # else source them from directory COMP
59    if [ -d ${SUBMIT_DIR}/DRIVER ] ; then
60      IGCM_debug_Print 2 ${SUBMIT_DIR}/DRIVER/${compname}.driver
61      # Source component library
62      . ${SUBMIT_DIR}/DRIVER/${compname}.driver
63    else
64      IGCM_debug_Print 2 ${SUBMIT_DIR}/COMP/${compname}.driver
65      # Source component library
66      . ${SUBMIT_DIR}/COMP/${compname}.driver
67    fi
68    IGCM_debug_Print 3 "With tag : ${comptagname}"
69
70    # Debug Print
71    IGCM_debug_Print 3 "Initialize ${comp} output directory."
72
73    # Define ARCHIVED Dirs
74    eval R_OUT_${comp}=${R_SAVE}/${comp}
75    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}}
76
77    eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output
78    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O}
79
80    eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart
81    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R}
82
83    eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug
84    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D}
85
86    eval R_OUT_${comp}_O_I=\${R_OUT_${comp}_O}/INS
87    eval R_OUT_${comp}_O_H=\${R_OUT_${comp}_O}/HF
88    eval R_OUT_${comp}_O_D=\${R_OUT_${comp}_O}/DA
89    eval R_OUT_${comp}_O_M=\${R_OUT_${comp}_O}/MO
90    eval R_OUT_${comp}_O_Y=\${R_OUT_${comp}_O}/YE
91
92    # Define BUFFERED Dirs
93    if [ ! ${config_Post_PackFrequency} = NONE ] ; then
94      eval R_BUF_${comp}=${R_BUFR}/${comp}
95      eval IGCM_sys_Mkdir \${R_BUF_${comp}}
96
97      eval R_BUF_${comp}_O=\${R_BUF_${comp}}/Output
98      eval IGCM_sys_Mkdir \${R_BUF_${comp}_O}
99
100      eval R_BUF_${comp}_R=\${R_BUF_${comp}}/Restart
101      eval IGCM_sys_Mkdir \${R_BUF_${comp}_R}
102
103      eval R_BUF_${comp}_D=\${R_BUF_${comp}}/Debug
104      eval IGCM_sys_Mkdir \${R_BUF_${comp}_D}
105
106      eval R_BUF_${comp}_O_I=\${R_BUF_${comp}_O}/INS
107      eval R_BUF_${comp}_O_H=\${R_BUF_${comp}_O}/HF
108      eval R_BUF_${comp}_O_D=\${R_BUF_${comp}_O}/DA
109      eval R_BUF_${comp}_O_M=\${R_BUF_${comp}_O}/MO
110      eval R_BUF_${comp}_O_Y=\${R_BUF_${comp}_O}/YE
111    fi
112
113    # Read UserChoices section of component card
114    IGCM_debug_Print 2 "DefineArrayFromSection : ${compname}_UserChoices ${card}"
115    IGCM_card_DefineArrayFromSection ${card} UserChoices
116    eval first_option=\${${compname}_UserChoices[0]} > /dev/null 2>&1
117
118    # If section is not empty we define corresponding variables
119    if [ X${first_option} != X"Error:" ] ; then
120      if [ X${card_UserChoices[0]} != X ] ; then
121        unset card_UserChoices
122      fi
123      eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1
124      IGCM_debug_Print 3 "${compname}_UserChoices_values:"
125      for option in ${card_UserChoices[*]} ; do
126        IGCM_card_DefineVariableFromOption ${card} UserChoices ${option}
127        eval IGCM_debug_Print 3 "${option}=\${${compname}_UserChoices_${option}}"
128      done
129    fi
130
131    # Read and Build Output File stuff
132    IGCM_debug_Print 2 "DefineArrayFromOption  : ${compname}_OutputFiles ${card}"
133    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
134    ListFilesName=${compname}_OutputFiles_List
135    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
136    #
137    if [ X${FileName0} != X${NULL_STR} ] ; then
138      #
139      #IGCM_debug_Print 1 "Component      : ${compname}"
140      #
141      # INITIALISATION
142      #
143      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
144      #
145      i=2
146      #
147      until [ $i -ge $NbFiles ]; do
148        #
149        eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
150        #
151        if [ X${flag_post} != XNONE ] ; then
152          #
153          # First of all
154          #
155          IGCM_card_DefineArrayFromSection ${card} ${flag_post}
156          #
157          # Seasonal case : If option Seasonal is not found (old cards) put SEASONAL ON by default
158          #
159          # variable option allready typeset above
160          for option in $( eval echo \${${compname}_${flag_post}[*]} ) ; do
161            if [ ${option} = Seasonal ] ; then
162              FoundSeasonal=true
163              IGCM_card_DefineVariableFromOption ${card} ${flag_post} Seasonal
164            fi
165          done
166          #
167          if [ ! X${FoundSeasonal} = Xtrue ] ; then
168            eval ${compname}_${flag_post}_Seasonal=ON
169          fi
170          #
171          if [ $( eval echo \${${compname}_${flag_post}_Seasonal} ) = ON ] ; then
172            Seasonal=true
173          fi
174
175          # Dimension = vide si vieille card.
176          IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars
177          IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches
178          if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not" ] ; then
179            # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob.
180            ListDimension[0]=2D
181            ListDimension[1]=3D
182            TimeSeries=false
183            iLoop=${#ListDimension[*]}
184            j=0
185            until [ $j -ge ${iLoop} ]; do
186              Dimension=${ListDimension[${j}]}
187              IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension}
188              IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension}
189              #
190              # Time series WITHOUT chunk
191              #
192              if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
193                if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then
194                  IGCM_debug_Print 3 "${Dimension} time series activated for ${flag_post}"
195                  eval TimeSeries${Dimension}=true
196                fi
197              fi
198              #
199              # Time series WITH chunk
200              #
201              if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
202                chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} )
203                if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
204                  IGCM_debug_Print 3 "${Dimension} time series activated with chunck for ${flag_post}"
205                  eval TimeSeriesChunck${Dimension}=true
206                  eval set +A CHUNCK${Dimension}_COMP \${CHUNCK${Dimension}_COMP[*]} ${comp}
207                  eval set +A CHUNCK${Dimension}_FLAG \${CHUNCK${Dimension}_FLAG[*]} ${i}
208                  eval set +A CHUNCK${Dimension}_NAME \${CHUNCK${Dimension}_NAME[*]} ${flag_post}
209                  eval set +A CHUNCK${Dimension}_SIZE \${CHUNCK${Dimension}_SIZE[*]} ${chunck_size}
210                fi
211              fi
212              (( j=j+1 ))
213            done
214          else
215            ListDimension[0]=""
216            TimeSeries=true
217            TimeSeries2D=false
218            TimeSeries3D=false
219            TimeSeriesChunck2D=false
220            TimeSeriesChunck3D=false
221          fi
222        fi
223        (( i=i+3 ))
224      done
225    fi
226    # Debug Print
227    IGCM_debug_Print 3 "Initialize ${compname} with driver."
228    # INIT component
229    ${comp}_Initialize
230    echo
231  done
232
233  IGCM_debug_PopStack "IGCM_comp_Initialize"
234}
235
236#=======================================================================
237function IGCM_comp_PrepareDeletedFiles
238{
239  IGCM_debug_PushStack "IGCM_comp_PrepareDeletedFiles" $@
240
241  if [ X${2} != X. ] ; then
242    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${2} ) > /dev/null 2>&1
243  else
244    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${1} ) > /dev/null 2>&1
245  fi
246
247  IGCM_debug_PopStack "IGCM_comp_PrepareDeletedFiles"
248}
249
250#=======================================================================
251function IGCM_comp_GetInputInitialStateFiles
252{
253  IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles"
254
255  # Debug Print :
256  echo
257  IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles"
258  echo
259
260  # Only the first time step need InitialStateFiles
261  # otherwise it's BoundaryConditions
262  if ( ${FirstInitialize} ) ; then
263    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
264    typeset file_in_ file_in file_out_ file_out do_init
265    for comp in ${config_ListOfComponents[*]} ; do
266      # Initialize
267      do_init="y"
268      # Do we need to bring initial state file for this component
269      if [ "${config_Restarts_OverRule}" = "y" ] ; then
270        eval do_init="n"
271      else
272        # Read component Restarts parameters
273        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
274        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
275        if [ "${do_start}" = "y" ] ; then
276          do_init="n"
277        else
278          do_init="y"
279        fi
280      fi
281
282      if [ "${do_init}" = "y" ] ; then
283        # Define component
284        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
285        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
286
287        # Debug Print :
288        IGCM_debug_Print 3 "Initialisation files ${compname}"
289
290        card=${SUBMIT_DIR}/COMP/${compname}.card
291
292        IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List
293        ListFilesName=${compname}_InitialStateFiles_List
294
295        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
296        if [ X${FileName0} != X${NULL_STR} ] ; then
297          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
298          (( i=0 ))
299          until [ $i -ge $NbFiles ]; do
300            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
301            eval file_in=${file_in_}
302            (( i_ = i+1 ))
303            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
304            eval file_out=${file_out_}
305
306            IGCM_sys_IsFileArchived ${file_in}
307            if [ $? = 0 ] ; then
308              IGCM_sys_Get ${file_in} ${file_out}
309              #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
310            else
311              IGCM_sys_Cp ${file_in} ${file_out}
312            fi
313            (( i=i+2 ))
314          done
315        fi
316      fi
317    done
318  fi
319  IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles"
320}
321
322#=======================================================================
323# Definition of Smooth modulo function
324# usage :
325# IGCM_SmoothModulo StringModulo value
326#
327# StringModulo : A string of min max and modulo like definition of Scilab vectors.
328# [min]:[modulo:][max]
329# where :
330# [] value are optionnals;
331# empty min equal 1
332# empty max equal infinity
333# modulo not given or empty equal 1
334# empty string or just ':' equal always.
335#
336# value : the value to test with the definition
337#
338# return : true(1)/false(0)
339function IGCM_SmoothModulo
340{
341  IGCM_debug_PushStack "IGCM_SmoothModulo"
342  typeset defVector ModValue
343
344  eval set +A defVector -- $( echo "${1}" | \
345    gawk -F ':' '{print ($1 == "" ? 1 : $1) " " (NF==3 ? ($2 == "" ? 1 : $2) : 1) " " (NF==3 ? ($3 == "" ? -1 : $3) : ($2 == "" ? -1 : $2))}' )
346
347  # Save Smooth Min and Max. Needed to call IGCM_sys_Get when appropriate
348  arr[1]=${defVector[0]}
349  arr[2]=${defVector[2]}
350
351  # Test limits :
352  # ${defVector[0]} <= ${2} <= ${defVector[2]}
353  #          or ${defVector[2]} == -1
354  if ( [ ${2} -ge ${defVector[0]} ] && ( [ ${2} -le ${defVector[2]} ] || [ ${defVector[2]} -lt 0 ] ) ) ; then
355    # Test modulo
356    ModValue=$( expr \( ${2} - ${defVector[0]} \) % ${defVector[1]} )
357    if [ ${ModValue} -eq 0 ] ;  then
358      arr[3]=true
359      echo ${arr[@]}
360      IGCM_debug_PopStack "IGCM_SmoothModulo"
361      return 1
362    else
363      arr[3]=false
364      echo ${arr[@]}
365      IGCM_debug_PopStack "IGCM_SmoothModulo"
366      return 0
367    fi
368  else
369    arr[3]=false
370    echo ${arr[@]}
371    IGCM_debug_PopStack "IGCM_SmoothModulo"
372    return 0
373  fi
374}
375
376#=======================================================================
377function IGCM_comp_GetInputSmoothFiles
378{
379  IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles"
380
381  # Debug Print :
382  echo
383  IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles"
384  echo
385
386  typeset comp compname comptagname card ListFilesName FileName0 NbFiles j i i_ i__
387  typeset file_in_ file_in file_out_ file_out ret SmoothDef aux val
388
389  for comp in ${config_ListOfComponents[*]} ; do
390    # Define component
391    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
392    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
393
394    # Debug Print :
395    IGCM_debug_Print 3 "Smooth files ${compname}"
396
397    card=${SUBMIT_DIR}/COMP/${compname}.card
398
399    IGCM_card_DefineArrayFromOption ${card} SmoothFiles List
400    ListFilesName=${compname}_SmoothFiles_List
401    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
402
403    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != X"Section" ] ) ; then
404      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
405
406      (( i=0 ))
407      until [ $i -ge $NbFiles ]; do
408        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
409        eval file_in=${file_in_}
410        (( i_ = i+1 ))
411        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
412        eval file_out=${file_out_}
413
414        # define CumulPeriod definition for this file
415        (( i__ = i+2 ))
416        eval SmoothDef=\${${ListFilesName}[$i__]}
417        IGCM_debug_Print 3 "  ${file_in} ${SmoothDef}"
418        aux=$( IGCM_SmoothModulo ${SmoothDef} ${CumulPeriod} )
419        j=1
420        for val in ${aux} ; do
421          [ ${j} -eq 1 ] && SmoothMin=${val}
422          [ ${j} -eq 2 ] && SmoothMax=${val}
423          [ ${j} -eq 3 ] && ret=${val}
424          (( j=j+1 ))
425        done
426        [ ${SmoothMax} -eq -1 ] && SmoothMax=${CumulPeriod}
427        if ( [ X${ret} = Xtrue ] || ( [ ${Period} -eq 1 ] && [ ${CumulPeriod} -ge ${SmoothMin} ] && [ ${CumulPeriod} -le ${SmoothMax} ] ) ) ; then
428
429          IGCM_sys_IsFileArchived ${file_in}
430          if [ $? = 0 ] ; then
431            IGCM_sys_Get ${file_in} ${file_out}
432            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
433          else
434            IGCM_sys_Cp ${file_in} ${file_out}
435          fi
436        fi
437        (( i=i+3 ))
438      done
439    fi
440  done
441
442  IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
443}
444
445#=======================================================================
446function IGCM_comp_GetInputBoundaryFiles
447{
448  IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
449
450  # Debug Print :
451  echo
452  IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles"
453  echo
454
455  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
456  typeset file_in_ file_in file_out_ file_out
457
458  if [ ${Period} = 1 ]; then
459    ListFixBoundary=" "
460  fi
461
462  for comp in ${config_ListOfComponents[*]} ; do
463
464    # Define component
465    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
466    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
467
468    # Debug Print :
469    IGCM_debug_Print 3 "Boundary files ${compname}"
470
471    card=${SUBMIT_DIR}/COMP/${compname}.card
472
473    IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
474    ListFilesName=${compname}_BoundaryFiles_List
475    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
476
477    if [ X${FileName0} != X${NULL_STR} ] ; then
478      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
479
480      (( i=0 ))
481      until [ $i -ge $NbFiles ]; do
482        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
483        eval file_in=${file_in_}
484        (( i_ = i+1 ))
485        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
486        eval file_out=${file_out_}
487
488        IGCM_sys_IsFileArchived ${file_in}
489        if [ $? = 0 ] ; then
490          IGCM_sys_Get ${file_in} ${file_out}
491          IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
492        else
493          IGCM_sys_Cp ${file_in} ${file_out}
494        fi
495
496        (( i=i+2 ))
497      done
498    fi
499
500    # Get non deleted files
501    if [ ${Period} = 1 ]; then
502
503      IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
504      ListFilesName=${compname}_BoundaryFiles_ListNonDel
505      eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
506
507      if [ X${FileName0} != X${NULL_STR} ] ; then
508        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
509
510        (( i=0 ))
511        until [ $i -ge $NbFiles ]; do
512          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
513          eval file_in=${file_in_}
514          (( i_ = i+1 ))
515          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
516          eval file_out=${file_out_}
517
518          IGCM_sys_IsFileArchived ${file_in}
519          if [ $? = 0 ] ; then
520            IGCM_sys_Get ${file_in} ${file_out}
521            #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
522          else
523            IGCM_sys_Cp ${file_in} ${file_out}
524          fi
525
526          if [ X${file_out} != X. ] ; then
527            ListFixBoundary=${ListFixBoundary}" "${file_out}
528          else
529            ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
530          fi
531
532          (( i=i+2 ))
533        done
534      fi
535    fi
536  done
537
538  IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
539}
540
541#=======================================================================
542function IGCM_comp_DelFixeBoundaryFiles
543{
544  IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
545
546  # Debug Print :
547  echo
548  IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles"
549  echo
550
551  ls -l ${ListFixBoundary}
552  rm -f ${ListFixBoundary}
553
554  IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
555}
556
557#=======================================================================
558function IGCM_comp_GetInputParametersFiles
559{
560  IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
561
562  # Debug Print :
563  echo
564  IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles"
565  echo
566
567  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
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 3 "Parameters ${compname}"
575
576    card=${SUBMIT_DIR}/COMP/${compname}.card
577
578    IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
579    ListFilesName=${compname}_ParametersFiles_List
580    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
581
582    if [ X${FileName0} != X${NULL_STR} ] ; then
583      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
584
585      (( i=0 ))
586      until [ $i -ge $NbFiles ]; do
587        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
588        eval file_in=${file_in_}
589        (( i_ = i+1 ))
590        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
591        eval file_out=${file_out_} 
592
593        IGCM_sys_Cp ${file_in} ${file_out} 
594        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
595
596        (( i=i+2 ))
597      done
598    fi
599  done
600
601  IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
602}
603
604#=======================================================================
605function IGCM_comp_GetInputRestartFiles
606{
607  IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
608
609  # Debug Print :
610  echo
611  IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles"
612  echo
613
614  typeset Date_tmp Date_r Path_r do_start CompOldName Path_OUT Path_BUF
615  typeset Buffered Archived Tared PotentialTarFile IsMatching TarFileFound
616  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
617  typeset file_in file_out file_in_ file_out_ file_in_Name
618  typeset -Z4 j4
619
620  IsMatching=""
621
622  for comp in ${config_ListOfComponents[*]} ; do
623    # Define component
624    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
625    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
626    #
627    card=${SUBMIT_DIR}/COMP/${compname}.card
628    #
629    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
630    ListFilesName=${compname}_RestartFiles_List
631    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
632
633    # Debug Print :
634    IGCM_debug_Print 3 "restart ${compname}"
635
636    if ( ${FirstInitialize} ) ; then
637
638      if [ "${config_Restarts_OverRule}" = "y" ] ; then
639        eval config_${comp}_Restart="y"
640        eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
641        eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
642        eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
643        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
644        eval CompOldName=${comp}
645      else
646        # Read component Restarts parameters
647        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
648        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
649
650        if [ "${do_start}" = "y" ] ; then
651          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
652          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
653          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
654        else
655          eval config_${comp}_RestartDate=-1
656          eval config_${comp}_RestartJobName=${NULL_STR}
657          eval config_${comp}_RestartPath=${NULL_STR}
658        fi
659        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} OldName
660        eval CompOldName=\${config_${comp}_OldName}
661        if [ X${CompOldName} = X ] ; then
662          eval CompOldName=${comp}
663        fi
664
665        # Reinitialize IsMatching to allow searching for a different tar file for each component.
666        IsMatching=""
667        TarFileFound=""
668      fi
669
670      if [ "${do_start}" = "y" ] ; then
671
672        # Restore Restarts files
673        #-----------------------
674        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
675          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
676
677          (( i=1 ))
678          until [ $i -gt $NbFiles ]; do
679            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
680            eval file_in=${file_in_}
681            (( i_ = i+1 ))
682            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
683            eval file_out=${file_out_}
684
685            eval Date_tmp=\${config_${comp}_RestartDate}
686            Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
687            # will be re-use
688            eval RestartPath=\${config_${comp}_RestartPath}
689            eval RestartJobName=\${config_${comp}_RestartJobName}
690            #
691            Path_r=${RestartPath}/${RestartJobName}/${CompOldName}/Restart
692            file_in_Name=${RestartJobName}_${Date_r}_${file_in}
693
694            extension_in=$( echo ${file_in_Name##*.} )
695            extension_out=$( echo ${file_out##*.} )
696
697            generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
698            generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
699
700            Path_OUT=${Path_r}/${generic_restart_file_name_in}
701
702            if [ $( IGCM_sys_TestFileBuffer ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
703              IGCM_debug_Print 3 "Buffered restart"
704              Buffered=true
705              Archived=false
706              Tared=false
707              nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_OUT}_????.${extension_in})
708            elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
709              IGCM_debug_Print 3 "Archived restart"
710              Buffered=false
711              Archived=true
712              Tared=false
713              nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
714            else
715              IGCM_debug_Print 3 "Tared restart"
716              Buffered=false
717              Archived=false
718              Tared=true
719              # Look after the tar file we want if we did not found it already
720              if [ X${IsMatching} = X ] ; then
721                for PotentialTarFile in $( IGCM_sys_RshArchive "find ${RestartPath}/${RestartJobName}/RESTART -name "${RestartJobName}_*_restart.tar" -print" ) ; do
722                  IsMatching=$( echo ${PotentialTarFile##*/} | \
723                        sed "s:^${RestartJobName}_::" | \
724                        sed "s:\.restart\.tar$::" | \
725                        gawk -F_ -v restartdate=${Date_r} \
726                             '{if (($1 < restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
727                  if [ ! X${IsMatching} = X ] ; then
728                    TarFileFound=${PotentialTarFile}
729                    break
730                  fi
731                done
732              fi
733              TarFileLocation=$( IGCM_sys_PrepareTaredRestart ${TarFileFound} )
734              IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
735              tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
736              nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
737            fi
738
739            if [ ${nb_restart_file} -gt 1 ] ; then
740              j=0
741              until [ $j -ge ${nb_restart_file} ]; do
742                j4=${j}
743                if [ X${Buffered} = Xtrue ] ; then
744                  IGCM_sys_GetBuffer ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
745                elif [ X${Archived} = Xtrue ] ; then
746                  IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
747                elif [ X${Tared} = Xtrue ] ; then
748                  IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
749                fi
750                (( j=j+1 ))
751              done
752
753              if [ X${NUM_PROC_OCE} != X ] ; then
754                if [ ${NUM_PROC_OCE} -ne ${nb_restart_file} ] ; then
755                  IGCM_sys_rebuild ${generic_restart_file_name_out}.${extension_out} ${generic_restart_file_name_out}_????.${extension_out}
756                  IGCM_sys_Rm ${generic_restart_file_name_out}_????.${extension_out}
757                fi
758              fi
759            else
760              if [ X${Buffered} = Xtrue ] ; then
761                IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
762              elif [ X${Archived} = Xtrue ] ; then
763                IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
764              elif [ X${Tared} = Xtrue ] ; then
765                IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
766              fi
767            fi
768            (( i=i+3 ))
769          done
770
771        else
772          if [ X${FileName0} != XNONE ] ; then
773            IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
774          else
775            IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
776          fi
777        fi
778      fi
779    elif [ ${Period} -eq 1 ] ; then
780      # if not FirstInitialize and first loop of this job
781
782      # Restore Restarts files
783      #-----------------------
784      if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
785        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
786
787        (( i=1 ))
788        until [ $i -gt $NbFiles ]; do
789          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
790          eval file_in=${file_in_}
791          (( i_ = i+1 ))
792          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
793          eval file_out=${file_out_}
794
795          file_in_Name=${run_Configuration_OldPrefix}_${file_in}
796
797          extension_in=$( echo ${file_in_Name##*.} )
798          extension_out=$( echo ${file_out##*.} )
799
800          generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
801          generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
802
803          eval Path_BUF=\${R_BUF_${comp}_R}/${generic_restart_file_name_in}
804          eval Path_OUT=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
805
806          if [ $( IGCM_sys_TestFileBuffer ${Path_BUF}*.${extension_in} ; echo $? ) = 0 ] ; then
807            IGCM_debug_Print 3 "Buffered restart"
808            Buffered=true
809            Archived=false
810            Tared=false
811            nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_BUF}_????.${extension_in})
812          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
813            IGCM_debug_Print 3 "Archived restart"
814            Buffered=false
815            Archived=true
816            Tared=false
817            nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
818          else
819            IGCM_debug_Print 3 "Tared restart"
820            Buffered=false
821            Archived=false
822            Tared=true
823            # Look after the tar file we want if we did not found it already
824            if [ X${IsMatching} = X ] ; then
825              for PotentialTarFile in $( IGCM_sys_RshArchive "find ${R_SAVE}/RESTART -name "${config_UserChoices_JobName}_*_restart.tar" -print" ) ; do
826                IsMatching=$( echo ${PotentialTarFile##*/} | sed "s:^${config_UserChoices_JobName}_::" | sed "s:\.restart\.tar$::" | gawk -F_ -v restartdate=${LastPeriodDateEnd} '{if (($1 < restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
827                if [ ! X${IsMatching} = X ] ; then
828                  TarFileFound=${PotentialTarFile}
829                  break
830                fi
831              done
832            fi
833            TarFileLocation=$( IGCM_sys_PrepareTaredRestart ${TarFileFound} )
834            IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
835            tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
836            nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
837          fi
838
839          if [ ${nb_restart_file} -gt 1 ] ; then
840            j=0
841            until [ $j -ge ${nb_restart_file} ]; do
842              j4=${j}
843              if [ X${Buffered} = Xtrue ] ; then
844                IGCM_sys_GetBuffer ${Path_BUF}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
845              elif [ X${Archived} = Xtrue ] ; then
846                IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
847              elif [ X${Tared} = Xtrue ] ; then
848                IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
849              fi
850              (( j=j+1 ))
851            done
852          else
853            if [ X${Buffered} = Xtrue ] ; then
854              eval IGCM_sys_GetBuffer \${R_BUF_${comp}_R}/${file_in_Name} ${file_out}
855            elif [ X${Archived} = Xtrue ] ; then
856              eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
857            elif [ X${Tared} = Xtrue ] ; then
858              IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
859            fi
860          fi
861          (( i=i+3 ))
862        done
863      else
864        if [ X${FileName0} != XNONE ] ; then
865          IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
866        else
867          IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
868        fi
869      fi
870    fi
871  done
872
873  NbFiles=$( ls * 2> /dev/null | wc -l )
874  if [ ${NbFiles} -gt 0 ] ; then
875    IGCM_sys_Chmod u+rw *
876  fi
877
878  IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
879}
880
881#=======================================================================
882function IGCM_comp_PeriodStart
883{
884  IGCM_debug_PushStack "IGCM_comp_PeriodStart"
885
886  # Debug Print :
887  echo
888  IGCM_debug_Print 1 "IGCM_comp_PeriodStart"
889  echo
890
891  typeset ExeNameIn ExeNameOut
892  typeset comp compname comptagname
893  for comp in ${config_ListOfComponents[*]} ; do
894    # Define component
895    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
896    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
897
898    # Copy executable for this component
899    eval ExeNameIn=\${config_Executable_${comp}[0]}
900    eval ExeNameOut=\${config_Executable_${comp}[1]}
901
902    # Debug Print
903    IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
904    # UPDATE component
905    ${comp}_PeriodStart 2> /dev/null
906
907  done
908
909  IGCM_debug_PopStack "IGCM_comp_PeriodStart"
910}
911
912#=======================================================================
913function IGCM_comp_Update
914{
915  IGCM_debug_PushStack "IGCM_comp_Update"
916
917    # Debug Print :
918  echo
919  IGCM_debug_Print 1 "IGCM_comp_Update"
920  echo
921
922  typeset ExeNameIn ExeNameOut
923  typeset comp compname comptagname
924  for comp in ${config_ListOfComponents[*]} ; do
925    # Define component
926    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
927    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
928
929    # Copy executable for this component
930    eval ExeNameIn=\${config_Executable_${comp}[0]}
931    eval ExeNameOut=\${config_Executable_${comp}[1]}
932
933    # If missing executable and DRYRUN is set to 0 or 1  then stop!
934    if [ ${DRYRUN} -le 1 ] && [ X${ExeNameIn} != X\"\" ] &&  [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
935      IGCM_debug_Exit "IGCM_comp_Update missing executable ${ExeNameIn}"
936    fi
937
938    if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
939      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
940      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
941        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
942      fi
943    elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
944      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
945      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
946        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
947      fi
948    fi
949
950    # Debug Print
951    IGCM_debug_Print 1 "Update ${compname} Parameter Files."
952    # UPDATE component
953    ${comp}_Update
954
955  done
956
957  IGCM_debug_PopStack "IGCM_comp_Update"
958}
959
960#=======================================================================
961function IGCM_comp_Finalize
962{
963  IGCM_debug_PushStack "IGCM_comp_Finalize"
964
965  # Debug Print :
966  echo
967  IGCM_debug_Print 1 "IGCM_comp_Finalize"
968  echo
969
970  typeset ListTextName TextName0
971  typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
972  typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
973  typeset -Z4 j4
974  typeset list_file nlist_file
975  typeset compactoutputs
976
977  compactoutputs=false
978  if [ X${JobType} != XRUN ] ; then
979    compactoutputs=true
980  elif [ X${config_UserChoices_CompactText} != Xn ] ; then
981    compactoutputs=true
982  fi
983
984  for comp in ${config_ListOfComponents[*]} ; do
985    # Define component
986    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
987    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
988
989    # Debug Print
990    IGCM_debug_Print 1 "Finalize ${comp} : ${compname} component."
991    # FINALIZE component
992    ${comp}_Finalize
993
994    card=${SUBMIT_DIR}/COMP/${compname}.card
995
996    # Save Output Text files of models
997    #---------------------------------
998    IGCM_debug_Print 2 "Save Output Text files for ${comp} : ${compname} component."
999    IGCM_card_DefineArrayFromOption ${card} OutputText List
1000    ListTextName=${compname}_OutputText_List
1001
1002    eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1003    if [ X${TextName0} != X${NULL_STR} ] ; then
1004      eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1005
1006      (( i=0 ))
1007      until [ $i -eq $NbFiles ]; do
1008        eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1009        eval file_out=${PREFIX}_${file_in}
1010
1011        (( i=i+1 ))
1012
1013        unset list_file
1014        #set +A list_file -- $( ls ${file_in}* | sort 2>/dev/null )
1015        # result for a a1 a10 a2 with file_in=a a a1 a2 a10
1016        set +A list_file -- $( [ -f ${file_in} ] && ls ${file_in} ; for i in $(ls ${file_in}* 2>/dev/null | sed "s/${file_in}//" | sort -n) ; do ls ${file_in}$i ; done )
1017        nlist_file=${#list_file[@]}
1018        if [ ${nlist_file} -gt 1 ] ; then
1019          if ( ${compactoutputs} ) ; then
1020            IGCM_debug_Print 2 "Parallelism of Text Output with ${nlist_file} files."
1021            IGCM_debug_Print 2 "Compact files in ${file_out} : " ${list_file[*]}
1022            echo ${list_file[*]} > ${file_out}
1023            echo "" >> ${file_out}
1024
1025            (( i_ = 0 ))
1026            for file in ${list_file[@]}
1027            do
1028              echo "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " >> ${file_out}
1029              echo "| " ${i_} " " ${file} >> ${file_out}
1030              echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " >> ${file_out}
1031              cat ${file} | sed "s/\(.*\)/${i_}\1/" ${file} >> ${file_out}
1032              echo "" >> ${file_out}
1033              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1034                  (( i_ = i_ + 1 ))
1035            done
1036            if [ X${Pack} = Xtrue ] ; then
1037              eval IGCM_sys_PutBuffer_Out ${file_out} \${R_BUF_${comp}_D}/${file_out}
1038            else
1039              eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}_D}/${file_out}
1040            fi
1041            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_out}" > /dev/null 2>&1
1042
1043            if ( ${ExecutionFail} ) ; then
1044              IGCM_sys_Cp ${file_out} ${SUBMIT_DIR}/Debug
1045            fi
1046          else
1047            for file in ${list_file[@]}
1048            do
1049              if [ X${Pack} = Xtrue ] ; then
1050                eval IGCM_sys_PutBuffer_Out ${file} \${R_BUF_${comp}_D}/${PREFIX}_${file}
1051              else
1052                eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
1053              fi
1054              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1055
1056              if ( ${ExecutionFail} ) ; then
1057                IGCM_sys_Cp ${file} ${SUBMIT_DIR}/Debug/${PREFIX}_${file}
1058              fi
1059            done
1060          fi
1061        else
1062          if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1063            eval IGCM_sys_Mv ${file_in}* ${file_in}
1064          fi
1065          if [ X${Pack} = Xtrue ] ; then
1066            eval IGCM_sys_PutBuffer_Out ${file_in} \${R_BUF_${comp}_D}/${file_out}
1067          else
1068            eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${file_out}
1069          fi
1070          eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1071
1072          if ( ${ExecutionFail} ) ; then
1073            IGCM_sys_Cp ${file_in} ${SUBMIT_DIR}/Debug/${file_out}
1074          fi
1075        fi
1076      done
1077    fi
1078
1079    # Save Restarts files
1080    #--------------------
1081    IGCM_debug_Print 2 "Save Restart files for ${comp} : ${compname} component."
1082    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
1083    ListFilesName=${compname}_RestartFiles_List
1084    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1085
1086    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
1087      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1088
1089      (( i=0 ))
1090      until [ $i -ge $NbFiles ]; do
1091        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1092        eval file_in=${file_in_}
1093
1094        (( i_ = i+1 ))
1095        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1096        eval file_out=${file_out_}
1097
1098        (( i_ = i+2 ))
1099        eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1100        eval file_outin=${file_outin_}
1101
1102        generic_restart_file_name_in=$(    basename ${file_in} .nc )
1103        generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
1104        generic_restart_file_name_outin=$( basename ${file_outin} .nc )
1105
1106        nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l ) 
1107        if [ ${nb_restart_file} -gt 1 ] ; then
1108          j=0
1109          until [ $j -ge ${nb_restart_file} ]; do
1110            j4=${j}
1111            if [ X${Pack} = Xtrue ] ; then
1112              eval IGCM_sys_PutBuffer_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_BUF_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1113            else
1114              eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1115            fi
1116            if [ ! ${file_in} = ${file_outin} ] ; then
1117              if ( ${ExitFlag} ) ; then
1118                echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
1119              else
1120                IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
1121              fi
1122            fi
1123            (( j=j+1 ))
1124          done
1125        else
1126          if [ X${Pack} = Xtrue ] ; then
1127            eval IGCM_sys_PutBuffer_Rest ${file_in} \${R_BUF_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1128          else
1129            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1130          fi
1131          if [ ! ${file_in} = ${file_outin} ] ; then
1132            if ( ${ExitFlag} ) ; then
1133              echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1134            else
1135              IGCM_sys_Mv ${file_in} ${file_outin}
1136            fi
1137          fi
1138        fi
1139
1140        (( i=i+3 ))
1141      done
1142    else
1143      if [ X${FileName0} != XNONE ] ; then
1144        IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
1145      else
1146        IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
1147      fi
1148    fi
1149
1150    # Save Output files
1151    #------------------
1152    IGCM_debug_Print 2 "Save Output files for ${comp} : ${compname} component."
1153    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
1154    ListFilesName=${compname}_OutputFiles_List
1155    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1156
1157    if [ X${FileName0} != X${NULL_STR} ] ; then
1158      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1159
1160      (( i=0 ))
1161      until [ $i -ge $NbFiles ]; do
1162        SaveOnArchive=true
1163        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1164        eval file_in=${file_in_}
1165        (( i_ = i+1 ))
1166        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1167        eval file_out=${file_out_}
1168        #
1169        # Override file_out path remplacing R_SAVE by R_BUFR
1170        #
1171        if [ X${Pack} = Xtrue ] ; then
1172          file_out=$( echo $file_out | sed "s:^$R_SAVE:$R_BUFR:" )
1173        fi
1174        #
1175        # Not necessarily the best option. /!\ Potential side effects /!\
1176        #
1177        (( i_ = i+2 ))
1178        eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1179        #
1180        generic_file_name=$( basename ${file_in} .nc )
1181        nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
1182        #
1183        if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
1184          IGCM_debug_Print 2 "Parallelism with 1 file. Rebuilding ${file_in} not needed"
1185          IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
1186        elif [ ${nb_rebuild_file} -gt 1 ] ; then
1187          IGCM_debug_Print 2 "Parallelism detected and rebuilding ${file_in} is needed"
1188          if [ X${AsynchronousRebuild} = Xfalse ] ; then
1189            IGCM_debug_Print 2 "Rebuilding ${file_in} online"
1190            IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
1191          else
1192            IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
1193            [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1194            IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1195
1196            # Prepare headers for the shell dedicated to offline rebuild
1197            if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
1198              if [ $DRYRUN -le 1 ]; then
1199                echo "#!/bin/ksh                                        " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1200                echo "function IGCM_FlushRebuild                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1201                echo "{                                                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1202                echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1203                echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1204                echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1205                echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1206                echo "export R_SAVE=${R_SAVE}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1207                echo "export R_BUFR=${R_BUFR}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1208                echo "export R_OUT_KSH=${R_OUT_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1209                echo "export R_BUF_KSH=${R_BUF_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1210                echo "export config_UserChoices_JobName=${config_UserChoices_JobName}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1211                echo "export config_UserChoices_SpaceName=${config_UserChoices_SpaceName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1212              fi
1213            fi
1214            # Prepare the shell dedicated to offline rebuild
1215            if [ $DRYRUN -le 1 ]; then
1216              if [ ${file_in} = histstn.nc ] ; then
1217                echo "IGCM_sys_rebuild_station ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1218              else
1219                echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1220              fi
1221              echo "IGCM_debug_Verif_Exit_Post" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1222            fi
1223            #
1224            # Load Patch we need to apply and apply
1225            if [ $DRYRUN -le 1 ]; then
1226              if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
1227                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
1228                  echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1229                  echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1230                  echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1231                done
1232              fi
1233            fi
1234            #
1235            if [ $DRYRUN -le 1 ]; then
1236              if [ X${Pack} = Xtrue ] ; then
1237                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1238              else
1239                echo "IGCM_sys_Put_Out ${file_in} ${file_out}           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1240              fi
1241              echo "IGCM_debug_Verif_Exit_Post                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1242              echo "IGCM_sys_Rm ${generic_file_name}_*.nc               " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1243            fi
1244            SaveOnArchive=false
1245          fi
1246        fi
1247        #
1248        if [ ${SaveOnArchive} = true ] ; then
1249          #
1250          # Rebuild has been done online or it was not needed
1251          #
1252          # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
1253          #
1254          thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
1255          if ( [ ! X${thereisapatch} = X${NULL_STR} ] && [ X${AsynchronousRebuild} = Xtrue ] && [ -f ${file_in} ] ) ; then
1256            [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1257            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1258            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
1259            #
1260            if [ $DRYRUN -le 1 ]; then
1261              if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
1262                echo "#!/bin/ksh                                      " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1263                echo "function IGCM_FlushRebuild                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1264                echo "{                                               " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1265                echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1266                echo "echo                                            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1267                echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1268                echo "echo                                            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1269                echo "export R_SAVE=${R_SAVE}                         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1270                echo "export config_UserChoices_JobName=${config_UserChoices_JobName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1271              fi
1272              #
1273              for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
1274                echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1275                echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1276                echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1277              done
1278              #
1279              if [ X${Pack} = Xtrue ] ; then
1280                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1281              else
1282                echo "IGCM_sys_Put_Out ${file_in} ${file_out}         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1283              fi
1284              echo "IGCM_debug_Verif_Exit_Post                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1285              #
1286            fi
1287          else
1288            #
1289            # No Patch, No Asynchronous rebuild, online rebuild has been done or was not needed
1290            #
1291            if [ X${Pack} = Xtrue ] ; then
1292              IGCM_sys_PutBuffer_Out ${file_in} ${file_out}
1293            else
1294              IGCM_sys_Put_Out ${file_in} ${file_out}
1295            fi
1296            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1297            if [ ${nb_rebuild_file} -gt 1 ] ; then
1298              for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
1299                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
1300              done
1301            fi
1302          fi
1303        fi
1304        (( i=i+3 ))
1305      done
1306    fi
1307    echo
1308  done
1309  IGCM_debug_PopStack "IGCM_comp_Finalize"
1310}
Note: See TracBrowser for help on using the repository browser.