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

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