source: CONFIG_DEVT/IPSLCM6.2.2_ENSEMBLES/libIGCM/libIGCM_comp/libIGCM_comp.ksh @ 6206

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

Fixed some problems.

File size: 88.2 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  for comp in ${config_ListOfComponents[*]} ; do
721    # Define component
722    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
723    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
724    #
725    card=${SUBMIT_DIR}/COMP/${compname}.card
726    #
727    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
728    ListFilesName=${compname}_RestartFiles_List
729    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
730
731    # Debug Print :
732    IGCM_debug_Print 3 "restart ${compname}"
733
734    if ( ${FirstInitialize} ) ; then
735
736      if ( [ "${config_Restarts_OverRule}" = "y" ] || [ "${config_Restarts_OverRule}" = "Y" ] ) ; then
737        # Adhoc exception for CMIP6 : exclude XIOS from the restart overrule mechanism.
738        if ( [ X${comp} = XIOS ] ) && ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then
739          CompOldName=IOS
740          config_IOS_Restart="n"
741          do_start="n"
742          config_IOS_RestartDate=-1
743          config_IOS_RestartJobName=${NULL_STR}
744          config_IOS_RestartPath=${NULL_STR}
745        else
746          eval config_${comp}_Restart="y"
747          eval config_${comp}_RestartDate=${config_Restarts_RestartDate}
748          eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName}
749          eval config_${comp}_RestartPath=${config_Restarts_RestartPath}
750          eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
751          eval CompOldName=${comp}
752        fi
753      else
754        # Read component Restarts parameters
755        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart
756        eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1
757
758        if [ "${do_start}" = "y" ] ; then
759          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate
760          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName
761          IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath
762        else
763          eval config_${comp}_RestartDate=-1
764          eval config_${comp}_RestartJobName=${NULL_STR}
765          eval config_${comp}_RestartPath=${NULL_STR}
766        fi
767
768        eval CompOldName=\${config_${comp}_OldName}
769        if [ X${CompOldName} = X ] ; then
770          eval CompOldName=${comp}
771        fi
772
773        # Reinitialize IsMatching to allow searching for a different tar file for each component.
774        IsMatching=""
775        TarFileFound=""
776      fi
777
778      if [ "${do_start}" = "y" ] ; then
779
780        # Restore Restarts files
781        #-----------------------
782        if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
783          eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
784
785          (( i=1 ))
786          until [ $i -gt $NbFiles ]; do
787            eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
788            eval file_in=${file_in_}
789            (( i_ = i+1 ))
790            eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
791            eval file_out=${file_out_}
792
793            eval Date_tmp=\${config_${comp}_RestartDate}
794            Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
795            # will be re-use
796            eval RestartPath=\${config_${comp}_RestartPath}
797            eval RestartJobName=\${config_${comp}_RestartJobName}
798            #
799            Path_r=${RestartPath}/${RestartJobName}/${CompOldName}/Restart
800            file_in_Name=${RestartJobName}_${Date_r}_${file_in}
801
802            extension_in=$( echo ${file_in_Name##*.} )
803            extension_out=$( echo ${file_out##*.} )
804
805            generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
806            generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
807            Path_OUT=${Path_r}/${generic_restart_file_name_in}
808
809            path_restart_tmp=`dirname $Path_OUT`
810            base_restart_tmp=`basename $Path_OUT`
811
812            if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
813                        for (( pool_member_rank=0 ; pool_member_rank < $config_Ensemble_PoolSize ; pool_member_rank++ ))
814                        do
815                  whole_ensemble_rank=$(($config_Ensemble_PoolSize*$1+$pool_member_rank))
816                  Path_OUT="$path_restart_tmp/MEMBER_$whole_ensemble_rank/$base_restart_tmp"
817                  Path_r="$path_restart_tmp/MEMBER_$whole_ensemble_rank"
818                  cd MEMBER_$whole_ensemble_rank
819
820            if [ $( IGCM_sys_TestFileBuffer ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
821              IGCM_debug_Print 3 "Buffered restart ${Path_OUT}*.${extension_in} "
822              Buffered=true
823              Archived=false
824              Tared=false
825              nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_OUT}_????.${extension_in})
826            elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
827              IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
828              Buffered=false
829              Archived=true
830              Tared=false
831              nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
832            else
833              IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
834              IGCM_debug_Print 3 "${Path_OUT}*.${extension_in} do not exist"
835              IGCM_debug_Print 3 "Restart files will now be searched for in : ${RestartPath}/${RestartJobName}/RESTART"
836              Buffered=false
837              Archived=false
838              Tared=true
839              # Look after the tar file we want if we did not found it already
840              if [ X${IsMatching} = X ] ; then
841                IGCM_sys_TestDirArchive ${RestartPath}/${RestartJobName}/RESTART
842                if [ $? ] ; then
843                  for PotentialTarFile in $( IGCM_sys_RshArchive "find ${RestartPath}/${RestartJobName}/RESTART -name "${RestartJobName}_*restart*.tar" -print" ) ; do
844                    IsMatching=$( echo ${PotentialTarFile##*/} | \
845                      sed "s:_restart::" | \
846                      sed "s:^${RestartJobName}_::" | \
847                      sed "s:\.tar$::" | \
848                      gawk -F_ -v restartdate=${Date_r} \
849                      '{if (($1 <= restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
850                    if [ ! X${IsMatching} = X ] ; then
851                      TarFileFound=${PotentialTarFile}
852                      break
853                    fi
854                  done
855                fi
856                # Stop here if nothing has been found
857                if [ X${TarFileFound} = X ] ; then
858                  IGCM_debug_Print 3 "Restart files were not found!"
859                  IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
860                  IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
861                  IGCM_debug_Exit "Please double check restart settings in config.card"
862                  IGCM_debug_Verif_Exit
863                fi
864              fi
865              IGCM_sys_PrepareTaredRestart ${TarFileFound}
866              TarFileLocation=$( basename ${TarFileFound} )
867              IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
868              tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
869              nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
870            fi
871
872            if [ ${nb_restart_file} -gt 1 ] ; then
873              j=0                                      # BASH LINE NOT NEEDED
874              # BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
875              until [ $j -ge ${nb_restart_file} ]; do  # BASH LINE NOT NEEDED
876                j4=${j}                                # BASH LINE NOT NEEDED
877                if [ X${Buffered} = Xtrue ] ; then
878                  IGCM_sys_GetBuffer ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
879                elif [ X${Archived} = Xtrue ] ; then
880                  IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
881                elif [ X${Tared} = Xtrue ] ; then
882                  IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
883                fi
884                (( j=j+1 ))                            #BASH LINE NOT NEEDED
885              done
886
887              # OCE SPECIFIC TO REBUILD RESTART WHEN NUMBER OF RESTART FILES DONT MATCH MPI PROCESS
888              if [ X${OCE_PROC_MPI} != X ] ; then
889                if [ ${OCE_PROC_MPI} -ne ${nb_restart_file} ] ; then
890                  IGCM_sys_rebuild_nemo ${generic_restart_file_name_out} ${nb_restart_file} ${extension_out} ${generic_restart_file_name_out}_????.${extension_out}
891                  IGCM_sys_Rm ${generic_restart_file_name_out}_????.${extension_out}
892                fi
893              fi
894            else
895              if [ X${Buffered} = Xtrue ] ; then
896                IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
897              elif [ X${Archived} = Xtrue ] ; then
898                IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
899              elif [ X${Tared} = Xtrue ] ; then
900                IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
901              fi
902            fi
903            cd ..
904            done
905            fi
906            (( i=i+3 ))
907          done
908        else
909          if [ X${FileName0} != XNONE ] ; then
910            IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
911          else
912            IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
913          fi
914        fi
915      fi
916    elif ( [ ${Period} -eq 1 ] && [ ${DRYRUN} -eq 0 ] ) ; then
917      # if not FirstInitialize and first loop of this job
918
919      # Restore Restarts files
920      #-----------------------
921      if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
922        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
923
924        index_j=0
925        for index_member in $(cut -d: -f2 ${SUBMIT_DIR}/ensemble.txt); do
926            member[$index_j]=$index_member
927            index_j=$index_j+1
928        done
929
930        (( i=1 ))
931        until [ $i -gt $NbFiles ]; do
932          eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
933          eval file_in=${file_in_}
934          (( i_ = i+1 ))
935          eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
936          eval file_out=${file_out_}
937
938          file_in_Name=${config_UserChoices_JobName}_${LastPeriodDateEnd}_${file_in}
939
940          extension_in=$( echo ${file_in_Name##*.} )
941          extension_out=$( echo ${file_out##*.} )
942
943          generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
944          generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
945
946          eval Path_BUF=\${R_BUF_${comp}_R}/${generic_restart_file_name_in}
947          eval Path_OUT=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
948
949          if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
950              path_restart_tmp=`dirname $Path_BUF`
951              base_restart_tmp=`basename $Path_BUF`
952
953             for (( pool_member_rank=0 ; pool_member_rank < $config_Ensemble_PoolSize ; pool_member_rank++ ))
954             do
955              whole_ensemble_rank=$(($config_Ensemble_PoolSize*$1+$pool_member_rank))   
956              Path_BUF=$path_restart_tmp/MEMBER_${member[$whole_ensemble_rank]}/$base_restart_tmp
957              Path_r=$path_restart_tmp/MEMBER_${member[$whole_ensemble_rank]}
958              cd MEMBER_$whole_ensemble_rank
959
960
961          if [ $( IGCM_sys_TestFileBuffer ${Path_BUF}*.${extension_in} ; echo $? ) = 0 ] ; then
962            IGCM_debug_Print 3 "Buffered restart ${Path_BUF}*.${extension_in}"
963            Buffered=true
964            Archived=false
965            Tared=false
966            nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_BUF}_????.${extension_in})
967          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
968            IGCM_debug_Print 3 "Archived restart ${Path_OUT}*.${extension_in}"
969            Buffered=false
970            Archived=true
971            Tared=false
972            nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
973          else
974            IGCM_debug_Print 3 "No restart file in the buffer nor in the archive directory"
975            IGCM_debug_Print 3 "Restart files will now be searched for in : ${R_SAVE}/RESTART"
976            Buffered=false
977            Archived=false
978            Tared=true
979            # Look after the tar file we want if we did not found it already
980            if [ X${IsMatching} = X ] ; then
981              for PotentialTarFile in $( IGCM_sys_RshArchive "find ${R_SAVE}/RESTART -name "${config_UserChoices_JobName}_*_restart.tar" -print" ) ; do
982                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}}' )
983                if [ ! X${IsMatching} = X ] ; then
984                  TarFileFound=${PotentialTarFile}
985                  break
986                fi
987              done
988            fi
989            # Stop here if nothing has been found
990            if [ X${TarFileFound} = X ] ; then
991              IGCM_debug_Print 3 "Restart files were not found!"
992              IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
993              IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
994              IGCM_debug_Exit "Please double check restart settings in config.card"
995              IGCM_debug_Verif_Exit
996            fi
997            IGCM_sys_PrepareTaredRestart ${TarFileFound}
998            TarFileLocation=$( basename ${TarFileFound} )
999            IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
1000            tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
1001            nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
1002          fi
1003
1004          if [ ${nb_restart_file} -gt 1 ] ; then
1005            j=0                                     # BASH LINE NOT NEEDED
1006            #BASH for j4 in in $( eval echo {0000..$(( nb_restart_file - 1 ))} ) ; do
1007            until [ $j -ge ${nb_restart_file} ]; do # BASH LINE NOT NEEDED
1008              j4=${j}                               # BASH LINE NOT NEEDED
1009              if [ X${Buffered} = Xtrue ] ; then
1010                IGCM_sys_GetBuffer ${Path_BUF}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
1011              elif [ X${Archived} = Xtrue ] ; then
1012                IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
1013              elif [ X${Tared} = Xtrue ] ; then
1014                IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
1015              fi
1016              (( j=j+1 ))                           # BASH LINE NOT NEEDED
1017            done
1018          else
1019            if [ X${Buffered} = Xtrue ] ; then
1020              eval IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
1021            elif [ X${Archived} = Xtrue ] ; then
1022              eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out}
1023            elif [ X${Tared} = Xtrue ] ; then
1024              IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
1025            fi
1026          fi
1027            cd ..
1028            done
1029            fi
1030          (( i=i+3 ))
1031        done
1032      else
1033        if [ X${FileName0} != XNONE ] ; then
1034          IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}."
1035        else
1036          IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}."
1037        fi
1038      fi
1039    fi
1040  done
1041
1042  NbFiles=$( ls * 2> /dev/null | wc -l )
1043  if [ ${NbFiles} -gt 0 ] ; then
1044    IGCM_sys_Chmod u+rw *
1045  fi
1046  IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles"
1047}
1048
1049#=======================================================================
1050function IGCM_comp_GetInputBinaryFiles
1051{
1052  IGCM_debug_PushStack "IGCM_comp_GetInputBinaryFiles"
1053
1054  # Debug Print :
1055  echo
1056  IGCM_debug_Print 1 "IGCM_comp_GetInputBinaryFiles"
1057  echo
1058
1059  # Clean up previous pass
1060  [ -f ${RUN_DIR}/compiler.txt ] && rm -f ${RUN_DIR}/compiler.txt
1061
1062  typeset comp ExeNameIn ExeNameOut byPass
1063  typeset compilerNmbr compilerUnit compilerFull
1064  byPass=false
1065  for comp in ${config_ListOfComponents[*]} ; do
1066    # Define component
1067
1068    # Copy executable for this component
1069    eval ExeNameIn=\${config_Executable_${comp}[0]}
1070    eval ExeNameOut=\${config_Executable_${comp}[1]}
1071    # Test if missing executable and DRYRUN is set to 0 or 1, then stop!
1072    if [ ${DRYRUN} -le 1 ] && [ X${ExeNameIn} != X\"\" ] ; then
1073        # The executable is set in config.card and is different from ""
1074        # Use eval to expand ExeNameIn if variables are used in the name
1075        eval ExeNameIn=${ExeNameIn}
1076        if [ ! -f ${R_EXE}/${ExeNameIn} ] ; then
1077            IGCM_debug_Exit "IGCM_comp_GetInputBinaryFiles missing executable ${ExeNameIn}"
1078        fi
1079    fi
1080
1081    if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then
1082      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1083      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1084        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1085      fi
1086    elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then
1087      eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut}
1088      if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1089        eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut}
1090      fi
1091    fi
1092
1093    if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then
1094      # Get the compiler version
1095      compilerFull=$( strings ${RUN_DIR}/${ExeNameOut}  | grep "RTL Message Catalog" | gawk '{print $6}' | gawk -F. '{print $1}' )
1096      compilerVersion=$( strings ${RUN_DIR}/${ExeNameOut}  | grep "RTL Message Catalog" | gawk '{print $6}' | gawk -F. '{print $1}' )
1097      # Save it
1098      echo $compilerFull >> ${RUN_DIR}/compiler.txt
1099      [ X${compilerFull} = X ] && byPass=true
1100      IGCM_debug_Print 1 "${RUN_DIR}/${ExeNameOut} has been compiled with ${compilerFull}"
1101      IGCM_debug_Print 1 "Compiler is ${compilerVersion}"
1102    fi
1103  done
1104
1105  compilerNmbr=$( cat ${RUN_DIR}/compiler.txt | wc -l )
1106  compilerUnit=$( cat ${RUN_DIR}/compiler.txt | sort | uniq -c )
1107
1108  if ( [ ${compilerNmbr} -ne ${compilerUnit} ] && [ ! X${byPass} = Xtrue  ] ); then
1109    IGCM_debug_Exit "Binaries has not been compiled with the same compiler version"
1110  fi
1111
1112# Test on compiler version for IPSLCM6* configuration on irene (only for CMIP6 production)
1113  if [ ${SYSTEM} = irene ]; then
1114    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
1115      IGCM_debug_Exit "IPSLCM6.0.13, IPSLCM6.0.14, IPSLCM6.0.15, IPSLCM6.1 and IPSLCM5A2.1 must be compiled with intel 2017 compiler"
1116    fi
1117  fi
1118
1119  IGCM_debug_PopStack "IGCM_comp_GetInputBinaryFiles"
1120}
1121
1122#=======================================================================
1123function IGCM_comp_PeriodStart
1124{
1125  IGCM_debug_PushStack "IGCM_comp_PeriodStart"
1126
1127  # Debug Print :
1128  echo
1129  IGCM_debug_Print 1 "IGCM_comp_PeriodStart"
1130  echo
1131
1132  typeset ExeNameIn ExeNameOut
1133  typeset comp compname comptagname
1134  for comp in ${config_ListOfComponents[*]} ; do
1135    # Define component
1136    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1137    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1138
1139    # Copy executable for this component
1140    eval ExeNameIn=\${config_Executable_${comp}[0]}
1141    eval ExeNameIn=${ExeNameIn}
1142    eval ExeNameOut=\${config_Executable_${comp}[1]}
1143
1144    # Debug Print
1145    IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)."
1146    # UPDATE component
1147    ${comp}_PeriodStart 2> /dev/null
1148
1149  done
1150
1151  IGCM_debug_PopStack "IGCM_comp_PeriodStart"
1152}
1153
1154
1155
1156#=======================================================================
1157function IGCM_comp_modifyFile
1158{
1159#
1160# syntax:     IGCM_comp_modifyFile  filein  key  [value]
1161#
1162# For example : IGCM_comp_modifyFile metrics_template.py case_id \'SE_${YEARS}\'
1163#
1164# This function is used to replace a pattern in a file for a specific variable.
1165#
1166# Arguments:
1167# - filein : the file in run directory in which the variable should be set
1168# - key    : the variable to modify
1169# - value  : the value to set the key equal to
1170#
1171  IGCM_debug_PushStack "IGCM_comp_modifyFile"
1172
1173  typeset filein key value pattern
1174
1175  # Set local variables and test the arguments
1176  if [ $# = 3 ] ; then
1177    # Normal case with 3 arguments
1178    filein=$1 ; key=$2 ; value=$3
1179  else
1180    IGCM_debug_Exit "IGCM_comp_modifyFile: Bad number of arguments."
1181    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1182    return
1183  fi
1184  IGCM_debug_Print 1 "Entering IGCM_comp_modifyFile with arguments: ${filein} ${key} ${value}"
1185
1186  # Test if the file exist
1187  if [ ! -f ${filein} ] ; then
1188    IGCM_debug_Exit "IGCM_comp_modifyFile: ${filein} does not exist."
1189    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1190    return
1191  fi
1192
1193  # Read the line with key in the file without the comments
1194  pattern=$( grep "^ *${key} *=" ${filein} | sed -e "s% *\!.*%%" )
1195
1196  # Verify the existance of the pattern
1197  if [ X"${pattern}" = X ] ; then
1198    # Variable key is not set in filein, stop.
1199    IGCM_debug_Exit "IGCM_comp_modifyFile : Variable ${key} is not set in correct file. It should be set in ${filein}."
1200    IGCM_debug_PopStack "IGCM_comp_modifyFile"
1201    return
1202  fi
1203
1204  # Now change key in filein
1205  #sed -e "s:${pattern}:${key}=${value}:" ${filein} > ${filein}.tmp
1206  sed -e "s:^ *${key} *=.*:${key}=${value}:" ${filein} > ${filein}.tmp
1207  IGCM_debug_Print 1 "IGCM_comp_modifyFile: In ${filein} set ${key}=${value}"
1208  \mv ${filein}.tmp ${filein}
1209 
1210  IGCM_debug_PopStack "IGCM_comp_modifyFile"
1211}
1212
1213#=======================================================================
1214function IGCM_comp_modifyDefFile
1215{
1216#
1217# syntax:     IGCM_comp_modifyDefFile  type  filein  key  [value]
1218#
1219# For example : IGCM_comp_modifyDefFile blocker run.def day_step 1200
1220#
1221# This function is used to modify a parameter file for a specific variable.
1222# The file must be a ".def" file, i.e. with IOIPSL parameter file syntax.
1223# This function can be used in the comp.driver files for the components.
1224#
1225# Arguments:
1226# - type   : first argument must be blocker, nonblocker or force
1227#            For "blocker" case, the variable must be attributed the keyworld AUTO
1228#            otherwise this function will exit.
1229#            For "nonblocker" case, the user can remove or modify the variable. For
1230#            this case, as long as AUTO is not set, no modification will be done.
1231#            For "force" case, the variable will be modified even if it is not set to AUTO
1232# - filein : the file in run directory of .def type in which the variable should be set
1233# - key    : the variable to modify
1234# - value  : the value to set the key equal to, optional. If value is not set or if
1235#            value=DEFAULT, then a default value must be given in filein using syntax :
1236#            key= AUTO : DEFAULT=def_value
1237#
1238  IGCM_debug_PushStack "IGCM_comp_modifyDefFile"
1239
1240  typeset type filein key value
1241  typeset filelist nb_occ modify
1242
1243  # Set local variables and test the arguments
1244  if [ $# = 4 ] ; then
1245    # Normal case with 4 arguments
1246    type=$1 ; filein=$2 ; key=$3 ; value=$4
1247  elif [ $# = 3 ] ; then
1248    # Normal case with 3 arguments
1249    type=$1 ; filein=$2 ;       key=$3; value="DEFAULT"
1250  else
1251    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Bad number of arguments."
1252    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1253    return
1254  fi
1255  IGCM_debug_Print 1 "Entering IGCM_comp_modifyDefFile with arguments: ${type} ${filein} ${key} ${value}"
1256
1257  # Test if first argument is correct
1258  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1259    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Error in first argument must be blocker, nonblocker or force"
1260    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1261    return
1262  fi
1263
1264  # Test if the file exist.
1265  # Exit with error if the file does not exist for the case blocker or force.
1266  # Only return for the case nonblocker.
1267  if [ ! -f ${filein} ] ; then
1268    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1269      IGCM_debug_Exit "IGCM_comp_modifyDefFile: ${filein} does not exist."
1270    else
1271      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${filein} does not exist. Nothing will be done for this file."
1272    fi
1273    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1274    return
1275  fi
1276
1277  # Define list of files to test using all files with suffix .def (except used*.def)
1278  filelist=$( ls *def | grep -v used )
1279
1280  # Count number of occurances for the key in all files
1281  nb_occ=$( grep -w ${key} ${filelist} | grep -v "#"  | wc -l )
1282
1283  # Test if key is set several times
1284  if [ ${nb_occ} -gt 1 ] ; then
1285    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in ${filein}: Variable=${key} is set ${nb_occ} times"
1286    IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1287    return
1288  fi
1289
1290  # Treatement according to different cases
1291  if [ ${nb_occ} -eq 0 ] && [ ${type} = blocker ] ; then
1292    # Stop if the key is never set and the function is blocker
1293    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in ${filein}: Variable=${key} has been removed but this function is blocker. "
1294    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: restore ${filein} for variable ${key}."
1295  elif [ ${nb_occ} -eq 0 ] && [ ${type} = nonblocker ] ; then
1296    # The key is not set but it is a nonblocker call so nothing is done.
1297    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key} is not set in ${filein}. This is a nonblocker call so nothing is done."
1298    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: Default value for ${key} from the model will be used."
1299    modify=no
1300  elif [ $( grep ${key} ${filein} | grep -v "\#"  |wc -l ) = 0 ] ; then
1301    # Variable key is not set in filein, stop.
1302    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Variable ${key} is not set in correct file. It should be set in ${filein}."
1303  fi
1304
1305  # Check if AUTO is set in the filein on the same line as the key variable
1306  if [ $( grep -w ${key} ${filein} | grep -v "\#" | grep AUTO | wc -l ) = 1 ] ; then
1307    # Modification will be done for all cases
1308    modify=yes
1309  else
1310    # The variable was not set to AUTO
1311    if [ ${type} = blocker ] ; then
1312      # Exit because this is a blocker call
1313      IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable ${key} cannot be modified. It should be set to AUTO."
1314      IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1315      return
1316    elif [ ${type} = nonblocker ] ; then
1317      # Do nothing. Suppose that the user did set the variable correct
1318      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key} is set by the user. Nothing done."
1319      modify=no
1320    elif [ ${type} = force ] ; then
1321      # Force modification
1322      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile : Variabl=${key} was not set to AUTO. Modification will be forced."
1323      modify=yes
1324    fi
1325  fi
1326
1327  # Do the modifcation now
1328  if [ ${modify} = yes ] ; then
1329
1330    # For option DEFAULT, read default value from file.
1331    if [ X"${value}" = XDEFAULT ] || [ X"${value}" = X ] ; then
1332      # Case to set DEFAULT value
1333      # Read default value from filein
1334      value=$( grep -w ${key} ${filein} | grep -v "\#" | awk  -F"DEFAULT *=" '{print $2}')
1335
1336      if [ X"${value}" = X ] ; then
1337        IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable ${key} needs a DEFAULT value in ${filein}."
1338        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: The syntax in ${filein} should be:"
1339        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: ${key}=_AUTO_:DEFAULT=def_value"
1340        IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1341        return
1342      fi
1343    fi
1344
1345    # Now change key in filein
1346    sed -e "s/^${key}\ *=.*/${key}= ${value}/" ${filein} > ${filein}.tmp
1347    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: In ${filein} set ${key}=${value}"
1348    \mv ${filein}.tmp ${filein}
1349  fi
1350  IGCM_debug_PopStack "IGCM_comp_modifyDefFile"
1351}
1352
1353#=======================================================================
1354function IGCM_comp_modifyNamelist
1355{
1356#
1357# syntax:     IGCM_comp_modifyNamelist  type  filein  key  [value]
1358#
1359# For example : IGCM_comp_modifyNamelist blocker run.def day_step 1200
1360#
1361# This function is used to modify a parameter file for a specific variable.
1362# The file must be a "namelist" file, i.e. with fortran namelist syntax.
1363# This function can be used in the comp.driver files for the components.
1364#
1365# Arguments:
1366# - type   : first argument must be blocker, nonblocker or force
1367#            For "blocker" case, the variable must be attributed the keyworld AUTO
1368#            otherwise this function will exit.
1369#            For "nonblocker" case, the user can remove or modify the variable. For
1370#            this case, as long as AUTO is not set, no modification will be done.
1371#            For "force" case, the variable will be modified even if it is not set to AUTO
1372# - filein : the file in run directory of .def type in which the variable should be set
1373# - key    : the variable to modify
1374# - value  : the value to set the key equal to, optional. If value is not set or if
1375#            value=DEFAULT, then a default value must be given in filein using syntax :
1376#            key= AUTO : DEFAULT=def_value
1377#
1378  IGCM_debug_PushStack "IGCM_comp_modifyNamelist"
1379
1380  typeset type filein key value pattern modify
1381
1382  # Set local variables and test the arguments
1383  if [ $# = 4 ] ; then
1384    # Normal case with 4 arguments
1385    type=$1 ; filein=$2 ; key=$3 ; value=$4
1386  elif [ $# = 3 ] ; then
1387    # Normal case with 3 arguments
1388    type=$1 ; filein=$2 ;       key=$3; value="DEFAULT"
1389  else
1390    IGCM_debug_Exit "IGCM_comp_modifyNamelist: Bad number of arguments."
1391    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1392    return
1393  fi
1394  IGCM_debug_Print 1 "Entering IGCM_comp_modifyNamelist with arguments: ${type} ${filein} ${key} ${value}"
1395
1396  # Test if first argument is correct
1397  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1398    IGCM_debug_Exit "IGCM_comp_modifyNamelist: Error in first argument must be blocker, nonblocker or force"
1399    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1400    return
1401  fi
1402
1403  # Test if the file exist.
1404  # Exit with error if the file does not exist for the case blocker or force.
1405  # Only return for the case nonblocker.
1406  if [ ! -f ${filein} ] ; then
1407    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1408      IGCM_debug_Exit "IGCM_comp_modifyNamelist: ${filein} does not exist."
1409    else
1410      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${filein} does not exist. Nothing will be done for this file."
1411    fi
1412    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1413    return
1414  fi
1415
1416  # Read the line with key in the file without the comments
1417  pattern=$( grep "^ *${key} *=" ${filein} | sed -e "s% *\!.*%%" )
1418
1419  # Verify the existance of the pattern
1420  if [ X"$pattern" = X ] ; then
1421    # Variable key is not set in filein, stop.
1422    IGCM_debug_Exit "IGCM_comp_modifyNamelist : Variable ${key} is not set in correct file. It should be set in ${filein}."
1423    IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1424    return
1425  fi
1426
1427  # Check if the variable is set to AUTO in the filein
1428  if [ $( echo $pattern | grep AUTO | wc -l ) = 1 ] ; then
1429    # Modification will be done for all cases
1430    modify=yes
1431  else
1432    # The variable was not set to AUTO
1433    if [ ${type} = blocker ] ; then
1434      # Exit because this is a blocker call
1435      IGCM_debug_Exit "IGCM_comp_modifyNamelist : The variable ${key} cannot be modified. It should be set to AUTO."
1436      IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1437      return
1438    elif [ ${type} = nonblocker ] ; then
1439      # Do nothing. Suppose that the user did set the variable correct
1440      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${key} is set by the user. Nothing done."
1441      modify=no
1442    elif [ ${type} = force ] ; then
1443      # Force modification
1444      IGCM_debug_Print 1 "IGCM_comp_modifyNamelist : Variabl=${key} was not set to AUTO. Modification will be forced."
1445      modify=yes
1446    fi
1447  fi
1448
1449  # Do the modifcation now
1450  if [ ${modify} = yes ] ; then
1451
1452    # For option DEFAULT, read default value from file.
1453    if [ X"${value}" = XDEFAULT ] || [ X"${value}" = X ] ; then
1454      # Case to set DEFAULT value
1455      # Read default value from filein
1456      value=$( echo $pattern | awk  -F"DEFAULT *=" '{print $2}')
1457
1458      if [ X"${value}" = X ] ; then
1459        IGCM_debug_Exit "IGCM_comp_modifyNamelist : The variable ${key} needs a DEFAULT value in ${filein}."
1460        IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: The syntax in ${filein} should be:"
1461        IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: ${key}=_AUTO_:DEFAULT=def_value"
1462        IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1463        return
1464      fi
1465    fi
1466
1467    # Now change key in filein
1468    sed -e "s/${pattern}/       ${key}=${value}/" ${filein} > ${filein}.tmp
1469    IGCM_debug_Print 1 "IGCM_comp_modifyNamelist: In ${filein} set ${key}=${value}"
1470    \mv ${filein}.tmp ${filein}
1471  fi
1472  IGCM_debug_PopStack "IGCM_comp_modifyNamelist"
1473}
1474
1475#=======================================================================
1476function IGCM_comp_modifyXmlFile
1477{
1478#
1479# syntax:     IGCM_comp_modifyXmlFile  type  filein  keyid  keyattrib  value
1480#
1481# For example : IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba2 enabled .TRUE.
1482#          or   IGCM_comp_modifyXmlFile blocker iodef.xml using_server NONE false
1483#
1484# This function is used to modify the value for a specific attribute and variable id.
1485# The file must be a valid xml file.
1486# This function can be used in the comp.driver files for the components.
1487#
1488# Arguments:
1489# - type      : first argument must be blocker, nonblocker or force.
1490#               For "blocker" case, the variable must be attributed the keyworld AUTO
1491#               otherwise this function will exit.
1492#               For "nonblocker" case, the user can remove or modify the variable. For
1493#               this case, as long as AUTO is not set, no modification will be done.
1494#               For "force" case, the variable will be modified even if it is not set to AUTO
1495# - filein    : the file in run directory of .xml type in which the variable should be set
1496# - keyid     : the variable to modify
1497# - keyattrib : the attribute name to modify. If NONE, then the variable itself will be modified
1498# - value     : the value to set in the filein
1499#
1500  IGCM_debug_PushStack "IGCM_comp_modifyXmlFile"
1501
1502  typeset type filein keyid keyattrib value modify
1503
1504  # Set local variables and test the arguments
1505  if [ $# = 5 ] ; then
1506    # Normal case with 4 arguments
1507    type=$1 ; filein=$2 ; keyid=$3 ; keyattrib=$4 ; value=$5
1508  else
1509    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Bad number of arguments."
1510    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1511    return
1512  fi
1513  IGCM_debug_Print 1 "Entering IGCM_comp_modifyXmlFile with arguments: type=${type} file=${filein}, id=${keyid} attribute=${keyattrib}, value=${value}"
1514
1515  # Test if first argument is correct
1516  if [ ${type} != blocker ] && [ ${type} != nonblocker ] && [ ${type} != force ] ; then
1517    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Error in first argument must be blocker, nonblocker or force"
1518    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1519    return
1520  fi
1521
1522  # Test if the file exist.
1523  # Exit with error if the file does not exist for the case blocker or force.
1524  # Only return for the case nonblocker.
1525  if [ ! -f ${filein} ] ; then
1526    if [ ${type} = blocker ] || [ ${type} = force ] ; then
1527      IGCM_debug_Exit "IGCM_comp_modifyXmlFile: ${filein} does not exist."
1528    else
1529      IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile: ${filein} does not exist. Nothing will be done for this file."
1530    fi
1531    IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1532    return
1533  fi
1534
1535  # Test if keyid is set in filein. If not exit for case all cases(blocker, force) except nonblocker.
1536  if [ $( grep -w ${keyid} ${filein} | wc -l ) = 0 ] ; then
1537      if [ ${type} = nonblocker ] ; then
1538          # This is a nonblocker case, print warning but do nothing else
1539          IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile: ${keyid} is not set in ${filein}. This is a nonblocker call so nothing is done."
1540      else
1541          # This is a blocker or force case : stop now
1542          IGCM_debug_Exit "IGCM_comp_modifyXmlFile : ${keyid} is not set in the file. Bad syntax of ${filein} file."
1543          IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1544          return
1545      fi
1546  fi
1547
1548  # Check if AUTO is set on the same line as keyid and keyattrib
1549  if [  $( grep -w ${keyid} ${filein} | grep AUTO | wc -l ) = 1 ] ; then
1550    # Modification will be done
1551    modify=yes
1552  else
1553    if [ ${type} = blocker ] ; then
1554      # Exit, the variable must be set to AUTO
1555      IGCM_debug_Exit "IGCM_comp_modifyXmlFile : blocker function. The ${keyattrib} for ${keyid} must be set to AUTO in ${filein}."
1556      IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1557      return
1558    elif [ ${type} = nonblocker ] ; then
1559      # Nothing will be done
1560      IGCM_debug_Print 1 "Nonblocker nothing is done for ${filein}, id=${keyid} and attribute ${keyattrib}"
1561      modify=no
1562    elif [ ${type} = force ] ; then
1563      # Force modification
1564      IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile : Attribute=${keyattrib} for id=${keyid} was not set to AUTO. Modification will be forced."
1565      modify=yes
1566    fi
1567  fi
1568
1569  # Do the modifcation now
1570  if [ ${modify} = yes ] ; then
1571    if [ ${keyattrib} = NONE ] ; then
1572      # Case to modify the variable itself
1573      IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting the variable=${value}"
1574      sed -e "s/\(<[^\"]*\"${keyid}\".*>\)\([^<]*\)\(<[^>]*\)/\1${value}\3/" ${filein} > ${filein}.tmp
1575    else
1576      # Check if keyattrib is set on the same line as keyid
1577      if [  $( grep -w ${keyid} ${filein} | grep ${keyattrib} | wc -l ) = 1 ] ; then
1578        # Case to modify the attribute value
1579        IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting attribute to ${keyattrib}=${value}"
1580        sed -e "/id=\"${keyid}\"/s/\(${keyattrib}=\"\)[^\"]*\(\"\)/\1${value}\2/" ${filein} > ${filein}.tmp
1581      else
1582        # Case to add the attribute and its value
1583        IGCM_debug_Print 1 "Now add in ${filein} for id=${keyid} the attribute ${keyattrib} to the value ${value}"
1584        sed -e "/id=\"${keyid}\"/s/\/>/ ${keyattrib}=\"${value}\"\/>/" ${filein} > ${filein}.tmp
1585      fi
1586    fi
1587    \mv ${filein}.tmp ${filein}
1588  fi
1589  IGCM_debug_PopStack "IGCM_comp_modifyXmlFile"
1590}
1591
1592#=======================================================================
1593function IGCM_comp_Update
1594{
1595  IGCM_debug_PushStack "IGCM_comp_Update"
1596
1597  # Debug Print :
1598  echo
1599  IGCM_debug_Print 1 "IGCM_comp_Update"
1600  echo
1601  if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
1602   cd ENSEMBLE_TEMPLATE
1603  fi
1604
1605  typeset comp compname comptagname
1606  for comp in ${config_ListOfComponents[*]} ; do
1607    # Define component
1608    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1609    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1610
1611    # Debug Print
1612    IGCM_debug_Print 1 "Update ${compname} Parameter Files."
1613    # UPDATE component
1614    ${comp}_Update
1615
1616    # Read TimeSeries information from XML files, prepare TS directories and do modifications in timeseries_def_${compname}.xml
1617    if [ -f timeseries_def_${compname}.xml ]; then
1618      ${libIGCM}/libIGCM_post/xios_parser.py tsquery --file timeseries_def_${compname}.xml > ts.temp.${compname}.txt
1619      for line in $( cat ts.temp.${compname}.txt ); do
1620        output_freq=$( echo ${line} | awk -F "," '{print $1}' | awk -F "=" '{print $2}' )
1621        id=$(          echo ${line} | awk -F "," '{print $2}' | awk -F "=" '{print $2}' )
1622        case ${output_freq} in
1623        *Y|*y)
1624          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_Y}
1625          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_Y}/${config_UserChoices_JobName}
1626          ;;
1627        *MO|*mo)
1628          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_M}
1629          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_M}/${config_UserChoices_JobName}
1630          ;;
1631        *D|*d)
1632          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_D}
1633          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_D}/${config_UserChoices_JobName}
1634          ;;
1635        *S|*s)
1636          eval IGCM_sys_Mkdir \${R_BUF_${comp}_A_H}
1637          eval IGCM_comp_modifyXmlFile nonblocker timeseries_def_${compname}.xml ${id} ts_prefix \${R_BUF_${comp}_A_H}/${config_UserChoices_JobName}
1638          ;;
1639        esac
1640      done
1641    fi
1642
1643    # Read TimeSeries information from XML files, prepare CMIP6 TS directories and do modifications in dr2xml_${compname}.xml
1644    if [ -f dr2xml_${compname}.xml ]; then
1645      if ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then
1646        eval IGCM_sys_Mkdir \${CMIP6_BUF_${comp}}
1647        eval CMIP6_DIR=\${CMIP6_BUF_${comp}}
1648        # Modify path from dr2xml_{compname}.xml
1649        if [ X${config_Post_dr2xmlIPSL} = XTRUE ]; then
1650          ${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
1651        else
1652          ${libIGCM}/libIGCM_post/xios_parser.py -v modifyPath --newPath ${CMIP6_DIR} --file dr2xml_${compname}.xml
1653        fi
1654        # Overwrite the original file
1655        IGCM_sys_Mv modified.dr2xml_${compname}.xml dr2xml_${compname}.xml
1656      fi
1657    fi
1658  done
1659  if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
1660   cd ..
1661  fi
1662
1663
1664  IGCM_debug_PopStack "IGCM_comp_Update"
1665}
1666
1667#=======================================================================
1668function IGCM_comp_Finalize
1669{
1670  IGCM_debug_PushStack "IGCM_comp_Finalize"
1671
1672  # Debug Print :
1673  echo
1674  IGCM_debug_Print 1 "IGCM_comp_Finalize"
1675  echo
1676
1677  typeset ListTextName TextName0
1678  typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive
1679  typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file
1680  typeset -Z4 j4 #BASH declare j4
1681  typeset list_file nlist_file
1682  typeset compactoutputs
1683
1684  # Initialize array hosting list of rebuilded files to copy
1685  unset rebuildedActionsList
1686
1687  # Text compacting options
1688  compactoutputs=false
1689  if [ X${JobType} != XRUN ] ; then
1690    compactoutputs=true
1691  elif [ X${config_UserChoices_CompactText} != Xn ] ; then
1692    compactoutputs=true
1693  fi
1694
1695  # Prepare headers for the shell dedicated to offline rebuild
1696  if [ X${AsynchronousRebuild} = Xtrue ] ; then
1697    [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin}
1698    if [ ${DRYRUN} -le 1 ] ; then
1699      echo "#!/bin/ksh                                        " >  ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1700      echo "function IGCM_FlushRebuild                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1701      echo "{                                                 " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1702      echo "IGCM_debug_PushStack \"IGCM_FlushRebuild\"        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1703      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1704      echo "IGCM_debug_Print 1 \"IGCM_FlushRebuild\"          " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1705      echo "echo                                              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1706      echo "export R_SAVE=${R_SAVE}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1707      echo "export R_BUFR=${R_BUFR}                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1708      echo "export R_OUT_KSH=${R_OUT_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1709      echo "export R_BUF_KSH=${R_BUF_KSH}                     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1710      echo "export config_UserChoices_JobName=${config_UserChoices_JobName}     " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1711      echo "export config_UserChoices_SpaceName=${config_UserChoices_SpaceName} " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
1712    fi
1713  fi
1714
1715  for comp in ${config_ListOfComponents[*]} ; do
1716    # Define component
1717    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
1718    eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1
1719
1720    # Debug Print
1721    IGCM_debug_Print 1 "Finalize ${comp} : ${compname} component."
1722    # FINALIZE component
1723    ${comp}_Finalize
1724
1725    card=${SUBMIT_DIR}/COMP/${compname}.card
1726
1727    # Save Output Text files of models
1728    #---------------------------------
1729    IGCM_debug_Print 2 "Save Output Text files for ${comp} : ${compname} component."
1730    IGCM_card_DefineArrayFromOption ${card} OutputText List
1731    ListTextName=${compname}_OutputText_List
1732
1733    eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1
1734    if [ X${TextName0} != X${NULL_STR} ] ; then
1735      eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1
1736
1737      (( i=0 ))
1738      until [ $i -eq $NbFiles ]; do
1739        eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1
1740        eval file_out=${PREFIX}_${file_in}
1741
1742        (( i=i+1 ))
1743
1744        unset list_file
1745
1746        if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
1747           for (( pool_member_rank=0 ; pool_member_rank < $config_Ensemble_PoolSize ; pool_member_rank++ ))
1748           do
1749            whole_ensemble_rank=$(($config_Ensemble_PoolSize*$1+$pool_member_rank))
1750            Path_OUT="\${R_BUF_${comp}_D}/MEMBER_$whole_ensemble_rank"
1751            cd MEMBER_$whole_ensemble_rank
1752
1753        #set +A list_file -- $( ls ${file_in}* | sort 2>/dev/null )
1754        # result for a a1 a10 a2 with file_in=a a a1 a2 a10
1755        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 )
1756        nlist_file=${#list_file[@]}
1757        if [ ${nlist_file} -gt 1 ] ; then
1758          if ( ${compactoutputs} ) ; then
1759            IGCM_debug_Print 2 "Parallelism of Text Output with ${nlist_file} files."
1760            IGCM_debug_Print 2 "Compact files in ${file_out} : " ${list_file[*]}
1761            echo ${list_file[*]} > ${file_out}
1762            echo "" >> ${file_out}
1763
1764            (( i_ = 0 ))
1765            for file in ${list_file[@]} ; do
1766              echo "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " >> ${file_out}
1767              echo "| " ${i_} " " ${file} >> ${file_out}
1768              echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " >> ${file_out}
1769              cat ${file} | sed "s/\(.*\)/${i_}\1/" >> ${file_out}
1770              echo "" >> ${file_out}
1771              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1772                  (( i_ = i_ + 1 ))
1773            done
1774            if ( ${ExecutionFail} ) ; then
1775              IGCM_sys_Cp ${file_out} ${SUBMIT_DIR}/Debug
1776            fi
1777
1778            if [ X${Pack} = Xtrue ] ; then
1779              eval IGCM_sys_PutBuffer_Out ${file_out} $Path_OUT/${file_out}
1780            else
1781              eval IGCM_sys_Put_Out ${file_out} $Path_OUT/${file_out}
1782            fi
1783
1784            eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_out}" > /dev/null 2>&1
1785          else
1786            for file in ${list_file[@]} ; do
1787              if ( ${ExecutionFail} ) ; then
1788                IGCM_sys_Cp ${file} ${SUBMIT_DIR}/Debug/${PREFIX}_${file}
1789              fi
1790
1791              if [ X${Pack} = Xtrue ] ; then
1792                eval IGCM_sys_PutBuffer_Out ${file} $Path_OUT/${PREFIX}_${file}
1793              else
1794                eval IGCM_sys_Put_Out ${file} $Path_OUT/${PREFIX}_${file}
1795              fi
1796
1797              eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1
1798            done
1799          fi
1800        else
1801          if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then
1802            eval IGCM_sys_Mv ${file_in}* ${file_in}
1803          fi
1804
1805          if ( ${ExecutionFail} ) ; then
1806            IGCM_sys_Cp ${file_in} ${SUBMIT_DIR}/Debug/${file_out}
1807          fi
1808
1809          if [ X${Pack} = Xtrue ] ; then
1810            eval IGCM_sys_PutBuffer_Out ${file_in} $Path_OUT/${file_out}
1811          else
1812            eval IGCM_sys_Put_Out ${file_in} $Path_OUT/${file_out}
1813          fi
1814          eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
1815        fi
1816        cd ..
1817        done
1818       fi
1819      done
1820    fi
1821
1822    # Save Restarts files
1823    #--------------------
1824    IGCM_debug_Print 2 "Save Restart files for ${comp} : ${compname} component."
1825    IGCM_card_DefineArrayFromOption ${card} RestartFiles List
1826
1827    # for i in $(cut -d: -f3 ${SUBMIT_DIR}/ensemble.txt); do
1828    #     noise_teta[$j]=$i
1829    #   j=$j+1
1830    # done
1831 
1832    # j=0
1833    # for CouplingField in O_SSTSST OIceFrc O_AlbIce O_TepIce O_OCurx1 O_OCury1 O_OCurz1
1834    # ListCouplingFieldSstoc[$CouplingField]
1835    # for j in $(seq '1 $
1836    # NumberCOCALVINicshf[$j]
1837
1838    ListFilesName=${compname}_RestartFiles_List
1839    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1840
1841    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
1842      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1843
1844      (( i=0 ))
1845      until [ $i -ge $NbFiles ]; do
1846        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1847        eval file_in=${file_in_}
1848
1849        (( i_ = i+1 ))
1850        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1851        eval file_out=${file_out_}
1852
1853        (( i_ = i+2 ))
1854        eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1855        eval file_outin=${file_outin_}
1856
1857        generic_restart_file_name_in=$(    basename ${file_in} .nc )
1858        generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
1859        generic_restart_file_name_outin=$( basename ${file_outin} .nc )
1860        if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
1861
1862            generic_restart_file_name_in_tmp=${generic_restart_file_name_in}
1863           for (( pool_member_rank=0 ; pool_member_rank < $config_Ensemble_PoolSize ; pool_member_rank++ ))
1864           do
1865            whole_ensemble_rank=$(($config_Ensemble_PoolSize*$1+$pool_member_rank))
1866            Path_OUT="\${R_BUF_${comp}_R}/MEMBER_$whole_ensemble_rank"
1867            cd MEMBER_$whole_ensemble_rank
1868            if [ X${comp} = XCPL ] ; then
1869              generic_restart_file_name_in="${generic_restart_file_name_in_tmp}__$pool_member_rank"
1870              file_in="${generic_restart_file_name_in}.nc"           
1871
1872              if [ X${file_in} = Xsstoc__${pool_member_rank}.nc ] ; then
1873
1874                  for varname in O_SSTSST OIceFrc O_AlbIce O_TepIce O_OCurx1 O_OCury1 O_OCurz1
1875                  do
1876                      ncrename -O -v .${varname}__${pool_member_rank},${varname} ${file_in}
1877                     
1878                  done
1879
1880              elif [ X${file_in} = Xflxat__${pool_member_rank}.nc ] ; then
1881                 
1882                  for varname in COTAUXXU COTAUYYU COTAUZZU COTAUXXV COTAUYYV COTAUZZV COTOTRAI COTOTSNO COTOTEVA COICEVAP COQSRMIX COQNSMIX COSHFICE CONSFICE CODFLXDT COCALVIN COLIQRUN COWINDSP COTAUMOD
1883                  do
1884                      ncrename -O -v .${varname}__${pool_member_rank},${varname} ${file_in}
1885                  done
1886
1887                  NumberCOLIQRUNflxat=$((27*${pool_member_rank}+27))
1888                  NumberCOLIQRUNflxat_4dgts=$(printf "%04i\n" ${NumberCOLIQRUNflxat})
1889
1890                  NumberCOCALVINflxat=$((27*${pool_member_rank}+24))
1891                  NumberCOCALVINflxat_4dgts=$(printf "%04i\n" ${NumberCOCALVINflxat})
1892
1893                  ncrename -O -d loc00${NumberCOLIQRUNflxat_4dgts}_cnt_ncnt,loc000000_COLIQRUN_cnt_ncnt ${file_in}
1894                  ncrename -O -d loc00${NumberCOLIQRUNflxat_4dgts}_COLIQRUN__${pool_member_rank}_nx,loc000000_COLIQRUN_nx ${file_in}
1895                  ncrename -O -d loc00${NumberCOLIQRUNflxat_4dgts}_COLIQRUN__${pool_member_rank}_ny,loc000000_COLIQRUN_ny ${file_in}
1896                  ncrename -O -v loc00${NumberCOLIQRUNflxat_4dgts}_cnt,loc000000_COLIQRUN_cnt ${file_in}
1897                  ncrename -O -v loc00${NumberCOLIQRUNflxat_4dgts}_COLIQRUN__${pool_member_rank},loc000000_COLIQRUN ${file_in}
1898
1899                  ncrename -O -d loc00${NumberCOCALVINflxat_4dgts}_cnt_ncnt,loc000000_COCALVIN_cnt_ncnt ${file_in}
1900                  ncrename -O -d loc00${NumberCOCALVINflxat_4dgts}_COCALVIN__${pool_member_rank}_nx,loc000000_COCALVIN_nx ${file_in}
1901                  ncrename -O -d loc00${NumberCOCALVINflxat_4dgts}_COCALVIN__${pool_member_rank}_ny,loc000000_COCALVIN_ny ${file_in}
1902                  ncrename -O -v loc00${NumberCOCALVINflxat_4dgts}_cnt,loc000000_COCALVIN_cnt ${file_in}
1903                  ncrename -O -v loc00${NumberCOCALVINflxat_4dgts}_COCALVIN__${pool_member_rank},loc000000_COCALVIN ${file_in}
1904
1905              elif [ X${file_in} = Xicbrg__${pool_member_rank}.nc ] ; then
1906           
1907                  NumberCOCALVINicbrg=$((27*${pool_member_rank}+25))
1908                  NumberCOCALVINicbrg_4dgts=$(printf "%04i\n" ${NumberCOCALVINicbrg})
1909
1910                      ncrename -O -d loc00${NumberCOCALVINicbrg_4dgts}_cnt_ncnt,loc000000_cnt_ncnt ${file_in}
1911                      ncrename -O -d loc00${NumberCOCALVINicbrg_4dgts}_COCALVIN__${pool_member_rank}_nx,loc000000_COCALVIN_nx ${file_in}
1912                      ncrename -O -d loc00${NumberCOCALVINicbrg_4dgts}_COCALVIN__${pool_member_rank}_ny,loc000000_COCALVIN_ny ${file_in}
1913                      ncrename -O -v loc00${NumberCOCALVINicbrg_4dgts}_cnt,loc000000_cnt ${file_in}
1914                      ncrename -O -v loc00${NumberCOCALVINicbrg_4dgts}_COCALVIN__${pool_member_rank},loc000000_COCALVIN ${file_in}
1915                      ncrename -O -v .COCALVIN__${pool_member_rank},COCALVIN ${file_in}
1916
1917              elif [ X${file_in} = Xicshf__${pool_member_rank}.nc ] ; then
1918
1919                  NumberCOCALVINicshf=$((27*${pool_member_rank}+26))
1920                  NumberCOCALVINicshf_4dgts=$(printf "%04i\n" ${NumberCOCALVINicshf})
1921                      ncrename -O -d loc00${NumberCOCALVINicshf_4dgts}_cnt_ncnt,loc000000_cnt_ncnt ${file_in}
1922                      ncrename -O -d loc00${NumberCOCALVINicshf_4dgts}_COCALVIN__${pool_member_rank}_nx,loc000000_COCALVIN_nx ${file_in}
1923                      ncrename -O -d loc00${NumberCOCALVINicshf_4dgts}_COCALVIN__${pool_member_rank}_ny,loc000000_COCALVIN_ny ${file_in}
1924                      ncrename -O -v loc00${NumberCOCALVINicshf_4dgts}_cnt,loc000000_cnt ${file_in}
1925                      ncrename -O -v loc00${NumberCOCALVINicshf_4dgts}_COCALVIN__${pool_member_rank},loc000000_COCALVIN ${file_in}
1926                      ncrename -O -v .COCALVIN__${pool_member_rank},COCALVIN ${file_in}
1927              fi
1928
1929            fi
1930            echo $generic_restart_file_name_in
1931            echo $file_in
1932        nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l )
1933        if [ ${nb_restart_file} -gt 1 ] ; then
1934                IGCM_sys_rebuild_nemo ${generic_restart_file_name_in} ${nb_restart_file}
1935            IGCM_sys_Rm ${generic_restart_file_name_in}_????.nc
1936            if [ X${Pack} = Xtrue ] ; then
1937                eval IGCM_sys_PutBuffer_Rest ${file_in} $Path_OUT/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1938            else
1939                eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1940            fi
1941            if [ ! ${file_in} = ${file_outin} ] ; then
1942                if ( ${ExitFlag} ) ; then
1943                    echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1944                else
1945                    IGCM_sys_Mv ${file_in} ${file_outin}
1946                fi
1947            fi
1948        else
1949          if [ X${Pack} = Xtrue ] ; then
1950            eval IGCM_sys_PutBuffer_Rest ${file_in} $Path_OUT/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1951          else
1952            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
1953          fi
1954          if [ ! ${file_in} = ${file_outin} ] ; then
1955            if ( ${ExitFlag} ) ; then
1956              echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
1957            else
1958              IGCM_sys_Mv ${file_in} ${file_outin}
1959            fi
1960          fi
1961        fi
1962            cd ..
1963            done
1964            fi
1965            (( i=i+3 ))
1966          done
1967    else
1968      if [ X${FileName0} != XNONE ] ; then
1969        IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}."
1970      else
1971        IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}."
1972      fi
1973    fi
1974
1975    # Save Output files
1976    #------------------
1977    IGCM_debug_Print 2 "Save Output files for ${comp} : ${compname} component."
1978    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
1979    ListFilesName=${compname}_OutputFiles_List
1980    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
1981
1982    if [ X${FileName0} != X${NULL_STR} ] ; then
1983      eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
1984
1985      nb_member_dir=$( ls | grep "MEMBER" | wc -l )
1986      (( total_number_member = config_Ensemble_PoolSize * config_Ensemble_PoolNumber ))
1987      OutputCopy=FALSE
1988      if [ ${nb_member_dir} = ${total_number_member} ] ; then
1989          OutputCopy=TRUE
1990      fi
1991      (( i=0 ))
1992      until [ $i -ge $NbFiles ]; do
1993        SaveOnArchive=true
1994        eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
1995        eval file_in=${file_in_}
1996        (( i_ = i+1 ))
1997        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
1998        eval file_out=${file_out_}
1999        #
2000        # Override file_out path remplacing R_SAVE by R_BUFR
2001        #
2002        if [ X${Pack} = Xtrue ] ; then
2003          file_out=$( echo $file_out | sed "s:^$R_SAVE:$R_BUFR:" )
2004        fi
2005        #
2006        # Not necessarily the best option. /!\ Potential side effects /!\
2007        #
2008        (( i_ = i+2 ))
2009        eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1
2010        #
2011
2012         if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
2013            cd XIOS
2014         fi
2015
2016        generic_file_name=$( basename ${file_in} .nc )
2017        nb_rebuild_file=$( ls | grep "^${generic_file_name}_[0-9]*.nc" | wc -l )
2018        #
2019        if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then
2020          IGCM_debug_Print 2 "Parallelism with 1 file. Rebuilding ${file_in} not needed"
2021          IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in}
2022        elif [ ${nb_rebuild_file} -gt 1 ] ; then
2023          IGCM_debug_Print 2 "Parallelism detected and rebuilding ${file_in} is needed"
2024          if [ X${AsynchronousRebuild} = Xfalse ] ; then
2025            IGCM_debug_Print 2 "Rebuilding ${file_in} online"
2026            #
2027            # for output.abort file, let use rebuild_NEMO : 13s instead of 20 mn.
2028            if [ ${file_in} = output.abort.nc ] ; then
2029              IGCM_sys_rebuild_nemo ${generic_file_name} ${nb_rebuild_file} "nc" ${generic_file_name}_[0-9]*.nc
2030            else
2031              IGCM_sys_rebuild ${file_in} ${generic_file_name}_????.nc
2032            fi
2033          else
2034            IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}"
2035            IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin}
2036
2037            # Prepare the shell dedicated to offline rebuild
2038            if [ $DRYRUN -le 1 ]; then
2039              if [ ${file_in} = histstn.nc ] ; then
2040                echo "IGCM_sys_rebuild_station ${file_in} ${generic_file_name}_*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2041              else
2042                echo "IGCM_sys_rebuild ${file_in} ${generic_file_name}_[0-9]*.nc" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2043              fi
2044              echo "IGCM_debug_Verif_Exit" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2045            fi
2046            #
2047            # Load Patch we need to apply and apply
2048            if [ $DRYRUN -le 1 ]; then
2049              if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) !=  X${NULL_STR} ]; then
2050                for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ) ; do
2051                  echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2052                  echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2053                  echo "IGCM_debug_Verif_Exit                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2054                done
2055              fi
2056            fi
2057            #
2058            if [ $DRYRUN -le 1 ]; then
2059              if [ X${Pack} = Xtrue ] ; then
2060                rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_PutBuffer_Out ${file_in} ${file_out}"
2061              else
2062                rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_Put_Out ${file_in} ${file_out}"
2063              fi
2064              rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_debug_Verif_Exit"
2065              rebuildedActionsList[${#rebuildedActionsList[*]}]="IGCM_sys_Rm ${generic_file_name}_[0-9]*.nc"
2066            fi
2067            SaveOnArchive=false
2068          fi
2069        fi
2070        #
2071        if [ ${SaveOnArchive} = true ] ; then
2072          #
2073          # Rebuild has been done online or it was not needed
2074          #
2075          # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on
2076          #
2077          thereisapatch=$( eval echo \${${compname}_${flag_post}_Patches[0]} )
2078          if ( [ ! X${thereisapatch} = X${NULL_STR} ] && [ ! X${thereisapatch} = X ] && [ X${AsynchronousRebuild} = Xtrue ] && [ -f ${file_in} ] ) ; then
2079            IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin}
2080            eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1
2081            #
2082            if [ $DRYRUN -le 1 ]; then
2083              for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ) ; do
2084                echo ". ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2085                echo "IGCM_${Patch} ${file_in}                        " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2086                echo "IGCM_debug_Verif_Exit                           " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2087              done
2088              #
2089              if [ X${Pack} = Xtrue ] ; then
2090                echo "IGCM_sys_PutBuffer_Out ${file_in} ${file_out}   " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2091              else
2092                echo "IGCM_sys_Put_Out ${file_in} ${file_out}         " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2093              fi
2094              echo "IGCM_debug_Verif_Exit                             " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2095              #
2096            fi
2097          else
2098            #
2099            # No Patch, No Asynchronous rebuild, online rebuild has been done or was not needed
2100            #
2101            if [ X${OutputCopy} = XTRUE ] ; then
2102                if [ X${Pack} = Xtrue ] ; then
2103                    IGCM_sys_PutBuffer_Out ${file_in} ${file_out}
2104                else
2105                    IGCM_sys_Put_Out ${file_in} ${file_out}
2106                fi
2107                eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1
2108                if [ ${nb_rebuild_file} -gt 1 ] ; then
2109                    for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do
2110                        eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1
2111                    done
2112                fi
2113            fi
2114          fi
2115        fi
2116        (( i=i+3 ))
2117         if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
2118            cd ..
2119         fi
2120      done
2121    fi
2122    echo
2123  done
2124  # Append the sync call and the copy sequence to the IGCM_FlushRebuild function if needed
2125  if [ ${#rebuildedActionsList[*]} -ne 0 ] ; then
2126    echo "IGCM_sys_sync              " >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2127    i=0
2128    until [ ${i} -ge ${#rebuildedActionsList[*]} ]; do
2129      echo ${rebuildedActionsList[$i]} >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh
2130      (( i=i+1 ))
2131    done
2132  fi
2133  IGCM_debug_PopStack "IGCM_comp_Finalize"
2134}
Note: See TracBrowser for help on using the repository browser.