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

Last change on this file since 778 was 778, checked in by labetoulle, 11 years ago

Bugfix in GetInputRestartFiles? when Restarts_OverRule=n (see #101).

  • 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.0 KB
RevLine 
[2]1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
[373]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
[2]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{
[544]17  IGCM_debug_PushStack "IGCM_comp_Initialize"
[2]18
[778]19  # Debug Print :
[544]20  echo
21  IGCM_debug_Print 1 "IGCM_comp_Initialize"
22  echo
[2]23
[544]24  typeset comp compname comptagname CompatibilityTag auxprint card_UserChoices first_option option i j
25  for comp in ${config_ListOfComponents[*]} ; do
[2]26
[544]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
[457]31
[615]32    # Debug Print
33    IGCM_debug_Print 1 "Initialize ${comp} : ${compname} component."
34
[544]35    # Read libIGCM compatibility version in ${compname}.card
36    card=${SUBMIT_DIR}/COMP/${compname}.card
37    IGCM_card_DefineVariableFromOption ${card} Compatibility libIGCM
[2]38
[778]39    eval CompatibilityTag=\${${compname}_Compatibility_libIGCM} > /dev/null 2>&1
[544]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
[2]43
[544]44    # Manage component executable
45    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card Executable ${comp}
[2]46
[544]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
[2]53
[544]54    # Debug Print :
55    IGCM_debug_Print 2 "Initialize following component library"
[522]56
[544]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}"
[2]69
[544]70    # Debug Print
71    IGCM_debug_Print 3 "Initialize ${comp} output directory."
[2]72
[544]73    # Define ARCHIVED Dirs
74    eval R_OUT_${comp}=${R_SAVE}/${comp}
75    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}}
[2]76
[544]77    eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output
78    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O}
[2]79
[544]80    eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart
81    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R}
[2]82
[544]83    eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug
84    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D}
[2]85
[544]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
[778]118        unset card_UserChoices
[544]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
[778]123        IGCM_card_DefineVariableFromOption ${card} UserChoices ${option}
124        eval IGCM_debug_Print 3 "${option}=\${${compname}_UserChoices_${option}}"
[544]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
[778]145        #
146        eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
147        #
148        if [ X${flag_post} != XNONE ] ; then
149          #
[544]150          # First of all
151          #
[778]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}
[544]186              #
[778]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 ))
[544]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
[2]229
[544]230  IGCM_debug_PopStack "IGCM_comp_Initialize"
[2]231}
232
233#=======================================================================
234function IGCM_comp_PrepareDeletedFiles
235{
[544]236  IGCM_debug_PushStack "IGCM_comp_PrepareDeletedFiles" $@
[778]237
[544]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
[2]243
[544]244  IGCM_debug_PopStack "IGCM_comp_PrepareDeletedFiles"
[2]245}
246
247#=======================================================================
248function IGCM_comp_GetInputInitialStateFiles
249{
[544]250  IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles"
[2]251
[544]252  # Debug Print :
253  echo
254  IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles"
255  echo
[2]256
[544]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
[778]267        eval do_init="n"
[544]268      else
[778]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
[544]277      fi
[2]278
[544]279      if [ "${do_init}" = "y" ] ; then
[778]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
[2]283
[778]284        # Debug Print :
285        IGCM_debug_Print 3 "Initialisation files ${compname}"
[2]286
[778]287        card=${SUBMIT_DIR}/COMP/${compname}.card
[2]288
[778]289        IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List
290        ListFilesName=${compname}_InitialStateFiles_List
[2]291
[778]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_}
[2]302
[778]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
[544]313      fi
314    done
315  fi
316  IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles"
[2]317}
318
319#=======================================================================
[247]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{
[544]338  IGCM_debug_PushStack "IGCM_SmoothModulo"
339  typeset defVector ModValue
[247]340
[544]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))}' )
[247]343
[544]344  # Save Smooth Min and Max. Needed to call IGCM_sys_Get when appropriate
345  arr[1]=${defVector[0]}
346  arr[2]=${defVector[2]}
[412]347
[544]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
[247]359    else
[544]360      arr[3]=false
361      echo ${arr[@]}
362      IGCM_debug_PopStack "IGCM_SmoothModulo"
363      return 0
[247]364    fi
[544]365  else
366    arr[3]=false
367    echo ${arr[@]}
368    IGCM_debug_PopStack "IGCM_SmoothModulo"
369    return 0
370  fi
[247]371}
372
373#=======================================================================
374function IGCM_comp_GetInputSmoothFiles
375{
[544]376  IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles"
[247]377
[544]378  # Debug Print :
379  echo
380  IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles"
381  echo
[247]382
[544]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
[247]385
[544]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
[247]390
[544]391    # Debug Print :
392    IGCM_debug_Print 3 "Smooth files ${compname}"
[247]393
[544]394    card=${SUBMIT_DIR}/COMP/${compname}.card
[247]395
[544]396    IGCM_card_DefineArrayFromOption ${card} SmoothFiles List
397    ListFilesName=${compname}_SmoothFiles_List
398    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
[247]399
[544]400    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != X"Section" ] ) ; then
401      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
[247]402
[544]403      (( i=0 ))
404      until [ $i -ge $NbFiles ]; do
[778]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_}
[247]410
[778]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
[548]425
[778]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 ))
[544]435      done
436    fi
437  done
[778]438
[544]439  IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
[247]440}
441
442#=======================================================================
[2]443function IGCM_comp_GetInputBoundaryFiles
444{
[544]445  IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
[2]446
[544]447  # Debug Print :
448  echo
449  IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles"
450  echo
[2]451
[544]452  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
453  typeset file_in_ file_in file_out_ file_out
[2]454
[544]455  if [ ${Period} = 1 ]; then
456    ListFixBoundary=" "
457  fi
[2]458
[544]459  for comp in ${config_ListOfComponents[*]} ; do
[2]460
[544]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
[2]464
[544]465    # Debug Print :
466    IGCM_debug_Print 3 "Boundary files ${compname}"
[2]467
[544]468    card=${SUBMIT_DIR}/COMP/${compname}.card
[2]469
[544]470    IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
471    ListFilesName=${compname}_BoundaryFiles_List
472    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
[2]473
[544]474    if [ X${FileName0} != X${NULL_STR} ] ; then
475      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
[2]476
[544]477      (( i=0 ))
478      until [ $i -ge $NbFiles ]; do
[778]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_}
[2]484
[778]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
[2]492
[778]493        (( i=i+2 ))
[544]494      done
495    fi
[2]496
[544]497    # Get non deleted files
498    if [ ${Period} = 1 ]; then
[2]499
[544]500      IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
501      ListFilesName=${compname}_BoundaryFiles_ListNonDel
502      eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
[778]503
[544]504      if [ X${FileName0} != X${NULL_STR} ] ; then
[778]505        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
[2]506
[778]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_}
[2]514
[778]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
[2]522
[778]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
[544]531      fi
532    fi
533  done
[778]534
[544]535  IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
[2]536}
537
538#=======================================================================
539function IGCM_comp_DelFixeBoundaryFiles
540{
[544]541  IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
[2]542
[544]543  # Debug Print :
544  echo
545  IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles"
546  echo
[2]547
[544]548  ls -l ${ListFixBoundary}
549  rm -f ${ListFixBoundary}
[2]550
[544]551  IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
[2]552}
553
554#=======================================================================
555function IGCM_comp_GetInputParametersFiles
556{
[544]557  IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
[2]558
[544]559  # Debug Print :
560  echo
561  IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles"
562  echo
[2]563
[544]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
[2]569
[544]570    # Debug Print :
571    IGCM_debug_Print 3 "Parameters ${compname}"
[2]572
[778]573    card=${SUBMIT_DIR}/COMP/${compname}.card
[2]574
[544]575    IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
576    ListFilesName=${compname}_ParametersFiles_List
577    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
[2]578
[544]579    if [ X${FileName0} != X${NULL_STR} ] ; then
580      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
[2]581
[544]582      (( i=0 ))
583      until [ $i -ge $NbFiles ]; do
[778]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_} 
[2]589
[778]590        IGCM_sys_Cp ${file_in} ${file_out} 
591        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
[2]592
[778]593        (( i=i+2 ))
[544]594      done
595    fi
596  done
[2]597
[544]598  IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
[2]599}
600
601#=======================================================================
602function IGCM_comp_GetInputRestartFiles
603{
[544]604  IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
[2]605
[544]606  # Debug Print :
607  echo
608  IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles"
609  echo
[2]610
[590]611  typeset Date_tmp Date_r Path_r do_start CompOldName Path_OUT Path_BUF
612  typeset Buffered Archived Tared PotentialTarFile IsMatching TarFileFound
[544]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
[2]616
[778]617  IsMatching=""
618
[544]619  for comp in ${config_ListOfComponents[*]} ; do
620    # Define component
621    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
622    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
623    #
624    card=${SUBMIT_DIR}/COMP/${compname}.card
625    #
626    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
627    ListFilesName=${compname}_RestartFiles_List
628    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
[2]629
[544]630    # Debug Print :
631    IGCM_debug_Print 3 "restart ${compname}"
[2]632
[544]633    if ( ${FirstInitialize} ) ; then
[2]634
[544]635      if [ "${config_Restarts_OverRule}" = "y" ] ; then
[778]636        eval config_${comp}_Restart="y"
637        eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
638        eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
639        eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
640        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
641        eval CompOldName=${comp}
[544]642      else
[778]643        # Read component Restarts parameters
644        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
645        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
[2]646
[778]647        if [ "${do_start}" = "y" ] ; then
648          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
649          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
650          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
651        else
652          eval config_${comp}_RestartDate=-1
653          eval config_${comp}_RestartJobName=${NULL_STR}
654          eval config_${comp}_RestartPath=${NULL_STR}
655        fi
656        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} OldName
657        eval CompOldName=\${config_${comp}_OldName}
658        if [ X${CompOldName} = X ] ; then
659          eval CompOldName=${comp}
660        fi
661
662        # Reinitialize IsMatching to allow searching for a different tar file for each component.
663        IsMatching=""
664        TarFileFound=""
[544]665      fi
[2]666
[544]667      if [ "${do_start}" = "y" ] ; then
[2]668
[672]669        # Restore Restarts files
670        #-----------------------
[778]671        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
672          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
[2]673
[778]674          (( i=1 ))
675          until [ $i -gt $NbFiles ]; do
676            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
677            eval file_in=${file_in_}
678            (( i_ = i+1 ))
679            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
680            eval file_out=${file_out_}
681
682            eval Date_tmp=\${config_${comp}_RestartDate}
683            Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
[672]684            # will be re-use
685            eval RestartPath=\${config_${comp}_RestartPath}
686            eval RestartJobName=\${config_${comp}_RestartJobName}
687            #
[778]688            Path_r=${RestartPath}/${RestartJobName}/${CompOldName}/Restart
689            file_in_Name=${RestartJobName}_${Date_r}_${file_in}
[2]690
[778]691            extension_in=$( echo ${file_in_Name##*.} )
692            extension_out=$( echo ${file_out##*.} )
[672]693
[778]694            generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
695            generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
[2]696
[778]697            Path_OUT=${Path_r}/${generic_restart_file_name_in}
698
[672]699            if [ $( IGCM_sys_TestFileBuffer ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
[778]700              IGCM_debug_Print 3 "Buffered restart"
701              Buffered=true
702              Archived=false
703              Tared=false
704              nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_OUT}_????.${extension_in})
[672]705            elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
[778]706              IGCM_debug_Print 3 "Archived restart"
707              Buffered=false
708              Archived=true
709              Tared=false
710              nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
[672]711            else
712              IGCM_debug_Print 3 "Tared restart"
[778]713              Buffered=false
714              Archived=false
715              Tared=true
[672]716              # Look after the tar file we want if we did not found it already
[778]717              if [ X${IsMatching} = X ] ; then
718                for PotentialTarFile in $( find ${RestartPath}/${RestartJobName}/RESTART -name "${RestartJobName}_*_restart.tar" -print ) ; do
719                  IsMatching=$( echo ${PotentialTarFile##*/} | \
720                        sed "s:^${RestartJobName}_::" | \
721                        sed "s:\.restart\.tar$::" | \
722                        gawk -F_ -v restartdate=${Date_r} \
723                             '{if (($1 < restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
724                  if [ ! X${IsMatching} = X ] ; then
725                    TarFileFound=${PotentialTarFile}
726                    break
727                  fi
728                done
729              fi
[672]730              IGCM_debug_Print 1 "tar xvf ${TarFileFound} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
[778]731              tar xvf ${TarFileFound} ${comp}_${generic_restart_file_name_in}*.${extension_in}
732              nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
733            fi
[672]734
735            if [ ${nb_restart_file} -gt 1 ] ; then
[778]736              j=0
737              until [ $j -ge ${nb_restart_file} ]; do
738                j4=${j}
739                if [ X${Buffered} = Xtrue ] ; then
740                  IGCM_sys_GetBuffer ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
741                elif [ X${Archived} = Xtrue ] ; then
742                  IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
743                elif [ X${Tared} = Xtrue ] ; then
744                  IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
745                fi
746                (( j=j+1 ))
747              done
[740]748
749              if [ X${NUM_PROC_OCE} != X ] ; then
750                if [ ${NUM_PROC_OCE} -ne ${nb_restart_file} ] ; then
751                  IGCM_sys_rebuild ${generic_restart_file_name_out}.${extension_out} ${generic_restart_file_name_out}_????.${extension_out}
752                  IGCM_sys_Rm ${generic_restart_file_name_out}_????.${extension_out}
753                fi
754              fi
[778]755            else
756              if [ X${Buffered} = Xtrue ] ; then
757                IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
758              elif [ X${Archived} = Xtrue ] ; then
759                IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
760              elif [ X${Tared} = Xtrue ] ; then
761                IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
762              fi
763            fi
764            (( i=i+3 ))
765          done
[672]766
[778]767        else
768          if [ X${FileName0} != XNONE ] ; then
769            IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
770          else
771            IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
772          fi
773        fi
[544]774      fi
775    elif [ ${Period} -eq 1 ] ; then
776      # if not FirstInitialize and first loop of this job
[2]777
[544]778      # Restore Restarts files
779      #-----------------------
780      if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
[778]781        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
[2]782
[778]783        (( i=1 ))
784        until [ $i -gt $NbFiles ]; do
785          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
786          eval file_in=${file_in_}
787          (( i_ = i+1 ))
788          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
789          eval file_out=${file_out_}
[2]790
[778]791          file_in_Name=${run_Configuration_OldPrefix}_${file_in}
[662]792
[778]793          extension_in=$( echo ${file_in_Name##*.} )
794          extension_out=$( echo ${file_out##*.} )
[67]795
[778]796          generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
797          generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
798
799          eval Path_BUF=\${R_BUF_${comp}_R}/${generic_restart_file_name_in}
800          eval Path_OUT=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
801
[662]802          if [ $( IGCM_sys_TestFileBuffer ${Path_BUF}*.${extension_in} ; echo $? ) = 0 ] ; then
[778]803            IGCM_debug_Print 3 "Buffered restart"
804            Buffered=true
805            Archived=false
806            Tared=false
807            nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_BUF}_????.${extension_in})
[672]808          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
[778]809            IGCM_debug_Print 3 "Archived restart"
810            Buffered=false
811            Archived=true
812            Tared=false
813            nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
814          else
815            IGCM_debug_Print 3 "Tared restart"
816            Buffered=false
817            Archived=false
818            Tared=true
819            # Look after the tar file we want if we did not found it already
820            if [ X${IsMatching} = X ] ; then
821              for PotentialTarFile in $( find ${R_SAVE}/RESTART -name "${config_UserChoices_JobName}_*_restart.tar" -print ) ; do
822                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}}' )
823                if [ ! X${IsMatching} = X ] ; then
824                  TarFileFound=${PotentialTarFile}
825                  break
826                fi
827              done
828            fi
829            tar xvf ${TarFileFound} ${comp}_${generic_restart_file_name_in}*.${extension_in}
830            nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
831          fi
[41]832
[778]833          if [ ${nb_restart_file} -gt 1 ] ; then
834            j=0
835            until [ $j -ge ${nb_restart_file} ]; do
836              j4=${j}
837              if [ X${Buffered} = Xtrue ] ; then
838                IGCM_sys_GetBuffer ${Path_BUF}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
839              elif [ X${Archived} = Xtrue ] ; then
840                IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
841              elif [ X${Tared} = Xtrue ] ; then
842                IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
843              fi
844              (( j=j+1 ))
845            done
846          else
847            if [ X${Buffered} = Xtrue ] ; then
848              eval IGCM_sys_GetBuffer \${R_BUF_${comp}_R}/${file_in_Name} ${file_out}
849            elif [ X${Archived} = Xtrue ] ; then
850              eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
851            elif [ X${Tared} = Xtrue ] ; then
852              IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
853            fi
854          fi
855          (( i=i+3 ))
856        done
[544]857      else
[778]858        if [ X${FileName0} != XNONE ] ; then
859          IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
860        else
861          IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
862        fi
[544]863      fi
[420]864    fi
[544]865  done
[420]866
[544]867  NbFiles=$( ls * 2> /dev/null | wc -l )
868  if [ ${NbFiles} -gt 0 ] ; then
869    IGCM_sys_Chmod u+rw *
870  fi
871
872  IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
[2]873}
874
875#=======================================================================
[269]876function IGCM_comp_PeriodStart
877{
[544]878  IGCM_debug_PushStack "IGCM_comp_PeriodStart"
[269]879
[544]880  # Debug Print :
881  echo
882  IGCM_debug_Print 1 "IGCM_comp_PeriodStart"
883  echo
[269]884
[544]885  typeset ExeNameIn ExeNameOut
886  typeset comp compname comptagname
887  for comp in ${config_ListOfComponents[*]} ; do
888    # Define component
889    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
890    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
[269]891
[544]892    # Copy executable for this component
893    eval ExeNameIn=\${config_Executable_${comp}[0]}
894    eval ExeNameOut=\${config_Executable_${comp}[1]}
[269]895
[544]896    # Debug Print
897    IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
898    # UPDATE component
899    ${comp}_PeriodStart 2> /dev/null
[269]900
[544]901  done
[269]902
[544]903  IGCM_debug_PopStack "IGCM_comp_PeriodStart"
[269]904}
905
906#=======================================================================
[2]907function IGCM_comp_Update
908{
[544]909  IGCM_debug_PushStack "IGCM_comp_Update"
[2]910
911    # Debug Print :
[544]912  echo
913  IGCM_debug_Print 1 "IGCM_comp_Update"
914  echo
[2]915
[544]916  typeset ExeNameIn ExeNameOut
917  typeset comp compname comptagname
918  for comp in ${config_ListOfComponents[*]} ; do
919    # Define component
920    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
921    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
[2]922
[544]923    # Copy executable for this component
924    eval ExeNameIn=\${config_Executable_${comp}[0]}
925    eval ExeNameOut=\${config_Executable_${comp}[1]}
[151]926
[622]927    # If missing executable and DRYRUN is set to 0 or 1  then stop!
928    if [ ${DRYRUN} -le 1 ] && [ X${ExeNameIn} != X\"\" ] &&  [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
929      IGCM_debug_Exit "IGCM_comp_Update missing executable ${ExeNameIn}"
[778]930    fi
[236]931
[544]932    if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
933      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
934      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
935        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
936      fi
937    elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
938      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
939      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
940        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
941      fi
942    fi
[2]943
[544]944    # Debug Print
945    IGCM_debug_Print 1 "Update ${compname} Parameter Files."
946    # UPDATE component
947    ${comp}_Update
[2]948
[544]949  done
[2]950
[544]951  IGCM_debug_PopStack "IGCM_comp_Update"
[2]952}
953
954#=======================================================================
955function IGCM_comp_Finalize
956{
[544]957  IGCM_debug_PushStack "IGCM_comp_Finalize"
[2]958
[544]959  # Debug Print :
960  echo
961  IGCM_debug_Print 1 "IGCM_comp_Finalize"
962  echo
[2]963
[544]964  typeset ListTextName TextName0
965  typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
966  typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
967  typeset -Z4 j4
968  typeset list_file nlist_file
969  typeset compactoutputs
[429]970
[544]971  compactoutputs=false
972  if [ X${JobType} != XRUN ] ; then
973    compactoutputs=true
974  elif [ X${config_UserChoices_CompactText} != Xn ] ; then
975    compactoutputs=true
976  fi
[433]977
[544]978  for comp in ${config_ListOfComponents[*]} ; do
979    # Define component
980    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
981    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
[2]982
[544]983    # Debug Print
984    IGCM_debug_Print 1 "Finalize ${comp} : ${compname} component."
985    # FINALIZE component
986    ${comp}_Finalize
[2]987
[778]988    card=${SUBMIT_DIR}/COMP/${compname}.card
[2]989
[544]990    # Save Restarts files
991    #--------------------
992    IGCM_debug_Print 2 "Save Restart files for ${comp} : ${compname} component."
993    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
994    ListFilesName=${compname}_RestartFiles_List
995    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
[778]996
[544]997    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
998      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
[778]999
[544]1000      (( i=0 ))
1001      until [ $i -ge $NbFiles ]; do
[778]1002        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1003        eval file_in=${file_in_}
[2]1004
[778]1005        (( i_ = i+1 ))
1006        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1007        eval file_out=${file_out_}
[151]1008
[778]1009        (( i_ = i+2 ))
1010        eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1011        eval file_outin=${file_outin_}
[151]1012
[778]1013        generic_restart_file_name_in=$(    basename ${file_in} .nc )
1014        generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
1015        generic_restart_file_name_outin=$( basename ${file_outin} .nc )
[2]1016
[778]1017        nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l ) 
1018        if [ ${nb_restart_file} -gt 1 ] ; then
1019          j=0
1020          until [ $j -ge ${nb_restart_file} ]; do
1021            j4=${j}
1022            if [ X${Pack} = Xtrue ] ; then
1023              eval IGCM_sys_PutBuffer_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_BUF_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1024            else
1025              eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
1026            fi
1027            if [ ! ${file_in} = ${file_outin} ] ; then
1028              if ( ${ExitFlag} ) ; then
1029                echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
1030              else
1031                IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
1032              fi
1033            fi
1034            (( j=j+1 ))
1035          done
1036        else
1037          if [ X${Pack} = Xtrue ] ; then
1038            eval IGCM_sys_PutBuffer_Rest ${file_in} \${R_BUF_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1039          else
1040            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1041          fi
1042          if [ ! ${file_in} = ${file_outin} ] ; then
1043            if ( ${ExitFlag} ) ; then
1044              echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1045            else
1046              IGCM_sys_Mv ${file_in} ${file_outin}
1047            fi
1048          fi
1049        fi
1050
1051        (( i=i+3 ))
[544]1052      done
1053    else
1054      if [ X${FileName0} != XNONE ] ; then
[778]1055        IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
[544]1056      else
[778]1057        IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
[544]1058      fi
1059    fi
[2]1060
[544]1061    # Save Output files
1062    #------------------
1063    IGCM_debug_Print 2 "Save Output files for ${comp} : ${compname} component."
1064    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
1065    ListFilesName=${compname}_OutputFiles_List
1066    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
[2]1067
[544]1068    if [ X${FileName0} != X${NULL_STR} ] ; then
1069      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
[149]1070
[544]1071      (( i=0 ))
1072      until [ $i -ge $NbFiles ]; do
[778]1073        SaveOnArchive=true
1074        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1075        eval file_in=${file_in_}
1076        (( i_ = i+1 ))
1077        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1078        eval file_out=${file_out_}
1079        #
1080        # Override file_out path remplacing R_SAVE by R_BUFR
1081        #
1082        if [ X${Pack} = Xtrue ] ; then
1083          file_out=$( echo $file_out | sed "s:^$R_SAVE:$R_BUFR:" )
1084        fi
1085        #
1086        # Not necessarily the best option. /!\ Potential side effects /!\
1087        #
1088        (( i_ = i+2 ))
1089        eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1090        #
1091        generic_file_name=$( basename ${file_in} .nc )
1092        nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
1093        #
1094        if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
1095          IGCM_debug_Print 2 "Parallelism with 1 process. Rebuilding ${file_in} not needed"
1096          IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
1097        elif [ ${nb_rebuild_file} -gt 1 ] ; then
1098          IGCM_debug_Print 2 "Parallelism detected rebuilding ${file_in} is needed"
1099          if [ X${AsynchronousRebuild} = Xfalse ] ; then
1100            IGCM_debug_Print 2 "Rebuilding ${file_in} online"
1101            IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc
1102          else
1103            IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
1104            [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1105            IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
[544]1106
[778]1107            # Prepare headers for the shell dedicated to offline rebuild
1108            if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
1109              if [ $DRYRUN -le 1 ]; then
1110                echo "#!/bin/ksh                                        " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1111                echo "function IGCM_FlushRebuild                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1112                echo "{                                                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1113                echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1114                echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1115                echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1116                echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1117                echo "export R_SAVE=${R_SAVE}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1118                echo "export R_BUFR=${R_BUFR}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[694]1119                echo "export R_OUT_KSH=${R_OUT_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1120                echo "export R_BUF_KSH=${R_BUF_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[749]1121                echo "export config_UserChoices_JobName=${config_UserChoices_JobName}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1122                echo "export config_UserChoices_SpaceName=${config_UserChoices_SpaceName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[778]1123              fi
1124            fi
1125            # Prepare the shell dedicated to offline rebuild
1126            if [ $DRYRUN -le 1 ]; then
[694]1127              if [ ${file_in} = histstn.nc ] ; then
1128                echo "IGCM_sys_rebuild_station ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1129              else
[778]1130                echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[694]1131              fi
1132              echo "IGCM_debug_Verif_Exit_Post" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
[778]1133            fi
1134            #
1135            # Load Patch we need to apply and apply
1136            if [ $DRYRUN -le 1 ]; then
1137              if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
1138                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
1139                  echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1140                  echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1141                  echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1142                done
1143              fi
1144            fi
1145            #
1146            if [ $DRYRUN -le 1 ]; then
1147              if [ X${Pack} = Xtrue ] ; then
1148                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1149              else
1150                echo "IGCM_sys_Put_Out ${file_in} ${file_out}           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1151              fi
1152              echo "IGCM_debug_Verif_Exit_Post                          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1153              echo "IGCM_sys_Rm ${generic_file_name}_*.nc               " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1154            fi
1155            SaveOnArchive=false
1156          fi
1157        fi
1158        #
1159        if [ ${SaveOnArchive} = true ] ; then
1160          #
1161          # Rebuild has been done online or it was not needed
1162          #
1163          # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
1164          #
1165          thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
1166          if ( [ ! X${thereisapatch} = X${NULL_STR} ] && [ X${AsynchronousRebuild} = Xtrue ] && [ -f ${file_in} ] ) ; then
1167            [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1168            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1169            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
1170            #
1171            if [ $DRYRUN -le 1 ]; then
1172              if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then
1173                echo "#!/bin/ksh                                      " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1174                echo "function IGCM_FlushRebuild                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1175                echo "{                                               " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1176                echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1177                echo "echo                                            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1178                echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1179                echo "echo                                            " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1180                echo "export R_SAVE=${R_SAVE}                         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1181                echo "export config_UserChoices_JobName=${config_UserChoices_JobName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1182              fi
[545]1183              #
[778]1184              for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do
1185                echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1186                echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1187                echo "IGCM_debug_Verif_Exit_Post                      " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1188              done
1189              #
1190              if [ X${Pack} = Xtrue ] ; then
1191                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1192              else
1193                echo "IGCM_sys_Put_Out ${file_in} ${file_out}         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1194              fi
1195              echo "IGCM_debug_Verif_Exit_Post                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1196              #
1197            fi
1198          else
1199            #
1200            # No Patch, No Asynchronous rebuild, online rebuild has been done or was not needed
1201            #
1202            if [ X${Pack} = Xtrue ] ; then
1203              IGCM_sys_PutBuffer_Out ${file_in} ${file_out}
1204            else
1205              IGCM_sys_Put_Out ${file_in} ${file_out}
1206            fi
1207            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1208            if [ ${nb_rebuild_file} -gt 1 ] ; then
1209              for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
1210                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
1211              done
1212            fi
1213          fi
1214        fi
1215        (( i=i+3 ))
[544]1216      done
1217    fi
[2]1218
[544]1219    # Save Output Text files of models
1220    #---------------------------------
1221    IGCM_debug_Print 2 "Save Output Text files for ${comp} : ${compname} component."
1222    IGCM_card_DefineArrayFromOption ${card} OutputText List
1223    ListTextName=${compname}_OutputText_List
[778]1224
[544]1225    eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1226    if [ X${TextName0} != X${NULL_STR} ] ; then
1227      eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
[2]1228
[544]1229      (( i=0 ))
1230      until [ $i -eq $NbFiles ]; do
[778]1231        eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1232        eval file_out=${PREFIX}_${file_in}
[2]1233
[778]1234        (( i=i+1 ))
[429]1235
[778]1236        unset list_file
1237        #set +A list_file -- $( ls ${file_in}* | sort 2>/dev/null )
[544]1238        # result for a a1 a10 a2 with file_in=a a a1 a2 a10
[778]1239        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 )
1240        nlist_file=${#list_file[@]}
1241        if [ ${nlist_file} -gt 1 ] ; then
1242          if ( ${compactoutputs} ) ; then
1243            IGCM_debug_Print 2 "Parallelism of Text Output with ${nlist_file} files."
1244            IGCM_debug_Print 2 "Compact files in ${file_out} : " ${list_file[*]}
1245            echo ${list_file[*]} > ${file_out}
1246            echo "" >> ${file_out}
[433]1247
[778]1248            (( i_ = 0 ))
1249            for file in ${list_file[@]}
1250            do
1251              echo "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " >> ${file_out}
1252              echo "| " ${i_} " " ${file} >> ${file_out}
1253              echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " >> ${file_out}
1254              cat ${file} | sed "s/\(.*\)/${i_}\1/" ${file} >> ${file_out}
1255              echo "" >> ${file_out}
1256              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1257                  (( i_ = i_ + 1 ))
1258            done
1259            if [ X${Pack} = Xtrue ] ; then
1260              eval IGCM_sys_PutBuffer_Out ${file_out} \${R_BUF_${comp}_D}/${file_out}
1261            else
1262              eval IGCM_sys_Put_Out ${file_out} \${R_OUT_${comp}_D}/${file_out}
1263            fi
1264            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_out}" > /dev/null 2>&1
[433]1265
[778]1266            if ( ${ExecutionFail} ) ; then
1267              IGCM_sys_Cp ${file_out} ${SUBMIT_DIR}/Debug
1268            fi
1269          else
1270            for file in ${list_file[@]}
1271            do
1272              if [ X${Pack} = Xtrue ] ; then
1273                eval IGCM_sys_PutBuffer_Out ${file} \${R_BUF_${comp}_D}/${PREFIX}_${file}
1274              else
1275                eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file}
1276              fi
1277              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
[2]1278
[778]1279              if ( ${ExecutionFail} ) ; then
1280                IGCM_sys_Cp ${file} ${SUBMIT_DIR}/Debug/${PREFIX}_${file}
1281              fi
1282            done
1283          fi
1284        else
1285          if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1286            eval IGCM_sys_Mv ${file_in}* ${file_in}
1287          fi
1288          if [ X${Pack} = Xtrue ] ; then
1289            eval IGCM_sys_PutBuffer_Out ${file_in} \${R_BUF_${comp}_D}/${file_out}
1290          else
1291            eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${file_out}
1292          fi
1293          eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1294
1295          if ( ${ExecutionFail} ) ; then
1296            IGCM_sys_Cp ${file_in} ${SUBMIT_DIR}/Debug/${file_out}
1297          fi
1298        fi
[544]1299      done
1300    fi
1301    echo
1302  done
1303  IGCM_debug_PopStack "IGCM_comp_Finalize"
[2]1304}
Note: See TracBrowser for help on using the repository browser.