source: CONFIG_DEVT/IPSLCM6.5_work_ENSEMBLES/libIGCM/libIGCM_comp/libIGCM_comp.ksh @ 6031

Last change on this file since 6031 was 6031, checked in by aclsce, 2 years ago

Update of ensembles development configuration.

File size: 84.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:: 1545                                     $ Revision of last commit
7# $Author:: aclsce                                     $ Author of last commit
8# $Date:: 2021-01-18 14:16:13 +0100 (Mon, 18 Jan 2021) $ 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 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    # ${compname}.card PATH
36    card=${SUBMIT_DIR}/COMP/${compname}.card
37
38    # Manage component executable
39    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card Executable ${comp}
40
41    # Define all options in section [comp]
42    IGCM_debug_Print 3 " DefineArrayFromSection : ${comp}"
43    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ${comp}
44    eval config_comp=\${config_${comp}[*]} > /dev/null 2>&1
45    for option in ${config_comp[*]} ; do
46        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} ${option}
47    done
48    IGCM_debug_Print 3 " Found in section config_${comp} :  ${config_comp[*]} "
49
50    # Debug Print :
51    eval auxprint=\${config_${comp}_WriteFrequency}
52    IGCM_debug_Print 1 "Write frequency for ${compname} : ${auxprint} "
53    #2> /dev/null
54
55    # Debug Print :
56    IGCM_debug_Print 2 "Initialize following component library"
57
58    # Source drivers in directory DRIVER if it exist
59    # else source them from directory COMP
60    if [ -d ${SUBMIT_DIR}/DRIVER ] ; then
61      IGCM_debug_Print 2 ${SUBMIT_DIR}/DRIVER/${compname}.driver
62      # Source component library
63      . ${SUBMIT_DIR}/DRIVER/${compname}.driver
64    else
65      IGCM_debug_Print 2 ${SUBMIT_DIR}/COMP/${compname}.driver
66      # Source component library
67      . ${SUBMIT_DIR}/COMP/${compname}.driver
68    fi
69    IGCM_debug_Print 3 "With tag : ${comptagname}"
70
71    # Debug Print
72    IGCM_debug_Print 3 "Initialize ${comp} output directory."
73
74    # Define ARCHIVED Dirs
75    eval R_OUT_${comp}=${R_SAVE}/${comp}
76    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}}
77
78    eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output
79    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O}
80
81    eval R_OUT_${comp}_A=\${R_OUT_${comp}}/Analyse
82    eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_A}
83
84    eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart
85    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R}
86
87    eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug
88    [ ${config_Post_PackFrequency} = NONE ] && eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D}
89
90    eval R_OUT_${comp}_O_H=\${R_OUT_${comp}_O}/HF
91    eval R_OUT_${comp}_O_D=\${R_OUT_${comp}_O}/DA
92    eval R_OUT_${comp}_O_M=\${R_OUT_${comp}_O}/MO
93    eval R_OUT_${comp}_O_Y=\${R_OUT_${comp}_O}/YE
94
95    eval R_OUT_${comp}_A_H=\${R_OUT_${comp}_A}/TS_HF
96    eval R_OUT_${comp}_A_D=\${R_OUT_${comp}_A}/TS_DA
97    eval R_OUT_${comp}_A_M=\${R_OUT_${comp}_A}/TS_MO
98    eval R_OUT_${comp}_A_Y=\${R_OUT_${comp}_A}/TS_YE
99
100    # Define BUFFERED Dirs
101    if ( [ ! ${config_Post_PackFrequency} = NONE ] || [ X${config_UserChoices_SpaceName} = XTEST ] ) ; then
102      eval R_BUF_${comp}=${R_BUFR}/${comp}
103      eval IGCM_sys_Mkdir \${R_BUF_${comp}}
104
105      eval R_BUF_${comp}_O=\${R_BUF_${comp}}/Output
106      eval IGCM_sys_Mkdir \${R_BUF_${comp}_O}
107
108      eval R_BUF_${comp}_A=\${R_BUF_${comp}}/Analyse
109      eval IGCM_sys_Mkdir \${R_BUF_${comp}_A}
110
111      eval R_BUF_${comp}_R=\${R_BUF_${comp}}/Restart
112
113      eval R_BUF_${comp}_D=\${R_BUF_${comp}}/Debug
114
115      if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
116
117        for (( pool_rank_comp_Init=0 ; pool_rank_comp_Init < $(($config_Ensemble_PoolNumber)) ; pool_rank_comp_Init++ ))
118        do
119
120        for (( pool_member_rank=0 ; pool_member_rank < $config_Ensemble_PoolSize ; pool_member_rank++ ))
121        do
122         whole_ensemble_rank=$(($config_Ensemble_PoolSize*$pool_rank_comp_Init+$pool_member_rank))
123         eval IGCM_sys_Mkdir \${R_BUF_${comp}_R}/MEMBER_$whole_ensemble_rank
124         eval IGCM_sys_Mkdir \${R_BUF_${comp}_D}/MEMBER_$whole_ensemble_rank
125        done
126        done
127      fi
128
129      eval R_BUF_${comp}_O_H=\${R_BUF_${comp}_O}/HF
130      eval R_BUF_${comp}_O_D=\${R_BUF_${comp}_O}/DA
131      eval R_BUF_${comp}_O_M=\${R_BUF_${comp}_O}/MO
132      eval R_BUF_${comp}_O_Y=\${R_BUF_${comp}_O}/YE
133
134      eval R_BUF_${comp}_A_H=\${R_BUF_${comp}_A}/TS_HF
135      eval R_BUF_${comp}_A_D=\${R_BUF_${comp}_A}/TS_DA
136      eval R_BUF_${comp}_A_M=\${R_BUF_${comp}_A}/TS_MO
137      eval R_BUF_${comp}_A_Y=\${R_BUF_${comp}_A}/TS_YE
138
139      # Define CMIP6 Dirs
140      eval CMIP6_BUF_${comp}=${R_CMIP}/CMIP6/${comp}
141    fi
142
143    # Read UserChoices section of component card
144    IGCM_debug_Print 2 "DefineArrayFromSection : ${compname}_UserChoices ${card}"
145    IGCM_card_DefineArrayFromSection ${card} UserChoices
146    eval first_option=\${${compname}_UserChoices[0]} > /dev/null 2>&1
147
148    # If section is not empty we define corresponding variables
149    if [ X${first_option} != X"Error:" ] ; then
150      if [ X${card_UserChoices[0]} != X ] ; then
151        unset card_UserChoices
152      fi
153      eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1
154      IGCM_debug_Print 3 "${compname}_UserChoices_values:"
155      for option in ${card_UserChoices[*]} ; do
156        IGCM_card_DefineVariableFromOption ${card} UserChoices ${option}
157        eval IGCM_debug_Print 3 "${option}=\${${compname}_UserChoices_${option}}"
158      done
159    fi
160
161    # Read and Build Output File stuff
162    IGCM_debug_Print 2 "DefineArrayFromOption  : ${compname}_OutputFiles ${card}"
163    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
164    ListFilesName=${compname}_OutputFiles_List
165    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
166    #
167    if [ X${FileName0} != X${NULL_STR} ] ; then
168      #
169      #IGCM_debug_Print 1 "Component      : ${compname}"
170      #
171      # INITIALISATION
172      #
173      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
174      #
175      i=2
176      #
177      until [ $i -ge $NbFiles ]; do
178        #
179        eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1
180        #
181        if [ X${flag_post} != XNONE ] ; then
182          #
183          # First of all
184          #
185          IGCM_card_DefineArrayFromSection ${card} ${flag_post}
186          # This section is mandatory
187          if [ "X$( eval echo \${${compname}_${flag_post}[@]} )" = "X" ] ; then
188            IGCM_debug_Print 1 "IGCM_card_DefineArrayFromSection ${card} ${flag_post}"
189            IGCM_debug_Exit "${flag_post} section do not exist in ${card}. Please check your card."
190            IGCM_debug_Verif_Exit
191          fi
192          #
193          # Seasonal case : If option Seasonal is not found (old cards) put SEASONAL ON by default
194          #
195          # variable option allready typeset above
196          for option in $( eval echo \${${compname}_${flag_post}[*]} ) ; do
197            if [ ${option} = Seasonal ] ; then
198              FoundSeasonal=true
199              IGCM_card_DefineVariableFromOption ${card} ${flag_post} Seasonal
200            fi
201          done
202          #
203          if [ ! X${FoundSeasonal} = Xtrue ] ; then
204            eval ${compname}_${flag_post}_Seasonal=ON
205          fi
206          #
207          if [ $( eval echo \${${compname}_${flag_post}_Seasonal} ) = ON ] ; then
208            Seasonal=true
209          fi
210
211          # Dimension = vide si vieille card.
212          IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars
213          IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches
214          if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not" ] ; then
215            # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob.
216            ListDimension[0]=2D
217            ListDimension[1]=3D
218            TimeSeries=false
219            iLoop=${#ListDimension[*]}
220            j=0
221            until [ $j -ge ${iLoop} ]; do
222              Dimension=${ListDimension[${j}]}
223              IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension}
224              IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension}
225              #
226              # Time series WITHOUT chunk
227              #
228              if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
229                if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then
230                  IGCM_debug_Print 3 "${Dimension} time series activated for ${flag_post}"
231                  eval TimeSeries${Dimension}=true
232                fi
233              fi
234              #
235              # Time series WITH chunk
236              #
237              if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then
238                chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} )
239                if [ ! ${chunck_size} = NONE ] &&  [ ! ${chunck_size} = OFF ] ; then
240                  IGCM_debug_Print 3 "${Dimension} time series activated with chunck for ${flag_post}"
241                  eval TimeSeriesChunck${Dimension}=true
242                  eval CHUNCK${Dimension}_COMP[\${#CHUNCK${Dimension}_COMP[*]}]=${comp}
243                  eval CHUNCK${Dimension}_FLAG[\${#CHUNCK${Dimension}_FLAG[*]}]=${i}
244                  eval CHUNCK${Dimension}_NAME[\${#CHUNCK${Dimension}_NAME[*]}]=${flag_post}
245                  eval CHUNCK${Dimension}_SIZE[\${#CHUNCK${Dimension}_SIZE[*]}]=${chunck_size}
246                fi
247              fi
248              (( j=j+1 ))
249            done
250          else
251            ListDimension[0]=""
252            TimeSeries=true
253            TimeSeries2D=false
254            TimeSeries3D=false
255            TimeSeriesChunck2D=false
256            TimeSeriesChunck3D=false
257          fi
258        fi
259        (( i=i+3 ))
260      done
261    fi
262    # Debug Print
263    IGCM_debug_Print 3 "Initialize ${compname} with driver."
264    # INIT component
265    ${comp}_Initialize
266    echo
267  done
268
269  IGCM_debug_PopStack "IGCM_comp_Initialize"
270}
271
272#=======================================================================
273function IGCM_comp_PrepareDeletedFiles
274{
275  IGCM_debug_PushStack "IGCM_comp_PrepareDeletedFiles" $@
276
277  if [ X${2} != X. ] ; then
278    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${2} ) > /dev/null 2>&1
279  else
280    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${1} ) > /dev/null 2>&1
281  fi
282
283  IGCM_debug_PopStack "IGCM_comp_PrepareDeletedFiles"
284}
285
286#=======================================================================
287function IGCM_comp_PrepareXiosFiles
288{
289  IGCM_debug_PushStack "IGCM_comp_PrepareXiosFiles" $@
290
291  typeset file
292  [ X${2} != X. ] && file=$( basename ${2} ) || file=$( basename ${1} )
293
294  if [ $( echo ${file} | grep "^field_def_" | wc -l ) = 1 ] ; then
295    eval FieldDef[${#FieldDef[@]}]=${file} > /dev/null 2>&1
296  fi
297  if [ $( echo ${file} | grep "^file_def_" | wc -l ) = 1 ] ; then
298    eval FileDef[${#FileDef[@]}]=${file} > /dev/null 2>&1
299  fi
300  if [ $( echo ${file} | grep "^timeseries_def_" | wc -l ) = 1 ] ; then
301    eval FileDef[${#FileDef[@]}]=${file} > /dev/null 2>&1
302  fi
303 
304  IGCM_debug_PopStack "IGCM_comp_PrepareXiosFiles"
305}
306
307#=======================================================================
308function IGCM_comp_GetInputInitialStateFiles
309{
310  IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles"
311
312  # Debug Print :
313  echo
314  IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles"
315  echo
316
317  # Only the first time step need InitialStateFiles
318  # otherwise it's BoundaryConditions
319  if ( ${FirstInitialize} ) ; then
320    typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
321    typeset file_in_ file_in file_out_ file_out do_init
322    for comp in ${config_ListOfComponents[*]} ; do
323      # Initialize
324      do_init="y"
325      # Do we need to bring initial state file for this component
326      if ( [ "${config_Restarts_OverRule}" = "y" ] || [ "${config_Restarts_OverRule}" = "Y" ] ) ; then
327        eval do_init="n"
328      else
329        # Read component Restarts parameters
330        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
331        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
332        if [ "${do_start}" = "y" ] ; then
333          do_init="n"
334        else
335          do_init="y"
336        fi
337      fi
338
339      if [ "${do_init}" = "y" ] ; then
340        # Define component
341        eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
342        eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
343
344        # Debug Print :
345        IGCM_debug_Print 3 "Initialisation files ${compname}"
346
347        card=${SUBMIT_DIR}/COMP/${compname}.card
348
349        IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List
350        ListFilesName=${compname}_InitialStateFiles_List
351
352        eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
353        if [ X${FileName0} != X${NULL_STR} ] ; then
354          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
355          (( i=0 ))
356          until [ $i -ge $NbFiles ]; do
357            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
358            eval file_in=${file_in_}
359            (( i_ = i+1 ))
360            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
361            eval file_out=${file_out_}
362
363            IGCM_sys_IsFileArchived ${file_in}
364            if [ $? = 0 ] ; then
365                if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
366                        IGCM_sys_Cp_ensembleXIOS ${file_in} ${file_out} $1
367                else
368                        IGCM_sys_Get ${file_in} ${file_out}
369                fi
370              IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
371            else
372                if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
373                        IGCM_sys_Cp_ensembleXIOS ${file_in} ${file_out} $1
374                else
375                        IGCM_sys_Cp ${file_in} ${file_out}
376                fi
377            fi
378            (( i=i+2 ))
379          done
380        fi
381      fi
382    done
383  fi
384  IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles"
385}
386
387#=======================================================================
388# Definition of Smooth modulo function
389# usage :
390# IGCM_SmoothModulo StringModulo value
391#
392# StringModulo : A string of min max and modulo like definition of Scilab vectors.
393# [min]:[modulo:][max]
394# where :
395# [] value are optionnals;
396# empty min equal 1
397# empty max equal infinity
398# modulo not given or empty equal 1
399# empty string or just ':' equal always.
400#
401# value : the value to test with the definition
402#
403# return : true(1)/false(0)
404function IGCM_SmoothModulo
405{
406  IGCM_debug_PushStack "IGCM_SmoothModulo"
407  typeset defVector ModValue
408
409  eval set +A defVector -- $( echo "${1}" | \
410    gawk -F ':' '{print ($1 == "" ? 1 : $1) " " (NF==3 ? ($2 == "" ? 1 : $2) : 1) " " (NF==3 ? ($3 == "" ? -1 : $3) : ($2 == "" ? -1 : $2))}' )
411
412  # Save Smooth Min and Max. Needed to call IGCM_sys_Get when appropriate
413  arr[1]=${defVector[0]}
414  arr[2]=${defVector[2]}
415
416  # Test limits :
417  # ${defVector[0]} <= ${2} <= ${defVector[2]}
418  #          or ${defVector[2]} == -1
419  if ( [ ${2} -ge ${defVector[0]} ] && ( [ ${2} -le ${defVector[2]} ] || [ ${defVector[2]} -lt 0 ] ) ) ; then
420    # Test modulo
421    ModValue=$( expr \( ${2} - ${defVector[0]} \) % ${defVector[1]} )
422    if [ ${ModValue} -eq 0 ] ;  then
423      arr[3]=true
424      echo ${arr[@]}
425      IGCM_debug_PopStack "IGCM_SmoothModulo"
426      return 1
427    else
428      arr[3]=false
429      echo ${arr[@]}
430      IGCM_debug_PopStack "IGCM_SmoothModulo"
431      return 0
432    fi
433  else
434    arr[3]=false
435    echo ${arr[@]}
436    IGCM_debug_PopStack "IGCM_SmoothModulo"
437    return 0
438  fi
439}
440
441#=======================================================================
442function IGCM_comp_GetInputSmoothFiles
443{
444  IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles"
445
446  # Debug Print :
447  echo
448  IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles"
449  echo
450
451  typeset comp compname comptagname card ListFilesName FileName0 NbFiles j i i_ i__
452  typeset file_in_ file_in file_out_ file_out ret SmoothDef aux val
453
454  for comp in ${config_ListOfComponents[*]} ; do
455    # Define component
456    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
457    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
458
459    # Debug Print :
460    IGCM_debug_Print 3 "Smooth files ${compname}"
461
462    card=${SUBMIT_DIR}/COMP/${compname}.card
463
464    IGCM_card_DefineArrayFromOption ${card} SmoothFiles List
465    ListFilesName=${compname}_SmoothFiles_List
466    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
467
468    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != X"Section" ] ) ; then
469      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
470
471      (( i=0 ))
472      until [ $i -ge $NbFiles ]; do
473        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
474        eval file_in=${file_in_}
475        (( i_ = i+1 ))
476        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
477        eval file_out=${file_out_}
478
479        # define CumulPeriod definition for this file
480        (( i__ = i+2 ))
481        eval SmoothDef=\${${ListFilesName}[$i__]}
482        IGCM_debug_Print 3 "  ${file_in} ${SmoothDef}"
483        aux=$( IGCM_SmoothModulo ${SmoothDef} ${CumulPeriod} )
484        j=1
485        for val in ${aux} ; do
486          [ ${j} -eq 1 ] && SmoothMin=${val}
487          [ ${j} -eq 2 ] && SmoothMax=${val}
488          [ ${j} -eq 3 ] && ret=${val}
489          (( j=j+1 ))
490        done
491        [ ${SmoothMax} -eq -1 ] && SmoothMax=${CumulPeriod}
492        if ( [ X${ret} = Xtrue ] || ( [ ${Period} -eq 1 ] && [ ${CumulPeriod} -ge ${SmoothMin} ] && [ ${CumulPeriod} -le ${SmoothMax} ] ) ) ; then
493
494          IGCM_sys_IsFileArchived ${file_in}
495            if [ $? = 0 ] ; then
496                if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
497                        IGCM_sys_Cp_ensembleXIOS ${file_in} ${file_out} $1
498                else
499                        IGCM_sys_Get ${file_in} ${file_out}
500                fi
501              IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
502            else
503                if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
504                        IGCM_sys_Cp_ensembleXIOS ${file_in} ${file_out} $1
505                else
506                        IGCM_sys_Cp ${file_in} ${file_out}
507                fi
508            fi
509        fi
510        (( i=i+3 ))
511      done
512    fi
513  done
514
515  IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles"
516}
517
518#=======================================================================
519function IGCM_comp_GetInputBoundaryFiles
520{
521  IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles"
522
523  # Debug Print :
524  echo
525  IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles"
526  echo
527
528  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
529  typeset file_in_ file_in file_out_ file_out
530
531  if [ ${Period} = 1 ]; then
532    ListFixBoundary=" "
533  fi
534
535  for comp in ${config_ListOfComponents[*]} ; do
536
537    # Define component
538    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
539    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
540
541    # Debug Print :
542    IGCM_debug_Print 3 "Boundary files ${compname}"
543
544    card=${SUBMIT_DIR}/COMP/${compname}.card
545
546    IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List
547    ListFilesName=${compname}_BoundaryFiles_List
548    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
549
550    if [ X${FileName0} != X${NULL_STR} ] ; then
551      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
552
553      (( i=0 ))
554      until [ $i -ge $NbFiles ]; do
555        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
556        eval file_in=${file_in_}
557        (( i_ = i+1 ))
558        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
559        eval file_out=${file_out_}
560
561        IGCM_sys_IsFileArchived ${file_in}
562        if [ $? = 0 ] ; then
563            if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
564                    IGCM_sys_Cp_ensembleXIOS ${file_in} ${file_out} $1
565            else
566                    IGCM_sys_Get ${file_in} ${file_out}
567            fi
568            IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
569        else
570            if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
571                    IGCM_sys_Cp_ensembleXIOS ${file_in} ${file_out} $1
572            else
573                    IGCM_sys_Cp ${file_in} ${file_out}
574            fi
575        fi
576
577        (( i=i+2 ))
578      done
579    fi
580
581    # Get non deleted files
582    if [ ${Period} = 1 ]; then
583
584      IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel
585      ListFilesName=${compname}_BoundaryFiles_ListNonDel
586      eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
587
588      if [ X${FileName0} != X${NULL_STR} ] ; then
589        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
590
591        (( i=0 ))
592        until [ $i -ge $NbFiles ]; do
593          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
594          eval file_in=${file_in_}
595          (( i_ = i+1 ))
596          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
597          eval file_out=${file_out_}
598
599          IGCM_sys_IsFileArchived ${file_in}
600          if [ $? = 0 ] ; then
601              if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
602                      IGCM_sys_Cp_ensembleXIOS ${file_in} ${file_out} $1
603              else
604                      IGCM_sys_Get ${file_in} ${file_out}
605              fi
606              IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
607          else
608              if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
609                      IGCM_sys_Cp_ensembleXIOS ${file_in} ${file_out} $1
610              else
611                      IGCM_sys_Cp ${file_in} ${file_out}
612              fi
613          fi
614
615          if [ X${file_out} != X. ] ; then
616            ListFixBoundary=${ListFixBoundary}" "${file_out}
617          else
618            ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} )
619          fi
620
621          (( i=i+2 ))
622        done
623      fi
624    fi
625  done
626
627  IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles"
628}
629
630#=======================================================================
631function IGCM_comp_DelFixeBoundaryFiles
632{
633  IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles"
634
635  # Debug Print :
636  echo
637  IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles"
638  echo
639
640  ls -l ${ListFixBoundary}
641  rm -f ${ListFixBoundary}
642
643  IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles"
644}
645
646#=======================================================================
647function IGCM_comp_GetInputParametersFiles
648{
649  IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles"
650
651  # Debug Print :
652  echo
653  IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles"
654  echo
655
656  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out
657  for comp in ${config_ListOfComponents[*]} ; do
658    # Define component
659    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
660    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
661
662    # Initialize array hosting file_def and field_def files to check and/or modify
663    unset FieldDef
664    unset FileDef
665
666    # Debug Print :
667    IGCM_debug_Print 3 "Parameters ${compname}"
668
669    card=${SUBMIT_DIR}/COMP/${compname}.card
670
671    IGCM_card_DefineArrayFromOption ${card} ParametersFiles List
672    ListFilesName=${compname}_ParametersFiles_List
673    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
674
675    if [ X${FileName0} != X${NULL_STR} ] ; then
676      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
677
678      (( i=0 ))
679      until [ $i -ge $NbFiles ]; do
680        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
681        eval file_in=${file_in_}
682        (( i_ = i+1 ))
683        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
684        eval file_out=${file_out_}
685        if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
686                IGCM_sys_Cp_ensembleXIOS ${file_in} ${file_out} $1
687        else
688                IGCM_sys_Cp ${file_in} ${file_out}
689        fi
690        IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
691        IGCM_comp_PrepareXiosFiles    ${file_in} ${file_out}
692
693        (( i=i+2 ))
694      done
695    fi
696
697  done
698
699  IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles"
700}
701
702#=======================================================================
703function IGCM_comp_GetInputRestartFiles
704{
705  IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles"
706
707  # Debug Print :
708  echo
709  IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles"
710  echo
711
712  typeset Date_tmp Date_r Path_r do_start CompOldName Path_OUT Path_BUF
713  typeset Buffered Archived Tared PotentialTarFile IsMatching TarFileFound
714  typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_
715  typeset file_in file_out file_in_ file_out_ file_in_Name
716  typeset -Z4 j4
717  #BASH declare j4
718
719  IsMatching=""
720
721  for comp in ${config_ListOfComponents[*]} ; do
722    # Define component
723    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
724    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
725    #
726    card=${SUBMIT_DIR}/COMP/${compname}.card
727    #
728    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
729    ListFilesName=${compname}_RestartFiles_List
730    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
731
732    # Debug Print :
733    IGCM_debug_Print 3 "restart ${compname}"
734
735    if ( ${FirstInitialize} ) ; then
736
737      if ( [ "${config_Restarts_OverRule}" = "y" ] || [ "${config_Restarts_OverRule}" = "Y" ] ) ; then
738        # Adhoc exception for CMIP6 : exclude XIOS from the restart overrule mechanism.
739        if ( [ X${comp} = XIOS ] ) && ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then
740          CompOldName=IOS
741          config_IOS_Restart="n"
742          do_start="n"
743          config_IOS_RestartDate=-1
744          config_IOS_RestartJobName=${NULL_STR}
745          config_IOS_RestartPath=${NULL_STR}
746        else
747          eval config_${comp}_Restart="y"
748          eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
749          eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
750          eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
751          eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
752          eval CompOldName=${comp}
753        fi
754      else
755        # Read component Restarts parameters
756        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
757        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
758
759        if [ "${do_start}" = "y" ] ; then
760          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
761          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
762          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
763        else
764          eval config_${comp}_RestartDate=-1
765          eval config_${comp}_RestartJobName=${NULL_STR}
766          eval config_${comp}_RestartPath=${NULL_STR}
767        fi
768
769        eval CompOldName=\${config_${comp}_OldName}
770        if [ X${CompOldName} = X ] ; then
771          eval CompOldName=${comp}
772        fi
773
774        # Reinitialize IsMatching to allow searching for a different tar file for each component.
775        IsMatching=""
776        TarFileFound=""
777      fi
778
779      if [ "${do_start}" = "y" ] ; then
780
781        # Restore Restarts files
782        #-----------------------
783        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
784          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
785
786          (( i=1 ))
787          until [ $i -gt $NbFiles ]; do
788            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
789            eval file_in=${file_in_}
790            (( i_ = i+1 ))
791            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
792            eval file_out=${file_out_}
793
794            eval Date_tmp=\${config_${comp}_RestartDate}
795            Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
796            # will be re-use
797            eval RestartPath=\${config_${comp}_RestartPath}
798            eval RestartJobName=\${config_${comp}_RestartJobName}
799            #
800            Path_r=${RestartPath}/${RestartJobName}/${CompOldName}/Restart
801            file_in_Name=${RestartJobName}_${Date_r}_${file_in}
802
803            extension_in=$( echo ${file_in_Name##*.} )
804            extension_out=$( echo ${file_out##*.} )
805
806            generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
807            generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
808            Path_OUT=${Path_r}/${generic_restart_file_name_in}
809
810            path_restart_tmp=`dirname $Path_OUT`
811            base_restart_tmp=`basename $Path_OUT`
812
813            if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
814                        for (( pool_member_rank=0 ; pool_member_rank < $config_Ensemble_PoolSize ; pool_member_rank++ ))
815                        do
816                  whole_ensemble_rank=$(($config_Ensemble_PoolSize*$1+$pool_member_rank))
817                  Path_OUT="$path_restart_tmp/MEMBER_$whole_ensemble_rank/$base_restart_tmp"
818                  Path_r="$path_restart_tmp/MEMBER_$whole_ensemble_rank"
819                  cd MEMBER_$whole_ensemble_rank
820
821            if [ $( IGCM_sys_TestFileBuffer ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
822              IGCM_debug_Print 3 "Buffered restart ${Path_OUT}*.${extension_in} "
823              Buffered=true
824              Archived=false
825              Tared=false
826              nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_OUT}_????.${extension_in})
827            elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
828              IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
829              Buffered=false
830              Archived=true
831              Tared=false
832              nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
833            else
834              IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
835              IGCM_debug_Print 3 "${Path_OUT}*.${extension_in} do not exist"
836              IGCM_debug_Print 3 "Restart files will now be searched for in : ${RestartPath}/${RestartJobName}/RESTART"
837              Buffered=false
838              Archived=false
839              Tared=true
840              # Look after the tar file we want if we did not found it already
841              if [ X${IsMatching} = X ] ; then
842                IGCM_sys_TestDirArchive ${RestartPath}/${RestartJobName}/RESTART
843                if [ $? ] ; then
844                  for PotentialTarFile in $( IGCM_sys_RshArchive "find ${RestartPath}/${RestartJobName}/RESTART -name "${RestartJobName}_*restart*.tar" -print" ) ; do
845                    IsMatching=$( echo ${PotentialTarFile##*/} | \
846                      sed "s:_restart::" | \
847                      sed "s:^${RestartJobName}_::" | \
848                      sed "s:\.tar$::" | \
849                      gawk -F_ -v restartdate=${Date_r} \
850                      '{if (($1 <= restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
851                    if [ ! X${IsMatching} = X ] ; then
852                      TarFileFound=${PotentialTarFile}
853                      break
854                    fi
855                  done
856                fi
857                # Stop here if nothing has been found
858                if [ X${TarFileFound} = X ] ; then
859                  IGCM_debug_Print 3 "Restart files were not found!"
860                  IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
861                  IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
862                  IGCM_debug_Exit "Please double check restart settings in config.card"
863                  IGCM_debug_Verif_Exit
864                fi
865              fi
866              IGCM_sys_PrepareTaredRestart ${TarFileFound}
867              TarFileLocation=$( basename ${TarFileFound} )
868              IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
869              tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
870              nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
871            fi
872
873            if [ ${nb_restart_file} -gt 1 ] ; then
874              j=0                                      # BASH LINE NOT NEEDED
875              # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
876              until [ $j -ge ${nb_restart_file} ]; do  # BASH LINE NOT NEEDED
877                j4=${j}                                # BASH LINE NOT NEEDED
878                if [ X${Buffered} = Xtrue ] ; then
879                  IGCM_sys_GetBuffer ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
880                elif [ X${Archived} = Xtrue ] ; then
881                  IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
882                elif [ X${Tared} = Xtrue ] ; then
883                  IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
884                fi
885                (( j=j+1 ))                            #BASH LINE NOT NEEDED
886              done
887
888              # OCE SPECIFIC TO REBUILD RESTART WHEN NUMBER OF RESTART FILES DONT MATCH MPI PROCESS
889              if [ X${OCE_PROC_MPI} != X ] ; then
890                if [ ${OCE_PROC_MPI} -ne ${nb_restart_file} ] ; then
891                  IGCM_sys_rebuild_nemo ${generic_restart_file_name_out} ${nb_restart_file} ${extension_out} ${generic_restart_file_name_out}_????.${extension_out}
892                  IGCM_sys_Rm ${generic_restart_file_name_out}_????.${extension_out}
893                fi
894              fi
895            else
896              if [ X${Buffered} = Xtrue ] ; then
897                IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
898              elif [ X${Archived} = Xtrue ] ; then
899                IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
900              elif [ X${Tared} = Xtrue ] ; then
901                IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
902              fi
903            fi
904            cd ..
905            done
906            fi
907            (( i=i+3 ))
908          done
909        else
910          if [ X${FileName0} != XNONE ] ; then
911            IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
912          else
913            IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
914          fi
915        fi
916      fi
917    elif ( [ ${Period} -eq 1 ] && [ ${DRYRUN} -eq 0 ] ) ; then
918      # if not FirstInitialize and first loop of this job
919
920      # Restore Restarts files
921      #-----------------------
922      if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
923        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
924
925        index_j=0
926        for index_member in $(cut -d: -f2 ${SUBMIT_DIR}/ensemble.txt); do
927            member[$index_j]=$index_member
928            index_j=$index_j+1
929        done
930
931        (( i=1 ))
932        until [ $i -gt $NbFiles ]; do
933          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
934          eval file_in=${file_in_}
935          (( i_ = i+1 ))
936          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
937          eval file_out=${file_out_}
938
939          file_in_Name=${config_UserChoices_JobName}_${LastPeriodDateEnd}_${file_in}
940
941          extension_in=$( echo ${file_in_Name##*.} )
942          extension_out=$( echo ${file_out##*.} )
943
944          generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
945          generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
946
947          eval Path_BUF=\${R_BUF_${comp}_R}/${generic_restart_file_name_in}
948          eval Path_OUT=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
949
950          if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
951              path_restart_tmp=`dirname $Path_BUF`
952              base_restart_tmp=`basename $Path_BUF`
953
954             for (( pool_member_rank=0 ; pool_member_rank < $config_Ensemble_PoolSize ; pool_member_rank++ ))
955             do
956              whole_ensemble_rank=$(($config_Ensemble_PoolSize*$1+$pool_member_rank))   
957              Path_BUF=$path_restart_tmp/MEMBER_${member[$whole_ensemble_rank]}/$base_restart_tmp
958              Path_r=$path_restart_tmp/MEMBER_${member[$whole_ensemble_rank]}
959              cd MEMBER_$whole_ensemble_rank
960
961
962          if [ $( IGCM_sys_TestFileBuffer ${Path_BUF}*.${extension_in} ; echo $? ) = 0 ] ; then
963            IGCM_debug_Print 3 "Buffered restart ${Path_BUF}*.${extension_in}"
964            Buffered=true
965            Archived=false
966            Tared=false
967            nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_BUF}_????.${extension_in})
968          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
969            IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
970            Buffered=false
971            Archived=true
972            Tared=false
973            nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
974          else
975            IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
976            IGCM_debug_Print 3 "Restart files will now be searched for in : ${R_SAVE}/RESTART"
977            Buffered=false
978            Archived=false
979            Tared=true
980            # Look after the tar file we want if we did not found it already
981            if [ X${IsMatching} = X ] ; then
982              for PotentialTarFile in $( IGCM_sys_RshArchive "find ${R_SAVE}/RESTART -name "${config_UserChoices_JobName}_*_restart.tar" -print" ) ; do
983                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}}' )
984                if [ ! X${IsMatching} = X ] ; then
985                  TarFileFound=${PotentialTarFile}
986                  break
987                fi
988              done
989            fi
990            # Stop here if nothing has been found
991            if [ X${TarFileFound} = X ] ; then
992              IGCM_debug_Print 3 "Restart files were not found!"
993              IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
994              IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
995              IGCM_debug_Exit "Please double check restart settings in config.card"
996              IGCM_debug_Verif_Exit
997            fi
998            IGCM_sys_PrepareTaredRestart ${TarFileFound}
999            TarFileLocation=$( basename ${TarFileFound} )
1000            IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
1001            tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
1002            nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
1003          fi
1004
1005          if [ ${nb_restart_file} -gt 1 ] ; then
1006            j=0                                     # BASH LINE NOT NEEDED
1007            #BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
1008            until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
1009              j4=${j}                               # BASH LINE NOT NEEDED
1010              if [ X${Buffered} = Xtrue ] ; then
1011                IGCM_sys_GetBuffer ${Path_BUF}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
1012              elif [ X${Archived} = Xtrue ] ; then
1013                IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
1014              elif [ X${Tared} = Xtrue ] ; then
1015                IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
1016              fi
1017              (( j=j+1 ))                           # BASH LINE NOT NEEDED
1018            done
1019          else
1020            if [ X${Buffered} = Xtrue ] ; then
1021              eval IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
1022            elif [ X${Archived} = Xtrue ] ; then
1023              eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
1024            elif [ X${Tared} = Xtrue ] ; then
1025              IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
1026            fi
1027          fi
1028            cd ..
1029            done
1030            fi
1031          (( i=i+3 ))
1032        done
1033      else
1034        if [ X${FileName0} != XNONE ] ; then
1035          IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
1036        else
1037          IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
1038        fi
1039      fi
1040    fi
1041  done
1042
1043  NbFiles=$( ls * 2> /dev/null | wc -l )
1044  if [ ${NbFiles} -gt 0 ] ; then
1045    IGCM_sys_Chmod u+rw *
1046  fi
1047
1048  IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
1049}
1050
1051#=======================================================================
1052function IGCM_comp_GetInputBinaryFiles
1053{
1054  IGCM_debug_PushStack "IGCM_comp_GetInputBinaryFiles"
1055
1056  # Debug Print :
1057  echo
1058  IGCM_debug_Print 1 "IGCM_comp_GetInputBinaryFiles"
1059  echo
1060
1061  # Clean up previous pass
1062  [ -f ${RUN_DIR}/compiler.txt ] && rm -f ${RUN_DIR}/compiler.txt
1063
1064  typeset comp ExeNameIn ExeNameOut byPass
1065  typeset compilerNmbr compilerUnit compilerFull
1066  byPass=false
1067  for comp in ${config_ListOfComponents[*]} ; do
1068    # Define component
1069
1070    # Copy executable for this component
1071    eval ExeNameIn=\${config_Executable_${comp}[0]}
1072    eval ExeNameOut=\${config_Executable_${comp}[1]}
1073    # Test if missing executable and DRYRUN is set to 0 or 1, then stop!
1074    if [ ${DRYRUN} -le 1 ] && [ X${ExeNameIn} != X\"\" ] ; then
1075        # The executable is set in config.card and is different from ""
1076        # Use eval to expand ExeNameIn if variables are used in the name
1077        eval ExeNameIn=${ExeNameIn}
1078        if [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
1079            IGCM_debug_Exit "IGCM_comp_GetInputBinaryFiles missing executable ${ExeNameIn}"
1080        fi
1081    fi
1082
1083    if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
1084      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1085      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1086        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1087      fi
1088    elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
1089      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1090      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1091        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1092      fi
1093    fi
1094
1095    if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1096      # Get the compiler version
1097      compilerFull=$( strings ${RUN_DIR}/${ExeNameOut}  | grep "RTL Message Catalog" | gawk '{print $6}' | gawk -F. '{print $1}' )
1098      compilerVersion=$( strings ${RUN_DIR}/${ExeNameOut}  | grep "RTL Message Catalog" | gawk '{print $6}' | gawk -F. '{print $1}' )
1099      # Save it
1100      echo $compilerFull >> ${RUN_DIR}/compiler.txt
1101      [ X${compilerFull} = X ] && byPass=true
1102      IGCM_debug_Print 1 "${RUN_DIR}/${ExeNameOut} has been compiled with ${compilerFull}"
1103      IGCM_debug_Print 1 "Compiler is ${compilerVersion}"
1104    fi
1105  done
1106
1107  compilerNmbr=$( cat ${RUN_DIR}/compiler.txt | wc -l )
1108  compilerUnit=$( cat ${RUN_DIR}/compiler.txt | sort | uniq -c )
1109
1110  if ( [ ${compilerNmbr} -ne ${compilerUnit} ] && [ ! X${byPass} = Xtrue  ] ); then
1111    IGCM_debug_Exit "Binaries has not been compiled with the same compiler version"
1112  fi
1113
1114# Test on compiler version for IPSLCM6* configuration on irene (only for CMIP6 production)
1115  if [ ${SYSTEM} = irene ]; then
1116    if ( [ X"$( echo ${config_UserChoices_LongName} | grep IPSLCM6.0.13 )" != "X" ] && [ X${compilerFull} != XV17 ] )  || ( [ X"$( echo ${config_UserChoices_LongName} | grep IPSLCM6.0.14 )" != "X" ] && [ X${compilerFull} != XV17 ] ) || ( [ X"$( echo ${config_UserChoices_LongName} | grep IPSLCM6.0.15 )" != "X" ] && [ X${compilerFull} != XV17 ] ) || ( [ X"$( echo ${config_UserChoices_LongName} | grep IPSLCM6.1 )" != "X" ] && [ X${compilerFull} != XV17 ] ) || ( [ X"$( echo ${config_UserChoices_LongName} | grep IPSLCM5A2.1 )" != "X" ] && [ X${compilerFull} != XV17 ] ) ; then
1117      IGCM_debug_Exit "IPSLCM6.0.13, IPSLCM6.0.14, IPSLCM6.0.15, IPSLCM6.1 and IPSLCM5A2.1 must be compiled with intel 2017 compiler"
1118    fi
1119  fi
1120
1121  IGCM_debug_PopStack "IGCM_comp_GetInputBinaryFiles"
1122}
1123
1124#=======================================================================
1125function IGCM_comp_PeriodStart
1126{
1127  IGCM_debug_PushStack "IGCM_comp_PeriodStart"
1128
1129  # Debug Print :
1130  echo
1131  IGCM_debug_Print 1 "IGCM_comp_PeriodStart"
1132  echo
1133
1134  typeset ExeNameIn ExeNameOut
1135  typeset comp compname comptagname
1136  for comp in ${config_ListOfComponents[*]} ; do
1137    # Define component
1138    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1139    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1140
1141    # Copy executable for this component
1142    eval ExeNameIn=\${config_Executable_${comp}[0]}
1143    eval ExeNameIn=${ExeNameIn}
1144    eval ExeNameOut=\${config_Executable_${comp}[1]}
1145
1146    # Debug Print
1147    IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
1148    # UPDATE component
1149    ${comp}_PeriodStart 2> /dev/null
1150
1151  done
1152
1153  IGCM_debug_PopStack "IGCM_comp_PeriodStart"
1154}
1155
1156
1157
1158#=======================================================================
1159function IGCM_comp_modifyFile
1160{
1161#
1162# syntax:     IGCM_comp_modifyFile  filein  key  [value]
1163#
1164# For example : IGCM_comp_modifyFile metrics_template.py case_id \'SE_${YEARS}\'
1165#
1166# This function is used to replace a pattern in a file for a specific variable.
1167#
1168# Arguments:
1169# - filein : the file in run directory in which the variable should be set
1170# - key    : the variable to modify
1171# - value  : the value to set the key equal to
1172#
1173  IGCM_debug_PushStack "IGCM_comp_modifyFile"
1174
1175  typeset filein key value pattern
1176
1177  # Set local variables and test the arguments
1178  if [ $# = 3 ] ; then
1179    # Normal case with 3 arguments
1180    filein=$1 ; key=$2 ; value=$3
1181  else
1182    IGCM_debug_Exit "IGCM_comp_modifyFile: Bad number of arguments."
1183    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1184    return
1185  fi
1186  IGCM_debug_Print 1 "Entering IGCM_comp_modifyFile with arguments: ${filein} ${key} ${value}"
1187
1188  # Test if the file exist
1189  if [ ! -f ${filein} ] ; then
1190    IGCM_debug_Exit "IGCM_comp_modifyFile: ${filein} does not exist."
1191    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1192    return
1193  fi
1194
1195  # Read the line with key in the file without the comments
1196  pattern=$( grep "^ *${key} *=" ${filein} | sed -e "s% *\!.*%%" )
1197
1198  # Verify the existance of the pattern
1199  if [ X"${pattern}" = X ] ; then
1200    # Variable key is not set in filein, stop.
1201    IGCM_debug_Exit "IGCM_comp_modifyFile : Variable ${key} is not set in correct file. It should be set in ${filein}."
1202    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1203    return
1204  fi
1205
1206  # Now change key in filein
1207  #sed -e "s:${pattern}:${key}=${value}:" ${filein} > ${filein}.tmp
1208  sed -e "s:^ *${key} *=.*:${key}=${value}:" ${filein} > ${filein}.tmp
1209  IGCM_debug_Print 1 "IGCM_comp_modifyFile: In ${filein} set ${key}=${value}"
1210  \mv ${filein}.tmp ${filein}
1211 
1212  IGCM_debug_PopStack "IGCM_comp_modifyFile"
1213}
1214
1215#=======================================================================
1216function IGCM_comp_modifyDefFile
1217{
1218#
1219# syntax:     IGCM_comp_modifyDefFile  type  filein  key  [value]
1220#
1221# For example : IGCM_comp_modifyDefFile blocker run.def day_step 1200
1222#
1223# This function is used to modify a parameter file for a specific variable.
1224# The file must be a ".def" file, i.e. with IOIPSL parameter file syntax.
1225# This function can be used in the comp.driver files for the components.
1226#
1227# Arguments:
1228# - type   : first argument must be blocker, nonblocker or force
1229#            For "blocker" case, the variable must be attributed the keyworld AUTO
1230#            otherwise this function will exit.
1231#            For "nonblocker" case, the user can remove or modify the variable. For
1232#            this case, as long as AUTO is not set, no modification will be done.
1233#            For "force" case, the variable will be modified even if it is not set to AUTO
1234# - filein : the file in run directory of .def type in which the variable should be set
1235# - key    : the variable to modify
1236# - value  : the value to set the key equal to, optional. If value is not set or if
1237#            value=DEFAULT, then a default value must be given in filein using syntax :
1238#            key= AUTO : DEFAULT=def_value
1239#
1240  IGCM_debug_PushStack "IGCM_comp_modifyDefFile"
1241
1242  typeset type filein key value
1243  typeset filelist nb_occ modify
1244
1245  # Set local variables and test the arguments
1246  if [ $# = 4 ] ; then
1247    # Normal case with 4 arguments
1248    type=$1 ; filein=$2 ; key=$3 ; value=$4
1249  elif [ $# = 3 ] ; then
1250    # Normal case with 3 arguments
1251    type=$1 ; filein=$2 ;       key=$3; value="DEFAULT"
1252  else
1253    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Bad number of arguments."
1254    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1255    return
1256  fi
1257  IGCM_debug_Print 1 "Entering IGCM_comp_modifyDefFile with arguments: ${type} ${filein} ${key} ${value}"
1258
1259  # Test if first argument is correct
1260  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1261    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Error in first argument must be blocker, nonblocker or force"
1262    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1263    return
1264  fi
1265
1266  # Test if the file exist.
1267  # Exit with error if the file does not exist for the case blocker or force.
1268  # Only return for the case nonblocker.
1269  if [ ! -f ${filein} ] ; then
1270    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1271      IGCM_debug_Exit "IGCM_comp_modifyDefFile: ${filein} does not exist."
1272    else
1273      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${filein} does not exist. Nothing will be done for this file."
1274    fi
1275    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1276    return
1277  fi
1278
1279  # Define list of files to test using all files with suffix .def (except used*.def)
1280  filelist=$( ls *def | grep -v used )
1281
1282  # Count number of occurances for the key in all files
1283  nb_occ=$( grep -w ${key} ${filelist} | grep -v "#"  | wc -l )
1284
1285  # Test if key is set several times
1286  if [ ${nb_occ} -gt 1 ] ; then
1287    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in ${filein}: Variable=${key} is set ${nb_occ} times"
1288    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1289    return
1290  fi
1291
1292  # Treatement according to different cases
1293  if [ ${nb_occ} -eq 0 ] && [ ${type} = blocker ] ; then
1294    # Stop if the key is never set and the function is blocker
1295    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in ${filein}: Variable=${key} has been removed but this function is blocker. "
1296    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: restore ${filein} for variable ${key}."
1297  elif [ ${nb_occ} -eq 0 ] && [ ${type} = nonblocker ] ; then
1298    # The key is not set but it is a nonblocker call so nothing is done.
1299    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key} is not set in ${filein}. This is a nonblocker call so nothing is done."
1300    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: Default value for ${key} from the model will be used."
1301    modify=no
1302  elif [ $( grep ${key} ${filein} | grep -v "\#"  |wc -l ) = 0 ] ; then
1303    # Variable key is not set in filein, stop.
1304    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Variable ${key} is not set in correct file. It should be set in ${filein}."
1305  fi
1306
1307  # Check if AUTO is set in the filein on the same line as the key variable
1308  if [ $( grep -w ${key} ${filein} | grep -v "\#" | grep AUTO | wc -l ) = 1 ] ; then
1309    # Modification will be done for all cases
1310    modify=yes
1311  else
1312    # The variable was not set to AUTO
1313    if [ ${type} = blocker ] ; then
1314      # Exit because this is a blocker call
1315      IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable ${key} cannot be modified. It should be set to AUTO."
1316      IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1317      return
1318    elif [ ${type} = nonblocker ] ; then
1319      # Do nothing. Suppose that the user did set the variable correct
1320      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key} is set by the user. Nothing done."
1321      modify=no
1322    elif [ ${type} = force ] ; then
1323      # Force modification
1324      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile : Variabl=${key} was not set to AUTO. Modification will be forced."
1325      modify=yes
1326    fi
1327  fi
1328
1329  # Do the modifcation now
1330  if [ ${modify} = yes ] ; then
1331
1332    # For option DEFAULT, read default value from file.
1333    if [ X"${value}" = XDEFAULT ] || [ X"${value}" = X ] ; then
1334      # Case to set DEFAULT value
1335      # Read default value from filein
1336      value=$( grep -w ${key} ${filein} | grep -v "\#" | awk  -F"DEFAULT *=" '{print $2}')
1337
1338      if [ X"${value}" = X ] ; then
1339        IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable ${key} needs a DEFAULT value in ${filein}."
1340        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: The syntax in ${filein} should be:"
1341        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key}=_AUTO_:DEFAULT=def_value"
1342        IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1343        return
1344      fi
1345    fi
1346
1347    # Now change key in filein
1348    sed -e "s/^${key}\ *=.*/${key}= ${value}/" ${filein} > ${filein}.tmp
1349    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: In ${filein} set ${key}=${value}"
1350    \mv ${filein}.tmp ${filein}
1351  fi
1352  IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1353}
1354
1355#=======================================================================
1356function IGCM_comp_modifyNamelist
1357{
1358#
1359# syntax:     IGCM_comp_modifyNamelist  type  filein  key  [value]
1360#
1361# For example : IGCM_comp_modifyNamelist blocker run.def day_step 1200
1362#
1363# This function is used to modify a parameter file for a specific variable.
1364# The file must be a "namelist" file, i.e. with fortran namelist syntax.
1365# This function can be used in the comp.driver files for the components.
1366#
1367# Arguments:
1368# - type   : first argument must be blocker, nonblocker or force
1369#            For "blocker" case, the variable must be attributed the keyworld AUTO
1370#            otherwise this function will exit.
1371#            For "nonblocker" case, the user can remove or modify the variable. For
1372#            this case, as long as AUTO is not set, no modification will be done.
1373#            For "force" case, the variable will be modified even if it is not set to AUTO
1374# - filein : the file in run directory of .def type in which the variable should be set
1375# - key    : the variable to modify
1376# - value  : the value to set the key equal to, optional. If value is not set or if
1377#            value=DEFAULT, then a default value must be given in filein using syntax :
1378#            key= AUTO : DEFAULT=def_value
1379#
1380  IGCM_debug_PushStack "IGCM_comp_modifyNamelist"
1381
1382  typeset type filein key value pattern modify
1383
1384  # Set local variables and test the arguments
1385  if [ $# = 4 ] ; then
1386    # Normal case with 4 arguments
1387    type=$1 ; filein=$2 ; key=$3 ; value=$4
1388  elif [ $# = 3 ] ; then
1389    # Normal case with 3 arguments
1390    type=$1 ; filein=$2 ;       key=$3; value="DEFAULT"
1391  else
1392    IGCM_debug_Exit "IGCM_comp_modifyNamelist: Bad number of arguments."
1393    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1394    return
1395  fi
1396  IGCM_debug_Print 1 "Entering IGCM_comp_modifyNamelist with arguments: ${type} ${filein} ${key} ${value}"
1397
1398  # Test if first argument is correct
1399  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1400    IGCM_debug_Exit "IGCM_comp_modifyNamelist: Error in first argument must be blocker, nonblocker or force"
1401    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1402    return
1403  fi
1404
1405  # Test if the file exist.
1406  # Exit with error if the file does not exist for the case blocker or force.
1407  # Only return for the case nonblocker.
1408  if [ ! -f ${filein} ] ; then
1409    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1410      IGCM_debug_Exit "IGCM_comp_modifyNamelist: ${filein} does not exist."
1411    else
1412      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${filein} does not exist. Nothing will be done for this file."
1413    fi
1414    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1415    return
1416  fi
1417
1418  # Read the line with key in the file without the comments
1419  pattern=$( grep "^ *${key} *=" ${filein} | sed -e "s% *\!.*%%" )
1420
1421  # Verify the existance of the pattern
1422  if [ X"$pattern" = X ] ; then
1423    # Variable key is not set in filein, stop.
1424    IGCM_debug_Exit "IGCM_comp_modifyNamelist : Variable ${key} is not set in correct file. It should be set in ${filein}."
1425    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1426    return
1427  fi
1428
1429  # Check if the variable is set to AUTO in the filein
1430  if [ $( echo $pattern | grep AUTO | wc -l ) = 1 ] ; then
1431    # Modification will be done for all cases
1432    modify=yes
1433  else
1434    # The variable was not set to AUTO
1435    if [ ${type} = blocker ] ; then
1436      # Exit because this is a blocker call
1437      IGCM_debug_Exit "IGCM_comp_modifyNamelist : The variable ${key} cannot be modified. It should be set to AUTO."
1438      IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1439      return
1440    elif [ ${type} = nonblocker ] ; then
1441      # Do nothing. Suppose that the user did set the variable correct
1442      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${key} is set by the user. Nothing done."
1443      modify=no
1444    elif [ ${type} = force ] ; then
1445      # Force modification
1446      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist : Variabl=${key} was not set to AUTO. Modification will be forced."
1447      modify=yes
1448    fi
1449  fi
1450
1451  # Do the modifcation now
1452  if [ ${modify} = yes ] ; then
1453
1454    # For option DEFAULT, read default value from file.
1455    if [ X"${value}" = XDEFAULT ] || [ X"${value}" = X ] ; then
1456      # Case to set DEFAULT value
1457      # Read default value from filein
1458      value=$( echo $pattern | awk  -F"DEFAULT *=" '{print $2}')
1459
1460      if [ X"${value}" = X ] ; then
1461        IGCM_debug_Exit "IGCM_comp_modifyNamelist : The variable ${key} needs a DEFAULT value in ${filein}."
1462        IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: The syntax in ${filein} should be:"
1463        IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${key}=_AUTO_:DEFAULT=def_value"
1464        IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1465        return
1466      fi
1467    fi
1468
1469    # Now change key in filein
1470    sed -e "s/${pattern}/       ${key}=${value}/" ${filein} > ${filein}.tmp
1471    IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: In ${filein} set ${key}=${value}"
1472    \mv ${filein}.tmp ${filein}
1473  fi
1474  IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1475}
1476
1477#=======================================================================
1478function IGCM_comp_modifyXmlFile
1479{
1480#
1481# syntax:     IGCM_comp_modifyXmlFile  type  filein  keyid  keyattrib  value
1482#
1483# For example : IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba2 enabled .TRUE.
1484#          or   IGCM_comp_modifyXmlFile blocker iodef.xml using_server NONE false
1485#
1486# This function is used to modify the value for a specific attribute and variable id.
1487# The file must be a valid xml file.
1488# This function can be used in the comp.driver files for the components.
1489#
1490# Arguments:
1491# - type      : first argument must be blocker, nonblocker or force.
1492#               For "blocker" case, the variable must be attributed the keyworld AUTO
1493#               otherwise this function will exit.
1494#               For "nonblocker" case, the user can remove or modify the variable. For
1495#               this case, as long as AUTO is not set, no modification will be done.
1496#               For "force" case, the variable will be modified even if it is not set to AUTO
1497# - filein    : the file in run directory of .xml type in which the variable should be set
1498# - keyid     : the variable to modify
1499# - keyattrib : the attribute name to modify. If NONE, then the variable itself will be modified
1500# - value     : the value to set in the filein
1501#
1502  IGCM_debug_PushStack "IGCM_comp_modifyXmlFile"
1503
1504  typeset type filein keyid keyattrib value modify
1505
1506  # Set local variables and test the arguments
1507  if [ $# = 5 ] ; then
1508    # Normal case with 4 arguments
1509    type=$1 ; filein=$2 ; keyid=$3 ; keyattrib=$4 ; value=$5
1510  else
1511    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Bad number of arguments."
1512    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1513    return
1514  fi
1515  IGCM_debug_Print 1 "Entering IGCM_comp_modifyXmlFile with arguments: type=${type} file=${filein}, id=${keyid} attribute=${keyattrib}, value=${value}"
1516
1517  # Test if first argument is correct
1518  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1519    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Error in first argument must be blocker, nonblocker or force"
1520    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1521    return
1522  fi
1523
1524  # Test if the file exist.
1525  # Exit with error if the file does not exist for the case blocker or force.
1526  # Only return for the case nonblocker.
1527  if [ ! -f ${filein} ] ; then
1528    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1529      IGCM_debug_Exit "IGCM_comp_modifyXmlFile: ${filein} does not exist."
1530    else
1531      IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile: ${filein} does not exist. Nothing will be done for this file."
1532    fi
1533    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1534    return
1535  fi
1536
1537  # Test if keyid is set in filein. If not exit for case all cases(blocker, force) except nonblocker.
1538  if [ $( grep -w ${keyid} ${filein} | wc -l ) = 0 ] ; then
1539      if [ ${type} = nonblocker ] ; then
1540          # This is a nonblocker case, print warning but do nothing else
1541          IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile: ${keyid} is not set in ${filein}. This is a nonblocker call so nothing is done."
1542      else
1543          # This is a blocker or force case : stop now
1544          IGCM_debug_Exit "IGCM_comp_modifyXmlFile : ${keyid} is not set in the file. Bad syntax of ${filein} file."
1545          IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1546          return
1547      fi
1548  fi
1549
1550  # Check if AUTO is set on the same line as keyid and keyattrib
1551  if [  $( grep -w ${keyid} ${filein} | grep AUTO | wc -l ) = 1 ] ; then
1552    # Modification will be done
1553    modify=yes
1554  else
1555    if [ ${type} = blocker ] ; then
1556      # Exit, the variable must be set to AUTO
1557      IGCM_debug_Exit "IGCM_comp_modifyXmlFile : blocker function. The ${keyattrib} for ${keyid} must be set to AUTO in ${filein}."
1558      IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1559      return
1560    elif [ ${type} = nonblocker ] ; then
1561      # Nothing will be done
1562      IGCM_debug_Print 1 "Nonblocker nothing is done for ${filein}, id=${keyid} and attribute ${keyattrib}"
1563      modify=no
1564    elif [ ${type} = force ] ; then
1565      # Force modification
1566      IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile : Attribute=${keyattrib} for id=${keyid} was not set to AUTO. Modification will be forced."
1567      modify=yes
1568    fi
1569  fi
1570
1571  # Do the modifcation now
1572  if [ ${modify} = yes ] ; then
1573    if [ ${keyattrib} = NONE ] ; then
1574      # Case to modify the variable itself
1575      IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting the variable=${value}"
1576      sed -e "s/\(<[^\"]*\"${keyid}\".*>\)\([^<]*\)\(<[^>]*\)/\1${value}\3/" ${filein} > ${filein}.tmp
1577    else
1578      # Check if keyattrib is set on the same line as keyid
1579      if [  $( grep -w ${keyid} ${filein} | grep ${keyattrib} | wc -l ) = 1 ] ; then
1580        # Case to modify the attribute value
1581        IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting attribute to ${keyattrib}=${value}"
1582        sed -e "/id=\"${keyid}\"/s/\(${keyattrib}=\"\)[^\"]*\(\"\)/\1${value}\2/" ${filein} > ${filein}.tmp
1583      else
1584        # Case to add the attribute and its value
1585        IGCM_debug_Print 1 "Now add in ${filein} for id=${keyid} the attribute ${keyattrib} to the value ${value}"
1586        sed -e "/id=\"${keyid}\"/s/\/>/ ${keyattrib}=\"${value}\"\/>/" ${filein} > ${filein}.tmp
1587      fi
1588    fi
1589    \mv ${filein}.tmp ${filein}
1590  fi
1591  IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1592}
1593
1594#=======================================================================
1595function IGCM_comp_Update
1596{
1597  IGCM_debug_PushStack "IGCM_comp_Update"
1598
1599  # Debug Print :
1600  echo
1601  IGCM_debug_Print 1 "IGCM_comp_Update"
1602  echo
1603  if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
1604   cd ENSEMBLE_TEMPLATE
1605  fi
1606
1607  typeset comp compname comptagname
1608  for comp in ${config_ListOfComponents[*]} ; do
1609    # Define component
1610    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1611    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1612
1613    # Debug Print
1614    IGCM_debug_Print 1 "Update ${compname} Parameter Files."
1615    # UPDATE component
1616    ${comp}_Update
1617
1618    # Read TimeSeries information from XML files, prepare TS directories and do modifications in timeseries_def_${compname}.xml
1619    if [ -f timeseries_def_${compname}.xml ]; then
1620      ${libIGCM}/libIGCM_post/xios_parser.py tsquery --file timeseries_def_${compname}.xml > ts.temp.${compname}.txt
1621      for line in $( cat ts.temp.${compname}.txt ); do
1622        output_freq=$( echo ${line} | awk -F "," '{print $1}' | awk -F "=" '{print $2}' )
1623        id=$(          echo ${line} | awk -F "," '{print $2}' | awk -F "=" '{print $2}' )
1624        case ${output_freq} in
1625        *Y|*y)
1626          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_Y}
1627          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_Y}/${config_UserChoices_JobName}
1628          ;;
1629        *MO|*mo)
1630          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_M}
1631          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_M}/${config_UserChoices_JobName}
1632          ;;
1633        *D|*d)
1634          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_D}
1635          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_D}/${config_UserChoices_JobName}
1636          ;;
1637        *S|*s)
1638          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_H}
1639          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_H}/${config_UserChoices_JobName}
1640          ;;
1641        esac
1642      done
1643    fi
1644
1645    # Read TimeSeries information from XML files, prepare CMIP6 TS directories and do modifications in dr2xml_${compname}.xml
1646    if [ -f dr2xml_${compname}.xml ]; then
1647      if ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then
1648        eval IGCM_sys_Mkdir \${CMIP6_BUF_${comp}}
1649        eval CMIP6_DIR=\${CMIP6_BUF_${comp}}
1650        # Modify path from dr2xml_{compname}.xml
1651        if [ X${config_Post_dr2xmlIPSL} = XTRUE ]; then
1652          ${libIGCM}/libIGCM_post/xios_parser.py -v modifydr2xmlIPSL --newPath ${CMIP6_DIR} --splitLastDate ${EndYear_p1} --JobName ${config_UserChoices_JobName} --ModelName ${config_UserChoices_ModelName} --ModelVersion ${config_UserChoices_LongName} --file dr2xml_${compname}.xml
1653        else
1654          ${libIGCM}/libIGCM_post/xios_parser.py -v modifyPath --newPath ${CMIP6_DIR} --file dr2xml_${compname}.xml
1655        fi
1656        # Overwrite the original file
1657        IGCM_sys_Mv modified.dr2xml_${compname}.xml dr2xml_${compname}.xml
1658      fi
1659    fi
1660  done
1661  if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
1662   cd ..
1663  fi
1664
1665
1666  IGCM_debug_PopStack "IGCM_comp_Update"
1667}
1668
1669#=======================================================================
1670function IGCM_comp_Finalize
1671{
1672  IGCM_debug_PushStack "IGCM_comp_Finalize"
1673
1674  # Debug Print :
1675  echo
1676  IGCM_debug_Print 1 "IGCM_comp_Finalize"
1677  echo
1678
1679  typeset ListTextName TextName0
1680  typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
1681  typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
1682  typeset -Z4 j4 #BASH declare j4
1683  typeset list_file nlist_file
1684  typeset compactoutputs
1685
1686  # Initialize array hosting list of rebuilded files to copy
1687  unset rebuildedActionsList
1688
1689  # Text compacting options
1690  compactoutputs=false
1691  if [ X${JobType} != XRUN ] ; then
1692    compactoutputs=true
1693  elif [ X${config_UserChoices_CompactText} != Xn ] ; then
1694    compactoutputs=true
1695  fi
1696
1697  # Prepare headers for the shell dedicated to offline rebuild
1698  if [ X${AsynchronousRebuild} = Xtrue ] ; then
1699    [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1700    if [ ${DRYRUN} -le 1 ] ; then
1701      echo "#!/bin/ksh                                        " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1702      echo "function IGCM_FlushRebuild                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1703      echo "{                                                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1704      echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1705      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1706      echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1707      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1708      echo "export R_SAVE=${R_SAVE}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1709      echo "export R_BUFR=${R_BUFR}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1710      echo "export R_OUT_KSH=${R_OUT_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1711      echo "export R_BUF_KSH=${R_BUF_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1712      echo "export config_UserChoices_JobName=${config_UserChoices_JobName}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1713      echo "export config_UserChoices_SpaceName=${config_UserChoices_SpaceName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1714    fi
1715  fi
1716
1717  for comp in ${config_ListOfComponents[*]} ; do
1718    # Define component
1719    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1720    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1721
1722    # Debug Print
1723    IGCM_debug_Print 1 "Finalize ${comp} : ${compname} component."
1724    # FINALIZE component
1725    ${comp}_Finalize
1726
1727    card=${SUBMIT_DIR}/COMP/${compname}.card
1728
1729    # Save Output Text files of models
1730    #---------------------------------
1731    IGCM_debug_Print 2 "Save Output Text files for ${comp} : ${compname} component."
1732    IGCM_card_DefineArrayFromOption ${card} OutputText List
1733    ListTextName=${compname}_OutputText_List
1734
1735    eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1736    if [ X${TextName0} != X${NULL_STR} ] ; then
1737      eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1738
1739      (( i=0 ))
1740      until [ $i -eq $NbFiles ]; do
1741        eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1742        eval file_out=${PREFIX}_${file_in}
1743
1744        (( i=i+1 ))
1745
1746        unset list_file
1747
1748        if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
1749           for (( pool_member_rank=0 ; pool_member_rank < $config_Ensemble_PoolSize ; pool_member_rank++ ))
1750           do
1751            whole_ensemble_rank=$(($config_Ensemble_PoolSize*$1+$pool_member_rank))
1752            Path_OUT="\${R_BUF_${comp}_D}/MEMBER_$whole_ensemble_rank"
1753            cd MEMBER_$whole_ensemble_rank
1754
1755        #set +A list_file -- $( ls ${file_in}* | sort 2>/dev/null )
1756        # result for a a1 a10 a2 with file_in=a a a1 a2 a10
1757        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 )
1758        nlist_file=${#list_file[@]}
1759        if [ ${nlist_file} -gt 1 ] ; then
1760          if ( ${compactoutputs} ) ; then
1761            IGCM_debug_Print 2 "Parallelism of Text Output with ${nlist_file} files."
1762            IGCM_debug_Print 2 "Compact files in ${file_out} : " ${list_file[*]}
1763            echo ${list_file[*]} > ${file_out}
1764            echo "" >> ${file_out}
1765
1766            (( i_ = 0 ))
1767            for file in ${list_file[@]} ; do
1768              echo "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " >> ${file_out}
1769              echo "| " ${i_} " " ${file} >> ${file_out}
1770              echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " >> ${file_out}
1771              cat ${file} | sed "s/\(.*\)/${i_}\1/" >> ${file_out}
1772              echo "" >> ${file_out}
1773              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1774                  (( i_ = i_ + 1 ))
1775            done
1776            if ( ${ExecutionFail} ) ; then
1777              IGCM_sys_Cp ${file_out} ${SUBMIT_DIR}/Debug
1778            fi
1779
1780            if [ X${Pack} = Xtrue ] ; then
1781              eval IGCM_sys_PutBuffer_Out ${file_out} $Path_OUT/${file_out}
1782            else
1783              eval IGCM_sys_Put_Out ${file_out} $Path_OUT/${file_out}
1784            fi
1785
1786            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_out}" > /dev/null 2>&1
1787          else
1788            for file in ${list_file[@]} ; do
1789              if ( ${ExecutionFail} ) ; then
1790                IGCM_sys_Cp ${file} ${SUBMIT_DIR}/Debug/${PREFIX}_${file}
1791              fi
1792
1793              if [ X${Pack} = Xtrue ] ; then
1794                eval IGCM_sys_PutBuffer_Out ${file} $Path_OUT/${PREFIX}_${file}
1795              else
1796                eval IGCM_sys_Put_Out ${file} $Path_OUT/${PREFIX}_${file}
1797              fi
1798
1799              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1800            done
1801          fi
1802        else
1803          if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1804            eval IGCM_sys_Mv ${file_in}* ${file_in}
1805          fi
1806
1807          if ( ${ExecutionFail} ) ; then
1808            IGCM_sys_Cp ${file_in} ${SUBMIT_DIR}/Debug/${file_out}
1809          fi
1810
1811          if [ X${Pack} = Xtrue ] ; then
1812            eval IGCM_sys_PutBuffer_Out ${file_in} $Path_OUT/${file_out}
1813          else
1814            eval IGCM_sys_Put_Out ${file_in} $Path_OUT/${file_out}
1815          fi
1816          eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1817        fi
1818        cd ..
1819        done
1820       fi
1821      done
1822    fi
1823
1824    # Save Restarts files
1825    #--------------------
1826    IGCM_debug_Print 2 "Save Restart files for ${comp} : ${compname} component."
1827    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
1828    ListFilesName=${compname}_RestartFiles_List
1829    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1830
1831    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
1832      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1833
1834      (( i=0 ))
1835      until [ $i -ge $NbFiles ]; do
1836        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1837        eval file_in=${file_in_}
1838
1839        (( i_ = i+1 ))
1840        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1841        eval file_out=${file_out_}
1842
1843        (( i_ = i+2 ))
1844        eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1845        eval file_outin=${file_outin_}
1846
1847        generic_restart_file_name_in=$(    basename ${file_in} .nc )
1848        generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
1849        generic_restart_file_name_outin=$( basename ${file_outin} .nc )
1850
1851        if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
1852
1853            generic_restart_file_name_in_tmp=${generic_restart_file_name_in}
1854           for (( pool_member_rank=0 ; pool_member_rank < $config_Ensemble_PoolSize ; pool_member_rank++ ))
1855           do
1856            whole_ensemble_rank=$(($config_Ensemble_PoolSize*$1+$pool_member_rank))
1857            Path_OUT="\${R_BUF_${comp}_R}/MEMBER_$whole_ensemble_rank"
1858            cd MEMBER_$whole_ensemble_rank
1859            if [ X${comp} = XCPL ] ; then
1860              generic_restart_file_name_in="${generic_restart_file_name_in_tmp}__$pool_member_rank"
1861              file_in="${generic_restart_file_name_in}.nc"           
1862
1863              if [ X${file_in} = Xsstoc__${pool_member_rank}.nc ] ; then
1864
1865               for varname in O_SSTSST OIceFrc O_AlbIce O_TepIce O_OCurx1 O_OCury1 O_OCurz1
1866               do
1867               ncrename -O -v .${varname}__${pool_member_rank},${varname} ${file_in}
1868               done
1869
1870              else
1871
1872             for varname in COTAUXXU COTAUYYU COTAUZZU COTAUXXV COTAUYYV COTAUZZV COTOTRAI COTOTSNO COTOTEVA COICEVAP COQSRMIX COQNSMIX COSHFICE CONSFICE CODFLXDT COCALVIN COLIQRUN COWINDSP COTAUMOD
1873             do
1874             ncrename -O -v .${varname}__${pool_member_rank},${varname} ${file_in}
1875             done
1876             fi
1877            fi
1878            echo $generic_restart_file_name_in
1879            echo $file_in
1880
1881        nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l )
1882        if [ ${nb_restart_file} -gt 1 ] ; then
1883                IGCM_sys_rebuild_nemo ${generic_restart_file_name_in} ${nb_restart_file}
1884            IGCM_sys_Rm ${generic_restart_file_name_in}_????.nc
1885            if [ X${Pack} = Xtrue ] ; then
1886                eval IGCM_sys_PutBuffer_Rest ${file_in} $Path_OUT/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1887            else
1888                eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1889            fi
1890            if [ ! ${file_in} = ${file_outin} ] ; then
1891                if ( ${ExitFlag} ) ; then
1892                    echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1893                else
1894                    IGCM_sys_Mv ${file_in} ${file_outin}
1895                fi
1896            fi
1897        else
1898          if [ X${Pack} = Xtrue ] ; then
1899            eval IGCM_sys_PutBuffer_Rest ${file_in} $Path_OUT/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1900          else
1901            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1902          fi
1903          if [ ! ${file_in} = ${file_outin} ] ; then
1904            if ( ${ExitFlag} ) ; then
1905              echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1906            else
1907              IGCM_sys_Mv ${file_in} ${file_outin}
1908            fi
1909          fi
1910        fi
1911            cd ..
1912            done
1913            fi
1914            (( i=i+3 ))
1915          done
1916    else
1917      if [ X${FileName0} != XNONE ] ; then
1918        IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
1919      else
1920        IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
1921      fi
1922    fi
1923
1924    # Save Output files
1925    #------------------
1926    IGCM_debug_Print 2 "Save Output files for ${comp} : ${compname} component."
1927    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
1928    ListFilesName=${compname}_OutputFiles_List
1929    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1930
1931    if [ X${FileName0} != X${NULL_STR} ] ; then
1932      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1933
1934      (( i=0 ))
1935      until [ $i -ge $NbFiles ]; do
1936        SaveOnArchive=true
1937        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1938        eval file_in=${file_in_}
1939        (( i_ = i+1 ))
1940        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1941        eval file_out=${file_out_}
1942        #
1943        # Override file_out path remplacing R_SAVE by R_BUFR
1944        #
1945        if [ X${Pack} = Xtrue ] ; then
1946          file_out=$( echo $file_out | sed "s:^$R_SAVE:$R_BUFR:" )
1947        fi
1948        #
1949        # Not necessarily the best option. /!\ Potential side effects /!\
1950        #
1951        (( i_ = i+2 ))
1952        eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1953        #
1954
1955         if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
1956            cd XIOS
1957         fi
1958
1959        generic_file_name=$( basename ${file_in} .nc )
1960        nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
1961        #
1962        if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
1963          IGCM_debug_Print 2 "Parallelism with 1 file. Rebuilding ${file_in} not needed"
1964          IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
1965        elif [ ${nb_rebuild_file} -gt 1 ] ; then
1966          IGCM_debug_Print 2 "Parallelism detected and rebuilding ${file_in} is needed"
1967          if [ X${AsynchronousRebuild} = Xfalse ] ; then
1968            IGCM_debug_Print 2 "Rebuilding ${file_in} online"
1969            #
1970            # for output.abort file, let use rebuild_NEMO : 13s instead of 20 mn.
1971            if [ ${file_in} = output.abort.nc ] ; then
1972              IGCM_sys_rebuild_nemo ${generic_file_name} ${nb_rebuild_file} "nc" ${generic_file_name}_[0-9]*.nc
1973            else
1974              IGCM_sys_rebuild ${file_in} ${generic_file_name}_????.nc
1975            fi
1976          else
1977            IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
1978            IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1979
1980            # Prepare the shell dedicated to offline rebuild
1981            if [ $DRYRUN -le 1 ]; then
1982              if [ ${file_in} = histstn.nc ] ; then
1983                echo "IGCM_sys_rebuild_station ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1984              else
1985                echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_[0-9]*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1986              fi
1987              echo "IGCM_debug_Verif_Exit" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1988            fi
1989            #
1990            # Load Patch we need to apply and apply
1991            if [ $DRYRUN -le 1 ]; then
1992              if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
1993                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ) ; do
1994                  echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1995                  echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1996                  echo "IGCM_debug_Verif_Exit                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1997                done
1998              fi
1999            fi
2000            #
2001            if [ $DRYRUN -le 1 ]; then
2002              if [ X${Pack} = Xtrue ] ; then
2003                rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_PutBuffer_Out ${file_in} ${file_out}"
2004              else
2005                rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_Put_Out ${file_in} ${file_out}"
2006              fi
2007              rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_debug_Verif_Exit"
2008              rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_Rm ${generic_file_name}_[0-9]*.nc"
2009            fi
2010            SaveOnArchive=false
2011          fi
2012        fi
2013        #
2014        if [ ${SaveOnArchive} = true ] ; then
2015          #
2016          # Rebuild has been done online or it was not needed
2017          #
2018          # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
2019          #
2020          thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
2021          if ( [ ! X${thereisapatch} = X${NULL_STR} ] && [ ! X${thereisapatch} = X ] && [ X${AsynchronousRebuild} = Xtrue ] && [ -f ${file_in} ] ) ; then
2022            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
2023            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
2024            #
2025            if [ $DRYRUN -le 1 ]; then
2026              for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ) ; do
2027                echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2028                echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2029                echo "IGCM_debug_Verif_Exit                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2030              done
2031              #
2032              if [ X${Pack} = Xtrue ] ; then
2033                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2034              else
2035                echo "IGCM_sys_Put_Out ${file_in} ${file_out}         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2036              fi
2037              echo "IGCM_debug_Verif_Exit                             " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2038              #
2039            fi
2040          else
2041            #
2042            # No Patch, No Asynchronous rebuild, online rebuild has been done or was not needed
2043            #
2044            if [ X${Pack} = Xtrue ] ; then
2045              IGCM_sys_PutBuffer_Out ${file_in} ${file_out}
2046            else
2047              IGCM_sys_Put_Out ${file_in} ${file_out}
2048            fi
2049            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
2050            if [ ${nb_rebuild_file} -gt 1 ] ; then
2051              for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
2052                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
2053              done
2054            fi
2055          fi
2056        fi
2057        (( i=i+3 ))
2058         if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
2059            cd ..
2060         fi
2061      done
2062    fi
2063    echo
2064  done
2065  # Append the sync call and the copy sequence to the IGCM_FlushRebuild function if needed
2066  if [ ${#rebuildedActionsList[*]} -ne 0 ] ; then
2067    echo "IGCM_sys_sync              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2068    i=0
2069    until [ ${i} -ge ${#rebuildedActionsList[*]} ]; do
2070      echo ${rebuildedActionsList[$i]} >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2071      (( i=i+1 ))
2072    done
2073  fi
2074  IGCM_debug_PopStack "IGCM_comp_Finalize"
2075}
Note: See TracBrowser for help on using the repository browser.