source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_default.ksh @ 1050

Last change on this file since 1050 was 1046, checked in by sdipsl, 10 years ago

Fix rebuild_station in the case empty files has been produced. see #212

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Revision Author Date
File size: 70.6 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys Default host
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe/param/files |            |         |                           |
46# |          |  Chmod Qsub         |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset -r MASTER=${HOST}
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# Submit command
78typeset SUBMIT=${SUBMIT:=qsub}
79# rsync with path
80typeset -r RSYNC=/usr/bin/rsync
81# RSYNC_opt args to rsync
82typeset -r RSYNC_opt="-va"
83# ie storage filesystem
84typeset -r STOREHOST=${MASTER}
85
86#====================================================
87# Set environment tools (ferret, nco, cdo)
88#====================================================
89#. /home/${LOGIN}/.atlas_env_${HOST}_ksh
90
91export PATH=${PATH}:/home/jripsl/snapshot/Monitoring/CNClient/
92
93#====================================================
94# Host specific DIRECTORIES
95#====================================================
96
97#====================================================
98#- MirrorlibIGCM for frontend
99typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
100
101#====================================================
102#- libIGCM_POST for frontend
103typeset -r libIGCM_POST=${libIGCM}
104
105#====================================================
106#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
107typeset -r R_EXE="${MODIPSL}/bin"
108
109#====================================================
110#- SUBMIT_DIR : submission dir
111typeset SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
112
113#====================================================
114#- IN
115typeset -r R_IN=${R_IN:=/home/${LOGIN}/IGCM}
116typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/home/${LOGIN}/IGCM}
117
118#====================================================
119#- ARCHIVE
120typeset ARCHIVE=${ARCHIVE:=/home/${LOGIN}}
121
122#====================================================
123#- STORAGE (dedicated to small/medium files)
124typeset STORAGE=${ARCHIVE}
125
126#====================================================
127#- R_OUT
128typeset R_OUT=${ARCHIVE}/IGCM_OUT
129
130#====================================================
131#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
132typeset R_FIG=${STORAGE}/IGCM_OUT
133
134#====================================================
135#- R_BUF (ONLY FOR double copy an scratch)
136typeset -r R_BUF=${STORAGE}/IGCM_OUT
137
138#====================================================
139#- RUN_DIR_PATH : Temporary working directory (=> TMP)
140typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${STORAGE}/RUN_DIR/tmp$$}
141
142#====================================================
143#- HOST_MPIRUN_COMMAND
144typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
145
146#====================================================
147#- Max number of arguments passed to nco operator or demigration command
148UNIX_MAX_LIMIT=360
149
150#====================================================
151#- Number of core per node (max number of OpenMP task)
152NUM_COREPERNODE=1
153
154#====================================================
155#- Default number of MPI task for IPSL coupled model
156#- required for backward compatibility
157#-
158DEFAULT_NUM_PROC_OCE=1
159DEFAULT_NUM_PROC_CPL=1
160(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
161DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
162
163#D-#==================================================
164#D-function IGCM_sys_ChangeArchive
165#D-* Purpose: Just a dummy call on this machine
166#D-* Examples:
167#D-
168function IGCM_sys_ChangeArchive {
169  IGCM_debug_Print 1 " dummy function : IGCM_sys_ChangeArchive "
170}
171
172#D-#==================================================
173#D-function IGCM_sys_RshMaster
174#D-* Purpose: Connection to frontend machine.
175#D-* Examples:
176#D-
177function IGCM_sys_RshMaster {
178  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
179  /bin/ksh <<-EOF
180    export libIGCM=${libIGCM}
181    export DEBUG_debug=${DEBUG_debug}
182    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
183    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
184    ${@}
185EOF
186  if [ $? -gt 0 ] ; then
187    echo "IGCM_sys_RshMaster : erreur."
188    IGCM_debug_Exit "IGCM_sys_RshMaster"
189  fi
190  IGCM_debug_PopStack "IGCM_sys_RshMaster"
191}
192
193#D-#==================================================
194#D-function IGCM_sys_RshArchive
195#D-* Purpose: Archive rsh command
196#D-* Examples:
197#D-
198function IGCM_sys_RshArchive {
199  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
200  /bin/ksh <<-EOF
201    ${@}
202EOF
203  status=$?
204  if [ ${status} -gt 0 ] ; then
205    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
206    IGCM_debug_Exit "IGCM_sys_RshArchive"
207  fi
208  IGCM_debug_PopStack "IGCM_sys_RshArchive"
209}
210
211#D-#==================================================
212#D-function IGCM_sys_RshPost
213#D-* Purpose: Post-process rsh command
214#D-* Examples:
215#D-
216function IGCM_sys_RshPost {
217  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
218  if ( $DEBUG_sys ) ; then
219    echo "IGCM_sys_RshPost :" $@
220  fi
221
222  # keep standard input (stdin) for the loop onto temporary file
223  cat >tmp_IGCM_sys_RshPost_$$
224
225  /bin/ksh <tmp_IGCM_sys_RshPost_$$
226  if [ $? -gt 0 ] ; then
227    echo "IGCM_sys_RshPost : erreur."
228    IGCM_debug_Exit "IGCM_sys_RshPost"
229  fi
230  # delete temporary file
231  \rm tmp_IGCM_sys_RshPost_$$
232  IGCM_debug_PopStack "IGCM_sys_RshPost"
233}
234
235#D-#==================================================
236#D-function IGCM_sys_SendMail
237#D-* Purpose: Send mail when simulation is over
238#D-* Examples:
239#D-
240function IGCM_sys_SendMail {
241  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
242  if ( $DEBUG_sys ) ; then
243    echo "IGCM_sys_SendMail :" $@
244  fi
245
246  if [ X${1} = XAccounting ] ; then
247    status=Accounting
248    mailText=jobAccounting.mail
249  elif ( ${ExitFlag} ) ; then
250    status=failed
251    mailText=jobEnd.mail
252  else
253    status=completed
254    mailText=jobEnd.mail
255  fi
256
257  # Update selected mail template
258  while read -r line; do
259    eval echo $line >> mail.txt ;
260  done < ${libIGCM}/libIGCM_sys/${mailText}
261
262  if [ ! -z ${config_UserChoices_MailName} ] ; then
263    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  mail.txt
264  elif [ -f ~/.forward ] ; then
265    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < mail.txt
266  fi
267
268  sleep 10
269  rm -f mail.txt
270
271  IGCM_debug_PopStack "IGCM_sys_SendMail"
272}
273
274#D-#==================================================
275#D-function IGCM_sys_Mkdir
276#D-* Purpose: Master locale mkdir command
277#D-* Examples:
278#D-
279function IGCM_sys_Mkdir {
280  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
281  if ( $DEBUG_sys ) ; then
282    echo "IGCM_sys_Mkdir :" $@
283  fi
284  if [ ! -d ${1} ]; then
285    \mkdir -p $1
286    if [ $? -gt 0 ] ; then
287      echo "IGCM_sys_Mkdir : erreur."
288      IGCM_debug_Exit "IGCM_sys_Mkdir"
289    fi
290  fi
291  # vérification :
292  if [ ! -d ${1} ] ; then
293    echo "IGCM_sys_Mkdir : erreur."
294    IGCM_debug_Exit "IGCM_sys_Mkdir"
295  fi
296  IGCM_debug_PopStack "IGCM_sys_Mkdir"
297}
298
299#D-#==================================================
300#D-function IGCM_sys_MkdirArchive
301#D-* Purpose: Mkdir on Archive
302#D-* Examples:
303#D-
304function IGCM_sys_MkdirArchive {
305  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
306  if ( $DEBUG_sys ) ; then
307    echo "IGCM_sys_MkdirArchive :" $@
308  fi
309  #- creation de repertoire sur le serveur fichier
310  mkdir -p $1
311  status=$?
312
313  if [ ${status} -gt 0 ] ; then
314    IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
315    IGCM_debug_Exit "IGCM_sys_MkdirArchive"
316  fi
317  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
318}
319
320#D-#==================================================
321#D-function IGCM_sys_MkdirWork
322#D-* Purpose: Mkdir on Work
323#D-* Examples:
324#D-
325function IGCM_sys_MkdirWork {
326  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
327  if ( $DEBUG_sys ) ; then
328    echo "IGCM_sys_MkdirWork :" $@
329  fi
330  #- creation de repertoire sur le serveur fichier
331  if [ ! -d ${1} ]; then
332    \mkdir -p $1
333    if [ $? -gt 0 ] ; then
334      echo "IGCM_sys_MkdirWork : erreur."
335      IGCM_debug_Exit "IGCM_sys_MkdirWork"
336    fi
337  fi
338  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
339}
340
341#D-#==================================================
342#D-function IGCM_sys_Cd
343#D-* Purpose: master cd command
344#D-* Examples:
345#D-
346function IGCM_sys_Cd {
347  IGCM_debug_PushStack "IGCM_sys_Cd" $@
348  if ( $DEBUG_sys ) ; then
349    echo "IGCM_sys_Cd :" $@
350  fi
351  \cd $1
352  if [ $? -gt 0 ] ; then
353    echo "IGCM_sys_Cd : erreur."
354    IGCM_debug_Exit "IGCM_sys_Cd"
355  fi
356  IGCM_debug_PopStack "IGCM_sys_Cd"
357}
358
359#D-#==================================================
360#D-function IGCM_sys_Chmod
361#D-* Purpose: Chmod
362#D-* Examples:
363#D-
364function IGCM_sys_Chmod {
365  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
366  if ( $DEBUG_sys ) ; then
367    echo "IGCM_sys_Chmod :" $@
368  fi
369  \chmod $@
370  if [ $? -gt 0 ] ; then
371    echo "IGCM_sys_Chmod : erreur."
372    IGCM_debug_Exit "IGCM_sys_Chmod"
373  fi
374  IGCM_debug_PopStack "IGCM_sys_Chmod"
375}
376
377#D-#==================================================
378#D-function IGCM_sys_FileSize
379#D-* Purpose: Filesize
380#D-* Examples:
381#D-
382function IGCM_sys_FileSize {
383  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
384
385  typeset sizeF
386  set +A sizeF -- $( ls -la ${1} )
387  if [ $? -gt 0 ] ; then
388    IGCM_debug_Exit "IGCM_sys_FileSize"
389  fi
390  eval ${2}=${sizeF[4]}
391
392  IGCM_debug_PopStack "IGCM_sys_FileSize"
393}
394
395#D-#==================================================
396#D-function IGCM_sys_TestDir
397#D-* Purpose: Test Directory that must exists
398#D-* Examples:
399#D-
400function IGCM_sys_TestDir {
401  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
402  if ( $DEBUG_sys ) ; then
403    echo "IGCM_sys_TestDir :" $@
404  fi
405  typeset ExistFlag
406  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
407  IGCM_debug_PopStack "IGCM_sys_TestDir"
408
409  return ${ExistFlag}
410}
411
412#D-#==================================================
413#D-function IGCM_sys_TestDirArchive
414#D-* Purpose: Test Directory that must exists on Archive
415#D-* Examples:
416#D-
417function IGCM_sys_TestDirArchive {
418  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
419  if ( $DEBUG_sys ) ; then
420    echo "IGCM_sys_TestDirArchive :" $@
421  fi
422  typeset ExistFlag
423  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
424  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
425  return ${ExistFlag}
426}
427
428#D-#==================================================
429#D-function IGCM_sys_IsFileArchived
430#D-* Purpose: Test file that must NOT EXISTS on Archive
431#D-* Examples:
432#D-
433function IGCM_sys_IsFileArchived {
434  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
435  if ( $DEBUG_sys ) ; then
436    echo "IGCM_sys_IsFileArchived :" $@
437  fi
438  typeset IsArchivedFlag
439  # Never archived for this system
440  IsArchivedFlag=1
441  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
442
443  return ${IsArchivedFlag}
444}
445
446#D-#==================================================
447#D-function IGCM_sys_TestFileArchive
448#D-* Purpose: Test file that must NOT EXISTS on Archive
449#D-* Examples:
450#D-
451function IGCM_sys_TestFileArchive {
452  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
453  typeset ExistFlag
454  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
455  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
456
457  return ${ExistFlag}
458}
459
460#D-#==================================================
461#D-function IGCM_sys_TestFileBuffer
462#D-* Purpose: Test file that must NOT EXISTS on Buffer
463#D-* Examples:
464#D-
465function IGCM_sys_TestFileBuffer {
466  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
467  typeset ExistFlag
468  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
469  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
470
471  return ${ExistFlag}
472}
473
474#D-#==================================================
475#D-function IGCM_sys_CountFileArchive
476#D-* Purpose: Count files on Archive filesystem
477#D-* Examples:
478#D-
479function IGCM_sys_CountFileArchive {
480  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
481  ls ${@} 2>/dev/null | wc -l
482  if [ $? -gt 0 ] ; then
483    echo "IGCM_sys_CountFileArchive : erreur."
484  fi
485  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
486}
487
488#D-#==================================================
489#D-function IGCM_sys_CountFileBuffer
490#D-* Purpose: Count files on Scratch filesystem
491#D-* Examples:
492#D-
493function IGCM_sys_CountFileBuffer {
494  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
495  ls ${@} 2>/dev/null | wc -l
496  if [ $? -gt 0 ] ; then
497    echo "IGCM_sys_CountFileBuffer : erreur."
498  fi
499  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
500}
501
502#D-#==================================================
503#D-function IGCM_sys_Tree
504#D-* Purpose: Tree directories with files on ${ARCHIVE}
505#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
506#D-
507function IGCM_sys_Tree {
508  IGCM_debug_PushStack "IGCM_sys_Tree" $@
509  if ( $DEBUG_sys ) ; then
510    echo "IGCM_sys_Tree :" $@
511  fi
512
513  \tree -f $@
514
515  IGCM_debug_PopStack "IGCM_sys_Tree"
516}
517
518#D-#==================================================
519#D-function IGCM_sys_Tar
520#D-* Purpose: master tar command
521#D-* Examples:
522#D-
523function IGCM_sys_Tar {
524  IGCM_debug_PushStack "IGCM_sys_Tar" $@
525  if ( $DEBUG_sys ) ; then
526    echo "IGCM_sys_Tar :" $@
527  fi
528  \tar cf $@
529  if [ $? -gt 0 ] ; then
530    echo "IGCM_sys_Tar : erreur."
531    IGCM_debug_Exit "IGCM_sys_Tar"
532  fi
533  IGCM_debug_PopStack "IGCM_sys_Tar"
534}
535
536#D-#==================================================
537#D-function IGCM_sys_UnTar
538#D-* Purpose: master un-tar command
539#D-* Examples:
540#D-
541function IGCM_sys_UnTar {
542  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
543  if ( $DEBUG_sys ) ; then
544    echo "IGCM_sys_UnTar :" $@
545  fi
546  \tar xvf $1
547  if [ $? -gt 0 ] ; then
548    echo "IGCM_sys_UnTar : erreur."
549    IGCM_debug_Exit "IGCM_sys_UnTar"
550  fi
551  IGCM_debug_PopStack "IGCM_sys_UnTar"
552}
553
554#D-#==================================================
555#D-function IGCM_sys_Qsub
556#D-* Purpose: Qsub new job
557#D-* Examples:
558#D-
559function IGCM_sys_Qsub {
560  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
561  if ( $DEBUG_sys ) ; then
562    echo "IGCM_sys_Qsub :" $@
563  fi
564  echo "${@} > ${SUBMIT_DIR}/${Script_Output} 2>&1 &"
565  ${@} > ${SUBMIT_DIR}/${Script_Output} 2>&1 &
566  if [ $? -gt 0 ] ; then
567    echo "IGCM_sys_Qsub : erreur ${options} $1"
568    IGCM_debug_Exit "IGCM_sys_Qsub"
569  fi
570  IGCM_debug_PopStack "IGCM_sys_Qsub"
571}
572
573#D-#==================================================
574#D-function IGCM_sys_QsubPost
575#D-* Purpose: Qsub new job on scalaire
576#D-* Examples:
577#D-
578function IGCM_sys_QsubPost {
579  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
580  if ( $DEBUG_sys ) ; then
581    echo "IGCM_sys_QsubPost :" $@
582  fi
583  echo "${libIGCM_POST}/$1.job > ${POST_DIR}/$1.${PeriodDateEnd}.out 2>&1 &"
584  ${libIGCM_POST}/$1.job > ${POST_DIR}/${Script_Post_Output}.out 2>&1 &
585  if [ $? -gt 0 ] ; then
586    echo "IGCM_sys_QsubPost : erreur " $@
587    IGCM_debug_Exit "IGCM_sys_QsubPost"
588  fi
589  IGCM_debug_PopStack "IGCM_sys_QsubPost"
590}
591
592#D-*************************
593#D- File transfer functions
594#D-*************************
595#D-
596
597#D-#==================================================
598#D-function IGCM_sys_Rsync_out
599#D-* Purpose: treat return val of rsync
600#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
601#D-  Error values and explanations can depend on your system version.
602function IGCM_sys_Rsync_out {
603  status=$1
604  if [ ! $status ] ; then
605    echo "rsync error !"
606  fi
607
608  if [ $MYLANG = "fr" ]; then
609    case $status in
610    0)  return ;;
611    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
612      echo "Erreur de syntaxe ou d'utilisation."
613      return;;
614    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
615      echo "Incompatibilité de protocole."
616      return;;
617    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
618      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
619      echo "répertoires"
620      return;;
621    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
622      echo "Action demandée non supportée : une tentative de manipulation de"
623      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
624      echo "été faite ; ou une option qui est supportée par le  client  mais"
625      echo "pas par le serveur a été spécifiée."
626      return;;
627    10) echo "Erreur de rsync ; RERR_SOCKETIO"
628      echo "Erreur dans le socket d'entrée sortie"
629      return;;
630    11) echo "Erreur de rsync ; RERR_FILEIO"
631      echo "Erreur d'entrée sortie fichier"
632      return;;
633    12) echo "Erreur de rsync ; RERR_STREAMIO"
634      echo "Erreur dans flux de donnée du protocole rsync"
635      return;;
636    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
637      echo "Erreur avec les diagnostics du programme"
638      return;;
639    14) echo "Erreur de rsync ; RERR_IPC"
640      echo "Erreur dans le code IPC"
641      return;;
642    20) echo "Erreur de rsync ; RERR_SIGNAL"
643      echo "SIGUSR1 ou SIGINT reçu"
644      return;;
645    21) echo "Erreur de rsync ; RERR_WAITCHILD"
646      echo "Une erreur retournée par waitpid()"
647      return;;
648    22) echo "Erreur de rsync ; RERR_MALLOC"
649      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
650      return;;
651    23) echo ""
652      echo "Erreur fichier inexistant"
653      return;;
654    30) echo "Erreur de rsync ; RERR_TIMEOUT"
655      echo "Temps d'attente écoulé dans l'envoi/réception de données"
656      return;;
657    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
658      return;;
659    esac
660  elif [ $MYLANG = "en" ] ; then
661    case $status in
662    0)  return;;
663    1)  echo "rsync error : Syntax or usage error "
664      return;;
665    2)  echo "rsync error : Protocol incompatibility "
666      return;;
667    3)  echo "rsync error : Errors selecting input/output files, dirs"
668      return;;
669    4)  echo "rsync error : Requested action not supported: an attempt"
670      echo "was made to manipulate 64-bit files on a platform that cannot support"
671      echo "them; or an option was specified that is supported by the client and"
672      echo "not by the server."
673      return;;
674    5)  echo "rsync error : Error starting client-server protocol"
675      return;;
676    10) echo "rsync error : Error in socket I/O "
677      return;;
678    11) echo "rsync error : Error in file I/O "
679      return;;
680    12) echo "rsync error : Error in rsync protocol data stream "
681      return;;
682    13) echo "rsync error : Errors with program diagnostics "
683      return;;
684    14) echo "rsync error : Error in IPC code "
685      return;;
686    20) echo "rsync error : Received SIGUSR1 or SIGINT "
687      return;;
688    21) echo "rsync error : Some error returned by waitpid() "
689      return;;
690    22) echo "rsync error : Error allocating core memory buffers "
691      return;;
692    23) echo "rsync error : Partial transfer due to error"
693      return;;
694    24) echo "rsync error : Partial transfer due to vanished source files"
695      return;;
696    30) echo "rsync error : Timeout in data send/receive "
697      return;;
698    *)  echo "rsync error : return code of rsync unknown :" $status
699      return;;
700    esac
701  else
702    echo "unknown language $MYLANG."
703    return
704  fi
705}
706
707#D-#==================================================
708#D-function IGCM_sys_Miror_libIGCM
709#D-* Purpose: Mirror libIGCM PATH and lib to frontend
710#D-* Examples:
711#D-
712function IGCM_sys_Mirror_libIGCM {
713  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
714  if ( $DEBUG_sys ) ; then
715    echo "IGCM_sys_Mirror_libIGCM"
716  fi
717
718  typeset status
719
720  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
721
722  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > /tmp/out_command.$$ 2>&1
723  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> /tmp/out_command.$$ 2>&1
724  status=$?
725
726  if [ ${status} -gt 0 ] ; then
727    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on frontend."
728    cat /tmp/out_command.$$
729  fi
730  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
731}
732
733#D-#==================================================
734#D-function IGCM_sys_Cp
735#D-* Purpose: generic cp
736#D-* Examples:
737#D-
738function IGCM_sys_Cp {
739  IGCM_debug_PushStack "IGCM_sys_Cp" $@
740  if ( $DEBUG_sys ) ; then
741    echo "IGCM_sys_Cp :" $@
742  fi
743
744  typeset status
745
746  echo cp $@ > /tmp/out_command.$$ 2>&1
747  \cp $@ >> /tmp/out_command.$$ 2>&1
748  status=$?
749
750  if [ ${status} -gt 0 ] ; then
751    echo "IGCM_sys_Cp : error code ${status}"
752    cat /tmp/out_command.$$
753    IGCM_debug_Exit "IGCM_sys_Cp"
754  else
755    \rm /tmp/out_command.$$
756  fi
757  IGCM_debug_PopStack "IGCM_sys_Cp"
758}
759
760#D-#==================================================
761#D-function IGCM_sys_Rm
762#D-* Purpose: generic rm
763#D-* Examples:
764#D-
765function IGCM_sys_Rm {
766  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
767  if ( $DEBUG_sys ) ; then
768    echo "IGCM_sys_Rm :" $@
769  fi
770
771  typeset status
772
773  echo rm $@ > /tmp/out_command.$$ 2>&1
774  \rm $@ >> /tmp/out_command.$$ 2>&1
775  status=$?
776
777  if [ ${status} -gt 0 ] ; then
778    echo "IGCM_sys_Rm : error code ${status}"
779    cat /tmp/out_command.$$
780    IGCM_debug_Exit "IGCM_sys_Rm"
781  else
782    \rm /tmp/out_command.$$
783  fi
784  IGCM_debug_PopStack "IGCM_sys_Rm"
785}
786
787#D-#==================================================
788#D-function IGCM_sys_RmRunDir
789#D-* Purpose: rm tmpdir (dummy function most of the time batch
790#D-                      scheduler will do the job)
791#D-* Examples:
792#D-
793function IGCM_sys_RmRunDir {
794  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
795  if ( $DEBUG_sys ) ; then
796    echo "IGCM_sys_RmRunDir :" $@
797    echo "Dummy call, let the user do that."
798#    IGCM_sys_Rm -rf ${RUN_DIR}
799  fi
800  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
801}
802
803#D-#==================================================
804#D-function IGCM_sys_Mv
805#D-* Purpose: generic move
806#D-* Examples:
807#D-
808function IGCM_sys_Mv {
809  IGCM_debug_PushStack "IGCM_sys_Mv" $@
810  if ( $DEBUG_sys ) ; then
811    echo "IGCM_sys_Mv :" $@
812  fi
813
814  if [ $DRYRUN = 0 ]; then
815
816    typeset status
817
818    echo mv $@ > /tmp/out_command.$$ 2>&1
819    \mv $@ >> /tmp/out_command.$$ 2>&1
820    status=$?
821
822    if [ ${status} -gt 0 ] ; then
823      echo "IGCM_sys_Mv : error code ${status}"
824      cat /tmp/out_command.$$
825      IGCM_debug_Exit "IGCM_sys_Mv"
826    else
827      \rm /tmp/out_command.$$
828    fi
829  fi
830
831  IGCM_debug_PopStack "IGCM_sys_Mv"
832}
833
834#D-#==================================================
835#D-function IGCM_sys_Put_Dir
836#D-* Purpose: Copy a complete directory on $(ARCHIVE)
837#D-* Examples:
838#D-
839function IGCM_sys_Put_Dir {
840  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
841  if ( $DEBUG_sys ) ; then
842    echo "IGCM_sys_Put_Dir :" $@
843  fi
844  if [ $DRYRUN = 0 ]; then
845    if [ ! -d ${1} ] ; then
846      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
847      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
848      return
849    fi
850
851    typeset status
852
853    # Only if we use rsync
854    #IGCM_sys_TestDirArchive $( dirname $2 )
855    #
856    #USUAL WAY
857    \cp -r $1 $2 > /tmp/out_command.$$ 2>&1
858    status=$?
859
860    if [ ${status} -gt 0 ] ; then
861      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
862      cat /tmp/out_command.$$
863      IGCM_debug_Exit "IGCM_sys_Put_Dir"
864    else
865      \rm /tmp/out_command.$$
866    fi
867  fi
868  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
869}
870
871#D-#==================================================
872#D-function IGCM_sys_Get_Dir
873#D-* Purpose: Copy a complete directory from ${ARCHIVE}
874#D-* Examples:
875#D-
876function IGCM_sys_Get_Dir {
877  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
878  if ( $DEBUG_sys ) ; then
879    echo "IGCM_sys_Get_Dir :" $@
880  fi
881  if [ $DRYRUN = 0 ]; then
882    if [ ! -d ${1} ] ; then
883      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
884      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
885      return
886    fi
887
888    typeset status
889
890    #USUAL WAY
891    \cp -ur $1 $2 > /tmp/out_command.$$ 2>&1
892    status=$?
893
894    if [ ${status} -gt 0 ] ; then
895      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
896      cat /tmp/out_command.$$
897      IGCM_debug_Exit "IGCM_sys_Get_Dir"
898    else
899      \rm /tmp/out_command.$$
900    fi
901  fi
902  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
903}
904
905#D-#==================================================
906#D-function IGCM_sys_Get_Master
907#D-* Purpose: Copy a complete directory from MASTER filesystem
908#D-* Examples:
909#D-
910function IGCM_sys_Get_Master {
911  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
912  if ( $DEBUG_sys ) ; then
913    echo "IGCM_sys_Get_Master :" $@
914  fi
915  if [ $DRYRUN = 0 ]; then
916    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
917      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
918      IGCM_debug_PopStack "IGCM_sys_Get_Master"
919      return
920    fi
921
922    typeset NB_ESSAI DELAI status i
923    # number of tentative
924    NB_ESSAI=3
925    # time delay between tentative
926    DELAI=2
927
928    i=0
929    while [ $i -lt $NB_ESSAI ] ; do
930      \cp -urL $1 $2 > /tmp/out_command.$$ 2>&1
931      status=$?
932      if [ ${status} -gt 0 ]; then
933        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
934        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
935        sleep $DELAI
936      else
937        break
938      fi
939      (( i = i + 1 ))
940    done
941
942    if [ ${status} -gt 0 ] ; then
943      echo "IGCM_sys_Get_Master : error."
944      cat /tmp/out_command.$$
945      IGCM_debug_Exit "IGCM_sys_Get_Master"
946    else
947      \rm /tmp/out_command.$$
948    fi
949  fi
950  IGCM_debug_PopStack "IGCM_sys_Get_Master"
951}
952
953#====================================================
954#- Call IGCM_sys_Mirror_libIGCM now !
955if ( $MirrorlibIGCM ) ; then
956  IGCM_sys_Mirror_libIGCM
957fi
958
959#D-#==================================================
960#D-function IGCM_sys_Put_Rest
961#D-* Purpose: Put computied restarts on ${ARCHIVE}.
962#D-           File and target directory must exist.
963#D-* Examples:
964#D-
965function IGCM_sys_Put_Rest {
966  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
967  if ( $DEBUG_sys ) ; then
968    echo "IGCM_sys_Put_Rest :" $@
969  fi
970  if [ $DRYRUN = 0 ]; then
971    if [ ! -f ${1} ] ; then
972      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
973      IGCM_debug_Exit "IGCM_sys_Put_Rest"
974    fi
975
976    typeset status
977    #
978    if [ X${JobType} = XRUN ] ; then
979      IGCM_sys_Chmod 444 ${1}
980    fi
981    #
982    # Only if we use rsync
983    #IGCM_sys_MkdirArchive $( dirname $2 )
984    #
985    #USUAL WAY
986    \cp $1 $2 > /tmp/out_command.$$ 2>&1
987    status=$?
988
989#       #RSYNC WITH NETWORK SSH CALL
990#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > /tmp/out_command.$$ 2>&1
991#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> /tmp/out_command.$$ 2>&1
992
993#       #RSYNC WITH NFS USE
994#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > /tmp/out_command.$$ 2>&1
995#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> /tmp/out_command.$$ 2>&1
996
997#       status=$?
998#       IGCM_sys_Rsync_out $status
999
1000#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command.$$
1001#       (( status=status+$? ))
1002
1003    if [ ${status} -gt 0 ] ; then
1004      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
1005      cat /tmp/out_command.$$
1006      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1007    else
1008      \rm /tmp/out_command.$$
1009    fi
1010  fi
1011  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1012}
1013
1014#D-#==================================================
1015#D-function IGCM_sys_PutBuffer_Rest
1016#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1017#D-           File and target directory must exist.
1018#D-* Examples:
1019#D-
1020function IGCM_sys_PutBuffer_Rest {
1021  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1022  if ( $DEBUG_sys ) ; then
1023    echo "IGCM_sys_PutBuffer_Rest :" $@
1024  fi
1025  if [ $DRYRUN = 0 ]; then
1026    if [ ! -f ${1} ] ; then
1027      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1028      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1029    fi
1030
1031    typeset status
1032    #
1033    if [ X${JobType} = XRUN ] ; then
1034      IGCM_sys_Chmod 444 ${1}
1035    fi
1036
1037    #
1038    # USUAL WAY
1039    \cp $1 $2 > /tmp/out_command.$$ 2>&1
1040    status=$?
1041
1042    if [ ${status} -gt 0 ] ; then
1043      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1044      [ -f ${2} ] && ls -l ${2}
1045      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1046      cat /tmp/out_command.$$
1047      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1048    else
1049      \rm /tmp/out_command.$$
1050    fi
1051  fi
1052  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1053}
1054
1055#D-#==================================================
1056#D-function IGCM_sys_PrepareTaredRestart
1057#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1058#D-* Examples:
1059#D-
1060function IGCM_sys_PrepareTaredRestart {
1061  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1062
1063  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1064}
1065
1066#D-#==================================================
1067#D-function IGCM_sys_Put_Out
1068#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1069#D-* Examples:
1070#D-
1071function IGCM_sys_Put_Out {
1072  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1073  if ( $DEBUG_sys ) ; then
1074    echo "IGCM_sys_Put_Out :" $@
1075  fi
1076
1077  typeset status
1078
1079  if [ $DRYRUN = 0 ]; then
1080    if [ ! -f ${1} ] ; then
1081      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1082      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1083      return 1
1084    fi
1085    #
1086    IGCM_sys_MkdirArchive $( dirname $2 )
1087    #
1088    if [ X${JobType} = XRUN ] ; then
1089      if [ X${3} = X ] ; then
1090        IGCM_sys_Chmod 444 ${1}
1091      fi
1092    fi
1093    #
1094
1095    echo ${RSYNC} ${RSYNC_opt} $1 $2 > /tmp/out_command.$$ 2>&1
1096    ${RSYNC} ${RSYNC_opt} $1 $2 >> /tmp/out_command.$$ 2>&1
1097    status=$?
1098    IGCM_sys_Rsync_out $status
1099
1100    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command.$$
1101    (( status=status+$? ))
1102
1103    if [ ${status} -gt 0 ] ; then
1104      IGCM_debug_Print 2 "IGCM_sys_Put_Out : rsync failed error code ${status}"
1105      cat /tmp/out_command.$$
1106      IGCM_debug_Exit "IGCM_sys_Put_Out"
1107    else
1108      \rm /tmp/out_command.$$
1109    fi
1110  fi
1111  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1112  return 0
1113}
1114
1115#D-#==================================================
1116#D-function IGCM_sys_PutBuffer_Out
1117#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1118#D-* Examples:
1119#D-
1120function IGCM_sys_PutBuffer_Out {
1121  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1122  if ( $DEBUG_sys ) ; then
1123    echo "IGCM_sys_PutBuffer_Out :" $@
1124  fi
1125
1126  typeset NB_ESSAI DELAI status i exist skip
1127
1128  # number of tentative
1129  NB_ESSAI=3
1130  # time delay between tentative
1131  DELAI=2
1132
1133  if [ $DRYRUN = 0 ]; then
1134    if [ ! -f ${1} ] ; then
1135      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1136      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1137      return 1
1138    fi
1139    #
1140    IGCM_sys_Mkdir $( dirname $2 )
1141    #
1142
1143    exist=false
1144    skip=false
1145    if [ -f $2 ] ; then
1146      IGCM_debug_Print 1 "$2 already exist"
1147      exist=true
1148      if [ "X$( diff $1 $2 )" = X ] ; then
1149        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1150        status=0
1151        skip=true
1152      else
1153        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1154        skip=false
1155      fi
1156    fi
1157    #
1158    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1159      IGCM_sys_Chmod u+w $2
1160    fi
1161
1162    if [ X${skip} = Xfalse ] ; then
1163      i=0
1164      while [ $i -lt $NB_ESSAI ] ; do
1165        # USUAL WAY
1166        \cp $1 $2 > /tmp/out_command.$$ 2>&1
1167        status=$?
1168        if [ ${status} -gt 0 ]; then
1169          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1170          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1171          [ -f ${2} ] && ls -l ${2}
1172          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1173          sleep $DELAI
1174        else
1175          break
1176        fi
1177        (( i = i + 1 ))
1178      done
1179    fi
1180
1181    if [ ${status} -gt 0 ] ; then
1182      echo "IGCM_sys_PutBuffer_Out : error."
1183      [ -f ${2} ] && ls -l ${2}
1184      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1185      cat /tmp/out_command.$$
1186      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1187    else
1188
1189      if [ X${JobType} = XRUN ] ; then
1190        if [ X${3} = X ] ; then
1191          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1192          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1193        fi
1194      fi
1195
1196      \rm /tmp/out_command.$$
1197    fi
1198  fi
1199  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1200  return 0
1201}
1202
1203#D-#==================================================
1204#D-function IGCM_sys_Get
1205#D-* Purpose: Get a file from ${ARCHIVE}
1206#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1207#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1208function IGCM_sys_Get {
1209  IGCM_debug_PushStack "IGCM_sys_Get" $@
1210
1211  typeset DEST status dm_liste
1212
1213  if ( $DEBUG_sys ) ; then
1214    echo "IGCM_sys_Get :" $@
1215  fi
1216  if [ $DRYRUN -le 2 ]; then
1217    if [ X${1} = X'/l' ] ; then
1218      eval set +A dm_liste \${${2}}
1219    else
1220      dm_liste=${1}
1221    fi
1222    eval DEST=\${${#}}
1223
1224    # test if the (first) file is present in the old computation :
1225    IGCM_sys_TestFileArchive ${dm_liste[0]}
1226    status=$?
1227    if [ ${status} -gt 0 ] ; then
1228      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1229      IGCM_debug_Exit "IGCM_sys_Get"
1230      return
1231    fi
1232
1233    #USUAL WAY
1234    \cp ${dm_liste[*]} ${DEST} > /tmp/out_command.$$ 2>&1
1235    status=$?
1236
1237    if [ ${status} -gt 0 ] ; then
1238      IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}"
1239      cat /tmp/out_command.$$
1240      IGCM_debug_Exit "IGCM_sys_Get"
1241    else
1242      \rm /tmp/out_command.$$
1243    fi
1244  fi
1245  IGCM_debug_PopStack "IGCM_sys_Get"
1246}
1247
1248#D-#==================================================
1249#D-function IGCM_sys_GetBuffer
1250#D-* Purpose: Get a file from ${SCRATCHDIR}
1251#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1252#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1253function IGCM_sys_GetBuffer {
1254  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1255
1256  typeset DEST buf_liste target file_work
1257  typeset NB_ESSAI DELAI status i
1258
1259  if ( $DEBUG_sys ) ; then
1260    echo "IGCM_sys_GetBuffer :" $@
1261  fi
1262
1263  # number of tentative
1264  NB_ESSAI=3
1265  # time delay between tentative
1266  DELAI=2
1267
1268  if [ $DRYRUN -le 2 ]; then
1269    if [ X${1} = X'/l' ] ; then
1270      eval set +A buf_liste \${${2}}
1271    else
1272      eval set +A buf_liste ${1}
1273    fi
1274    eval DEST=\${${#}}
1275
1276    #USUAL WAY
1277    if [ X${1} = X'/l' ] ; then
1278      for target in ${buf_liste[*]} ; do
1279        local_file=$( basename ${target} )
1280        i=0
1281        while [ $i -lt $NB_ESSAI ] ; do
1282          \cp ${target} ${DEST}/${local_file} >> /tmp/out_command.$$ 2>&1
1283          status=$?
1284          if [ ${status} -gt 0 ]; then
1285            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1286            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1287            sleep $DELAI
1288          else
1289            break
1290          fi
1291          (( i = i + 1 ))
1292        done
1293        if [ ${status} -gt 0 ] ; then
1294          echo "IGCM_sys_Get : error"
1295          cat /tmp/out_command.$$
1296          \rm /tmp/out_command.$$
1297          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1298        else
1299          \rm /tmp/out_command.$$
1300        fi
1301      done
1302    else
1303      i=0
1304      while [ $i -lt $NB_ESSAI ] ; do
1305        \cp ${buf_liste} ${DEST} >> /tmp/out_command.$$ 2>&1
1306        status=$?
1307        if [ ${status} -gt 0 ]; then
1308          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1309          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1310          sleep $DELAI
1311        else
1312          break
1313        fi
1314        (( i = i + 1 ))
1315      done
1316      if [ ${status} -gt 0 ] ; then
1317        echo "IGCM_sys_Get : error"
1318        cat /tmp/out_command.$$
1319        \rm /tmp/out_command.$$
1320        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1321      else
1322        \rm /tmp/out_command.$$
1323      fi
1324    fi
1325  fi
1326  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1327}
1328
1329#D-#==================================================
1330#D-function IGCM_sys_GetDate_FichWork
1331#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1332#D-* Examples:
1333#D-
1334function IGCM_sys_GetDate_FichWork {
1335  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1336  if ( $DEBUG_sys ) ; then
1337    echo "IGCM_sys_GetDate_FichWork :" $@
1338  fi
1339  typeset dateF
1340  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1341  eval ${2}=${dateF[5]}
1342
1343  # donne la date filesys d'un fichier sur la machine work
1344  IGCM_debug_PopStack "IGCM_sys_FichWork"
1345}
1346
1347#D-#==================================================
1348#D-function IGCM_sys_GetDate_FichArchive
1349#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1350#D-* Examples:
1351#D-
1352function IGCM_sys_GetDate_FichArchive {
1353  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1354  if ( $DEBUG_sys ) ; then
1355    echo "IGCM_sys_GetDate_FichArchive :" $@
1356  fi
1357  typeset dateF
1358  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1359  eval ${2}=${dateF[5]}
1360
1361  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1362}
1363
1364#D-#==================================================
1365#D-function IGCM_sys_Dods_Rm
1366#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1367#D-* Examples:
1368#D-
1369function IGCM_sys_Dods_Rm {
1370  if ( $DEBUG_sys ) ; then
1371    echo "IGCM_sys_Dods_Rm :" $@
1372  fi
1373  return 0
1374}
1375
1376#D-#==================================================
1377#D-function IGCM_sys_Dods_Cp
1378#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1379#D-* Examples:
1380#D-
1381function IGCM_sys_Dods_Cp {
1382  if ( $DEBUG_sys ) ; then
1383    echo "IGCM_sys_Dods_Cp :" $@
1384  fi
1385  return 0
1386}
1387
1388#D-#==================================================
1389#D-function IGCM_sys_Put_Dods
1390#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here
1391#D-* Examples:
1392#D-
1393function IGCM_sys_Put_Dods {
1394  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1395  if ( $DEBUG_sys ) ; then
1396    echo "IGCM_sys_Put_Dods :" $@
1397  fi
1398  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1399}
1400
1401##############################################################
1402# REBUILD OPERATOR
1403
1404#D-#==================================================
1405#D-function IGCM_sys_rebuild
1406#D-* Purpose: rebuild parallel files
1407#D-* Examples:
1408#D-
1409function IGCM_sys_rebuild {
1410  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1411  if ( $DEBUG_sys ) ; then
1412    echo "IGCM_sys_rebuild :" $@
1413  fi
1414
1415  typeset NB_ESSAI DELAI status i firstArg
1416  # number of tentative
1417  NB_ESSAI=3
1418  # time delay between tentative
1419  DELAI=2
1420
1421  i=0
1422  while [ $i -lt $NB_ESSAI ] ; do
1423    rebuild -f -o $@ > /tmp/out_command.$$ 2>&1
1424    status=$?
1425    if [ ${status} -gt 0 ] ; then
1426      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1427      cat /tmp/out_command.$$
1428      \rm /tmp/out_command.$$
1429      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1430      firstArg=${1}
1431      \rm ${firstArg}
1432      sleep $DELAI
1433    else
1434      \rm /tmp/out_command.$$
1435      break
1436    fi
1437    (( i = i + 1 ))
1438  done
1439
1440  if [ ${status} -gt 0 ] ; then
1441    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1442    IGCM_debug_Exit "rebuild"
1443  fi
1444
1445  IGCM_debug_PopStack "IGCM_sys_rebuild"
1446}
1447
1448#D-#==================================================
1449#D-function IGCM_sys_rebuild_station
1450#D-* Purpose: rebuild parallel files describing station
1451#D-* Examples:
1452#D-
1453function IGCM_sys_rebuild_station {
1454  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1455  typeset i list_opt file_in file_out prefix_invert list_invert
1456  if ( $DEBUG_sys ) ; then
1457    echo "IGCM_sys_rebuild_station :" $@
1458  fi
1459  list_opt=$@
1460
1461  # Invert Axis : t,x -> x,t
1462  #               t,pres,x -> x,t,pres
1463  # So that we can concatenate along x
1464  i=0
1465  for file_in in ${list_opt} ; do
1466    (( i = i + 1))
1467    [ ${i} = 1 ] && file_out=${file_in} && continue
1468    # detect time counter and do the job only if present
1469    var_unlim=$(ncdump -h ${file_in} | grep UNLIMITED | cut -d ' ' -f 1)
1470    if [ X${var_unlim} = Xtime_counter ] ; then
1471      prefix_invert=$( basename ${file_in} .nc )
1472      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1473      list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1474    fi
1475  done
1476
1477  # Concatenate
1478  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1479
1480  # Re-ivert file
1481  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1482
1483  # Station re-ordering is too expansive to be run within libIGCM
1484  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1485  # This re-ordering must be done "in memory" by the cmorization process
1486  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1487  # BEGIN reordering
1488
1489  # Only LMDZ text output contains the exact ordering of the station.
1490  # We isolate this in the code below:
1491  #  0  38  -157.5000000000000  70.98591549295774
1492  #  0  54  27.49999999999999   67.18309859154928
1493  #  0  56  -62.50000000000001  82.39436619718309
1494  #  0  79  12.49999999999999   78.59154929577466
1495  #  0  116 -165.0000000000000  76.05633802816901
1496  #  0  117 130.0000000000000   70.98591549295774
1497  #  0  118 110.0000000000000   87.46478873239437
1498  #  1  40  4.999999999999995   51.97183098591550
1499#  typeset iStation iProc list_opt file_in file_out prefix_invert
1500#  typeset -Z4 j4
1501#  typeset -Z3 j3
1502
1503#  unset list_opt
1504#  set +A list_opt $@
1505
1506  # Filename after rebuild
1507#  file_out=${list_opt[0]}
1508  # Prefix of output files
1509#  prefix_invert=$( basename ${file_out} .nc )
1510  # Number of procs
1511#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1512
1513#  iProc=0
1514#  while [ ${iProc} -lt ${num_proc} ] ; do
1515    # Array containing Station as a number
1516#    unset proc_stn
1517#    set +A proc_stn $( grep "iophy_mpi rank ip lon lat  $iProc" ${PREFIX}_${Exe_Output} | sed -e "s/iophy_mpi rank ip lon lat //g" | gawk ' {print $2}' )
1518    # Number of stations produced by processor proc
1519#    stationLast=${#proc_stn[*]}
1520    # Proc number on 4 digits
1521#    j4=${iProc}
1522    # Init
1523#    iStation=0
1524#    while [ ${iStation} -lt ${stationLast} ] ; do
1525      # Station number on 3 digits
1526#      j3=${proc_stn[${iStation}]}
1527      # Extract station
1528      # Invert Axis : t,x -> x,t
1529      #               t,pres,x -> x,t,pres
1530      # So that we can concatenate along x
1531#      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs -d x,$iStation,$iStation ${prefix_invert}_${j4}.nc ${prefix_invert}_stn_${j3}.nc
1532#      (( iStation = iStation + 1 ))
1533#    done
1534#    (( iProc = iProc + 1 ))
1535#  done
1536
1537  # Concatenate all station along x
1538#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1539
1540  # Re-invert file
1541#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1542
1543  # END reordering
1544
1545  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1546}
1547
1548############################################################
1549# Activate Running Environnment Variables
1550
1551#D-#==================================================
1552#D-function IGCM_sys_desactiv_variables
1553#D-* Purpose: set environement variables prior to execution
1554#D-* Examples:
1555#D-
1556function IGCM_sys_activ_variables {
1557  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1558  if ( $DEBUG_sys ) ; then
1559    echo "IGCM_sys_activ_variables"
1560  fi
1561
1562# --------------------------------------------------------------------
1563#D- MPI specifications
1564# --------------------------------------------------------------------
1565
1566# --------------------------------------------------------------------
1567#D- Other specifications
1568# --------------------------------------------------------------------
1569
1570  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1571}
1572
1573############################################################
1574# Desactivate Running Environnment Variables
1575
1576#D-#==================================================
1577#D-function IGCM_sys_desactiv_variables
1578#D-* Purpose: unset environement variables after execution
1579#D-* Examples:
1580#D-
1581function IGCM_sys_desactiv_variables {
1582  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1583  if ( $DEBUG_sys ) ; then
1584    echo "IGCM_sys_desactiv_variables"
1585  fi
1586# --------------------------------------------------------------------
1587#D- MPI specifications
1588# --------------------------------------------------------------------
1589
1590# --------------------------------------------------------------------
1591#D- Other specifications
1592# --------------------------------------------------------------------
1593
1594  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1595}
1596
1597############################################################
1598# Build MPI/OMP scripts run file (dummy function)
1599
1600#D-#==================================================
1601#D-function IGCM_sys_build_run_file
1602#D-* Purpose: build run file (deprecated)
1603#D-* Examples:
1604#D-
1605function IGCM_sys_build_run_file {
1606
1607  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1608
1609}
1610
1611############################################################
1612# Build MPI/OMP scripts
1613
1614#D-#==================================================
1615#D-function IGCM_sys_build_execution_scripts
1616#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1617#D-* Examples:
1618#D-
1619function IGCM_sys_build_execution_scripts
1620{
1621  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1622  if ( $DEBUG_sys ) ; then
1623    echo "IGCM_sys_build_execution_scripts " $@
1624  fi
1625  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1626  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1627  typeset num_corempi nombre_restant_node nombre_restant_comp
1628
1629  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1630    IGCM_debug_Exit "IGCM_sys_default build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1631  fi
1632
1633  if ( ${OK_PARA_MPMD} ) ; then
1634
1635    if [ -f run_file ] ; then
1636      IGCM_sys_Rm -f run_file
1637    fi
1638    touch run_file
1639
1640    if ( ${OK_PARA_OMP} ) ; then
1641
1642      #  Hosts treatment
1643
1644      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1645
1646      i=0
1647      rm -f hosts
1648      IGCM_debug_Print 1 "sys $( hostname ), Hosts avaible :"
1649      for nodes in `cat hosts.tmp` ; do
1650        host[$i]=$nodes
1651        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1652        IGCM_debug_Print 1 ${host[$i]}
1653        i=$((i+1))
1654      done
1655      rm -f hosts.tmp
1656
1657      listnodes=${host[*]}
1658
1659      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1660
1661      # Initialisation
1662
1663      init_node=y
1664      node_num_current=0
1665      start_num=0
1666      init_exec=n
1667
1668      # Test : if oasis is there, we put it at the first position
1669
1670      for comp in ${config_ListOfComponents[*]} ; do
1671
1672        if [ "X${comp}" = "XCPL" ]  ; then
1673
1674          eval ExeNameIn=\${config_Executable_${comp}[0]}
1675          eval ExeNameOut=\${config_Executable_${comp}[1]}
1676
1677          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1678          echo ""  >> script_${ExeNameOut}.ksh
1679          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1680          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1681          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1682          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1683          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1684
1685          init_node=n
1686
1687          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1688          node_num_current=0
1689          node_current=${host[${node_num_current}]}
1690
1691          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1692
1693          init_exec=y
1694          start_num=1
1695
1696        fi
1697
1698      done
1699
1700      # Then loop on the components (except for oasis)
1701
1702      for comp in ${config_ListOfComponents[*]} ; do
1703
1704        eval ExeNameIn=\${config_Executable_${comp}[0]}
1705        eval ExeNameOut=\${config_Executable_${comp}[1]}
1706
1707        # Only if we really have an executable for the component :
1708        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1709
1710          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1711          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1712
1713          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1714          # echo "set -vx" >> script_${ExeNameOut}.ksh
1715          echo ""  >> script_${ExeNameOut}.ksh
1716          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1717          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1718          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1719          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1720          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1721          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1722          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1723
1724          node_num=0
1725
1726          # We define the number of MPI process to be assigned for the component
1727
1728          nombre_restant_comp=${comp_proc_mpi_loc}
1729
1730          # Loop on the allocated nodes
1731
1732          for node in ${listnodes} ; do
1733
1734            # We go to the current node
1735            if [ ${node_num} = ${node_num_current} ] ; then
1736
1737              node_current=${host[${node_num_current}]}
1738
1739              # If first time on the node : initialisation
1740
1741              if [ ${init_node} = y ] ; then
1742                nombre_restant_node=${NUM_COREPERNODE}
1743              fi
1744
1745              # Test on the number of OMP threads
1746
1747              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1748                (( node_num = node_num + 1 ))
1749                node_num_current=${node_num}
1750                init_node=y
1751                continue
1752              fi
1753
1754              # Number of MPI process to assign
1755
1756              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1757
1758              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1759                num_corempi=${nombre_restant_comp}
1760              fi
1761
1762              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1763              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1764
1765              if [ ${init_exec} = y ] ; then
1766                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1767              else
1768                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1769                init_exec=y
1770              fi
1771
1772              ((  start_num = num_corempi + start_num ))
1773
1774            else
1775
1776              (( node_num = node_num + 1 ))
1777              continue
1778            fi
1779
1780            # Test on the number of core/process remaining on the node/component
1781
1782            if [ ${nombre_restant_node} = 0 ] ; then
1783              (( node_num = node_num + 1 ))
1784              node_num_current=${node_num}
1785              init_node=y
1786
1787              if [ ${nombre_restant_comp} = 0 ] ; then
1788                break 1
1789              fi
1790            else
1791
1792              node_num_current=${node_num}
1793              init_node=n
1794
1795              if [ ${nombre_restant_comp} = 0 ] ; then
1796                break 1
1797              fi
1798            fi
1799          done
1800        fi
1801      done
1802
1803    else
1804
1805      # Then first loop on the components for the coupler ie oasis
1806
1807      ## the coupler ie oasis must be the first one
1808      for comp in ${config_ListOfComponents[*]} ; do
1809
1810        eval ExeNameOut=\${config_Executable_${comp}[1]}
1811
1812        # for CPL component only
1813        if [ "X${comp}" = "XCPL" ] ; then
1814          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1815          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1816        fi
1817      done
1818
1819      # Then second loop on the components
1820
1821      for comp in ${config_ListOfComponents[*]} ; do
1822
1823        eval ExeNameOut=\${config_Executable_${comp}[1]}
1824
1825        # Only if we really have an executable for the component and not the coupler ie oasis:
1826        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1827          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1828          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1829        fi
1830      done
1831      IGCM_sys_Chmod u+x run_file
1832
1833      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1834
1835    fi
1836
1837  else # Only one executable. launch it.
1838
1839    for comp in ${config_ListOfComponents[*]} ; do
1840
1841      # Only if we really have an executable for the component :
1842      eval ExeNameOut=\${config_Executable_${comp}[1]}
1843      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1844
1845        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1846        echo ""  >> script_${ExeNameOut}.ksh
1847        if ( ${OK_PARA_OMP} ) ; then
1848          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1849          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1850        fi
1851        if  ( ${OK_PARA_MPI} ) ; then
1852          # Default : mpirun used if nb_proc gt 1
1853          # pour sortie out/err par process
1854          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1855          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1856          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1857          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1858        else
1859          # Default : mpirun is NOT used if nb_proc eq 1
1860          # pour sortie out/err par process
1861          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1862          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1863          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1864          EXECUTION="time ./script_${ExeNameOut}.ksh"
1865        fi
1866      fi
1867    done
1868
1869  fi
1870
1871  IGCM_debug_Print 1 "sys $( hostname ) : execution command is"
1872  IGCM_debug_Print 1 "$EXECUTION"
1873
1874  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1875}
1876
1877#D-#==================================================
1878#D-function IGCM_sys_check_path
1879#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1880#D-* do not point to an important use directory. Stop immediately in that case.
1881#D-* Examples:
1882#D-
1883function IGCM_sys_check_path {
1884  IGCM_debug_PushStack "IGCM_sys_check_path"
1885  if ( $DEBUG_sys ) ; then
1886    echo "IGCM_sys_check_path"
1887  fi
1888
1889  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
1890    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1891    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1892    IGCM_debug_Exit "This will stop the job"
1893  fi
1894  IGCM_debug_PopStack "IGCM_sys_check_path"
1895}
1896
1897#D-#==================================================
1898#D-function IGCM_sys_check_quota. Dummy call here
1899#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1900#D-* Examples:
1901#D-
1902function IGCM_sys_check_quota {
1903  IGCM_debug_PushStack "IGCM_sys_check_quota"
1904  if ( $DEBUG_sys ) ; then
1905    echo "IGCM_sys_check_quota"
1906  fi
1907  IGCM_debug_PopStack "IGCM_sys_check_quota"
1908}
1909
1910#D-#==================================================
1911#D-function IGCM_sys_CountJobInQueue
1912#D-* Purpose: Check if job_name is currently
1913#D-  running or in queue
1914#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1915#D-
1916function IGCM_sys_CountJobInQueue {
1917  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1918  if ( $DEBUG_sys ) ; then
1919    echo "IGCM_sys_CountJobInQueue"
1920  fi
1921  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1922}
1923
1924##############################################################
1925# NCO OPERATOR
1926
1927#D-#==================================================
1928#D-function IGCM_sys_ncap2
1929#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1930#D-* Examples:
1931#D-
1932function IGCM_sys_ncap2 {
1933  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1934  if ( $DEBUG_sys ) ; then
1935    echo "IGCM_sys_ncap2 :" $@
1936  fi
1937
1938  typeset NB_ESSAI DELAI status i
1939  # number of tentative
1940  NB_ESSAI=3
1941  # time delay between tentative
1942  DELAI=2
1943
1944  i=0
1945  while [ $i -lt $NB_ESSAI ] ; do
1946    ncap2 "$@" > /tmp/out_command.$$ 2>&1
1947    status=$?
1948    if [ ${status} -gt 0 ] ; then
1949      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1950      cat /tmp/out_command.$$
1951      \rm /tmp/out_command.$$
1952      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1953      sleep $DELAI
1954    else
1955      \rm /tmp/out_command.$$
1956      break
1957    fi
1958    (( i = i + 1 ))
1959  done
1960
1961  if [ ${status} -gt 0 ] ; then
1962    echo "IGCM_sys_ncap2 : ncap2 error"
1963    IGCM_debug_Exit "ncap2"
1964  fi
1965
1966  IGCM_debug_PopStack "IGCM_sys_ncap2"
1967}
1968
1969#D-#==================================================
1970#D-function IGCM_sys_ncatted
1971#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
1972#D-* Examples:
1973#D-
1974function IGCM_sys_ncatted {
1975  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1976  if ( $DEBUG_sys ) ; then
1977    echo "IGCM_sys_ncatted :" $@
1978  fi
1979
1980  typeset NB_ESSAI DELAI status i
1981  # number of tentative
1982  NB_ESSAI=3
1983  # time delay between tentative
1984  DELAI=2
1985
1986  i=0
1987  while [ $i -lt $NB_ESSAI ] ; do
1988    ncatted "$@" > /tmp/out_command.$$ 2>&1
1989    status=$?
1990    if [ ${status} -gt 0 ] ; then
1991      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1992      cat /tmp/out_command.$$
1993      \rm /tmp/out_command.$$
1994      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1995      sleep $DELAI
1996    else
1997      \rm /tmp/out_command.$$
1998      break
1999    fi
2000    (( i = i + 1 ))
2001  done
2002
2003  if [ ${status} -gt 0 ] ; then
2004    echo "IGCM_sys_ncatted : ncatted error"
2005    IGCM_debug_Exit "ncatted"
2006  fi
2007
2008  IGCM_debug_PopStack "IGCM_sys_ncatted"
2009}
2010
2011#D-#==================================================
2012#D-function IGCM_sys_ncbo
2013#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2014#D-* Examples:
2015#D-
2016function IGCM_sys_ncbo {
2017  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2018  if ( $DEBUG_sys ) ; then
2019    echo "IGCM_sys_ncbo :" $@
2020  fi
2021
2022  typeset NB_ESSAI DELAI status i
2023  # number of tentative
2024  NB_ESSAI=3
2025  # time delay between tentative
2026  DELAI=2
2027
2028  i=0
2029  while [ $i -lt $NB_ESSAI ] ; do
2030    ncbo $@ > /tmp/out_command.$$ 2>&1
2031    status=$?
2032    if [ ${status} -gt 0 ] ; then
2033      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2034      cat /tmp/out_command.$$
2035      \rm /tmp/out_command.$$
2036      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2037      sleep $DELAI
2038    else
2039      \rm /tmp/out_command.$$
2040      break
2041    fi
2042    (( i = i + 1 ))
2043  done
2044
2045  if [ ${status} -gt 0 ] ; then
2046    echo "IGCM_sys_ncbo : ncbo error"
2047    IGCM_debug_Exit "ncbo"
2048  fi
2049
2050  IGCM_debug_PopStack "IGCM_sys_ncbo"
2051}
2052
2053#D-#==================================================
2054#D-function IGCM_sys_ncdif
2055#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2056#D-* Examples:
2057#D-
2058function IGCM_sys_ncdiff {
2059  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2060  if ( $DEBUG_sys ) ; then
2061    echo "IGCM_sys_ncdiff :" $@
2062  fi
2063
2064  typeset NB_ESSAI DELAI status i
2065  # number of tentative
2066  NB_ESSAI=3
2067  # time delay between tentative
2068  DELAI=2
2069
2070  i=0
2071  while [ $i -lt $NB_ESSAI ] ; do
2072    ncdiff $@ > /tmp/out_command.$$ 2>&1
2073    status=$?
2074    if [ ${status} -gt 0 ] ; then
2075      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2076      cat /tmp/out_command.$$
2077      \rm /tmp/out_command.$$
2078      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2079      sleep $DELAI
2080    else
2081      \rm /tmp/out_command.$$
2082      break
2083    fi
2084    (( i = i + 1 ))
2085  done
2086
2087  if [ ${status} -gt 0 ] ; then
2088    echo "IGCM_sys_ncdiff : ncdiff error"
2089    IGCM_debug_Exit "ncdiff"
2090  fi
2091
2092  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2093}
2094
2095#D-#==================================================
2096#D-function IGCM_sys_ncea
2097#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2098#D-* Examples:
2099#D-
2100function IGCM_sys_ncea {
2101  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2102  if ( $DEBUG_sys ) ; then
2103    echo "IGCM_sys_ncea :" $@
2104  fi
2105
2106  typeset NB_ESSAI DELAI status i
2107  # number of tentative
2108  NB_ESSAI=3
2109  # time delay between tentative
2110  DELAI=2
2111
2112  i=0
2113  while [ $i -lt $NB_ESSAI ] ; do
2114    ncea $@ > /tmp/out_command.$$ 2>&1
2115    status=$?
2116    if [ ${status} -gt 0 ] ; then
2117      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2118      cat /tmp/out_command.$$
2119      \rm /tmp/out_command.$$
2120      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2121      sleep $DELAI
2122    else
2123      \rm /tmp/out_command.$$
2124      break
2125    fi
2126    (( i = i + 1 ))
2127  done
2128
2129  if [ ${status} -gt 0 ] ; then
2130    echo "IGCM_sys_ncea : ncea error"
2131    IGCM_debug_Exit "ncea"
2132  fi
2133
2134  IGCM_debug_PopStack "IGCM_sys_ncea"
2135}
2136
2137#D-#==================================================
2138#D-function IGCM_sys_ncecat
2139#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2140#D-* Examples:
2141#D-
2142function IGCM_sys_ncecat {
2143  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2144  if ( $DEBUG_sys ) ; then
2145    echo "IGCM_sys_ncecat :" $@
2146  fi
2147
2148  typeset NB_ESSAI DELAI status i
2149  # number of tentative
2150  NB_ESSAI=3
2151  # time delay between tentative
2152  DELAI=2
2153
2154  i=0
2155  while [ $i -lt $NB_ESSAI ] ; do
2156    ncecat $@ > /tmp/out_command.$$ 2>&1
2157    status=$?
2158    if [ ${status} -gt 0 ] ; then
2159      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2160      cat /tmp/out_command.$$
2161      \rm /tmp/out_command.$$
2162      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2163      sleep $DELAI
2164    else
2165      \rm /tmp/out_command.$$
2166      break
2167    fi
2168    (( i = i + 1 ))
2169  done
2170
2171  if [ ${status} -gt 0 ] ; then
2172    echo "IGCM_sys_ncecat : ncecat error"
2173    IGCM_debug_Exit "ncecat"
2174  fi
2175
2176  IGCM_debug_PopStack "IGCM_sys_ncecat"
2177}
2178
2179#D-#==================================================
2180#D-function IGCM_sys_ncflint
2181#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2182#D-* Examples:
2183#D-
2184function IGCM_sys_ncflint {
2185  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2186  if ( $DEBUG_sys ) ; then
2187    echo "IGCM_sys_ncflint :" $@
2188  fi
2189
2190  typeset NB_ESSAI DELAI status i
2191  # number of tentative
2192  NB_ESSAI=3
2193  # time delay between tentative
2194  DELAI=2
2195
2196  i=0
2197  while [ $i -lt $NB_ESSAI ] ; do
2198    ncflint $@ > /tmp/out_command.$$ 2>&1
2199    status=$?
2200    if [ ${status} -gt 0 ] ; then
2201      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2202      cat /tmp/out_command.$$
2203      \rm /tmp/out_command.$$
2204      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2205      sleep $DELAI
2206    else
2207      \rm /tmp/out_command.$$
2208      break
2209    fi
2210    (( i = i + 1 ))
2211  done
2212
2213  if [ ${status} -gt 0 ] ; then
2214    echo "IGCM_sys_ncflint : ncflint error"
2215    IGCM_debug_Exit "ncflint"
2216  fi
2217
2218  IGCM_debug_PopStack "IGCM_sys_ncflint"
2219}
2220
2221#D-#==================================================
2222#D-function IGCM_sys_ncks
2223#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2224#D-* Examples:
2225#D-
2226function IGCM_sys_ncks {
2227  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2228  if ( $DEBUG_sys ) ; then
2229    echo "IGCM_sys_ncks :" $@
2230  fi
2231
2232  typeset NB_ESSAI DELAI status i
2233  # number of tentative
2234  NB_ESSAI=3
2235  # time delay between tentative
2236  DELAI=2
2237
2238  i=0
2239  while [ $i -lt $NB_ESSAI ] ; do
2240    ncks $@ > /tmp/out_command.$$ 2>&1
2241    status=$?
2242    if [ ${status} -gt 0 ] ; then
2243      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2244      cat /tmp/out_command.$$
2245      \rm /tmp/out_command.$$
2246      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2247      sleep $DELAI
2248    else
2249      \rm /tmp/out_command.$$
2250      break
2251    fi
2252    (( i = i + 1 ))
2253  done
2254
2255  if [ ${status} -gt 0 ] ; then
2256    echo "IGCM_sys_ncks : ncks error"
2257    IGCM_debug_Exit "ncks"
2258  fi
2259
2260  IGCM_debug_PopStack "IGCM_sys_ncks"
2261}
2262
2263#D-#==================================================
2264#D-function IGCM_sys_ncpdq
2265#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2266#D-* Examples:
2267#D-
2268function IGCM_sys_ncpdq {
2269  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2270  if ( $DEBUG_sys ) ; then
2271    echo "IGCM_sys_ncpdq :" $@
2272  fi
2273
2274  typeset NB_ESSAI DELAI status i
2275  # number of tentative
2276  NB_ESSAI=3
2277  # time delay between tentative
2278  DELAI=2
2279
2280  i=0
2281  while [ $i -lt $NB_ESSAI ] ; do
2282    ncpdq $@ > /tmp/out_command.$$ 2>&1
2283    status=$?
2284    if [ ${status} -gt 0 ] ; then
2285      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2286      cat /tmp/out_command.$$
2287      \rm /tmp/out_command.$$
2288      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2289      sleep $DELAI
2290    else
2291      \rm /tmp/out_command.$$
2292      break
2293    fi
2294    (( i = i + 1 ))
2295  done
2296
2297  if [ ${status} -gt 0 ] ; then
2298    echo "IGCM_sys_ncpdq : ncpdq error"
2299    IGCM_debug_Exit "ncpdq"
2300  fi
2301
2302  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2303}
2304
2305#D-#==================================================
2306#D-function IGCM_sys_ncra
2307#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2308#D-* Examples:
2309#D-
2310function IGCM_sys_ncra {
2311  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2312  if ( $DEBUG_sys ) ; then
2313    echo "IGCM_sys_ncra :" $@
2314  fi
2315
2316  typeset NB_ESSAI DELAI status i
2317  # number of tentative
2318  NB_ESSAI=3
2319  # time delay between tentative
2320  DELAI=2
2321
2322  i=0
2323  while [ $i -lt $NB_ESSAI ] ; do
2324    ncra $@ > /tmp/out_command.$$ 2>&1
2325    status=$?
2326    if [ ${status} -gt 0 ] ; then
2327      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2328      cat /tmp/out_command.$$
2329      \rm /tmp/out_command.$$
2330      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2331      sleep $DELAI
2332    else
2333      \rm /tmp/out_command.$$
2334      break
2335    fi
2336    (( i = i + 1 ))
2337  done
2338
2339  if [ ${status} -gt 0 ] ; then
2340    echo "IGCM_sys_ncra : ncra error"
2341    IGCM_debug_Exit "ncra"
2342  fi
2343
2344  IGCM_debug_PopStack "IGCM_sys_ncra"
2345}
2346
2347#D-#==================================================
2348#D-function IGCM_sys_ncrcat
2349#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2350#D-* Examples:
2351#D-
2352function IGCM_sys_ncrcat {
2353  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2354  if ( $DEBUG_sys ) ; then
2355    echo "IGCM_sys_ncrcat :" $@
2356  fi
2357
2358  typeset NB_ESSAI DELAI status i lastArg
2359  # number of tentative
2360  NB_ESSAI=3
2361  # time delay between tentative
2362  DELAI=2
2363
2364  i=0
2365  while [ $i -lt $NB_ESSAI ] ; do
2366    ncrcat $@ > /tmp/out_command.$$ 2>&1
2367    status=$?
2368    if [ ${status} -gt 0 ] ; then
2369      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2370      cat /tmp/out_command.$$
2371      \rm /tmp/out_command.$$
2372      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2373      sleep $DELAI
2374    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command.$$ )" = "X" ] ; then
2375      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2376      cat /tmp/out_command.$$
2377      # remove files having corrupted time axis
2378      eval lastArg=\${$#}
2379      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2380      \rm ${lastArg}
2381      \rm /tmp/out_command.$$
2382      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2383      sleep $DELAI
2384    else
2385      \rm /tmp/out_command.$$
2386      break
2387    fi
2388    (( i = i + 1 ))
2389  done
2390
2391  if [ ${status} -gt 0 ] ; then
2392    echo "IGCM_sys_ncrcat : ncrcat error"
2393    #IGCM_debug_Exit "ncrcat"
2394  fi
2395
2396  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2397}
2398
2399#D-#==================================================
2400#D-function IGCM_sys_ncrename
2401#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2402#D-* Examples:
2403#D-
2404function IGCM_sys_ncrename {
2405  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2406  if ( $DEBUG_sys ) ; then
2407    echo "IGCM_sys_ncrename :" $@
2408  fi
2409
2410  typeset NB_ESSAI DELAI status i
2411  # number of tentative
2412  NB_ESSAI=3
2413  # time delay between tentative
2414  DELAI=2
2415
2416  i=0
2417  while [ $i -lt $NB_ESSAI ] ; do
2418    ncrename $@ > /tmp/out_command.$$ 2>&1
2419    status=$?
2420    if [ ${status} -gt 0 ] ; then
2421      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2422      cat /tmp/out_command.$$
2423      \rm /tmp/out_command.$$
2424      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2425      sleep $DELAI
2426    else
2427      \rm /tmp/out_command.$$
2428      break
2429    fi
2430    (( i = i + 1 ))
2431  done
2432
2433  if [ ${status} -gt 0 ] ; then
2434    echo "IGCM_sys_ncrename : ncrename error"
2435    IGCM_debug_Exit "ncrename"
2436  fi
2437
2438  IGCM_debug_PopStack "IGCM_sys_ncrename"
2439}
2440
2441#D-#==================================================
2442#D-function IGCM_sys_ncwa
2443#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2444#D-* Examples:
2445#D-
2446function IGCM_sys_ncwa {
2447  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2448  if ( $DEBUG_sys ) ; then
2449    echo "IGCM_sys_ncwa :" $@
2450  fi
2451
2452  typeset NB_ESSAI DELAI status i
2453  # number of tentative
2454  NB_ESSAI=3
2455  # time delay between tentative
2456  DELAI=2
2457
2458  i=0
2459  while [ $i -lt $NB_ESSAI ] ; do
2460    ncwa $@ > /tmp/out_command.$$ 2>&1
2461    status=$?
2462    if [ ${status} -gt 0 ] ; then
2463      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2464      cat /tmp/out_command.$$
2465      \rm /tmp/out_command.$$
2466      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2467      sleep $DELAI
2468    else
2469      \rm /tmp/out_command.$$
2470      break
2471    fi
2472    (( i = i + 1 ))
2473  done
2474
2475  if [ ${status} -gt 0 ] ; then
2476    echo "IGCM_sys_ncwa : ncwa error"
2477    IGCM_debug_Exit "ncwa"
2478  fi
2479
2480  IGCM_debug_PopStack "IGCM_sys_ncwa"
2481}
2482
2483##############################################################
2484# CDO OPERATOR
2485
2486#D-#==================================================
2487#D-function IGCM_sys_cdo
2488#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2489#D-* Examples:
2490#D-
2491function IGCM_sys_cdo {
2492  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2493  if ( $DEBUG_sys ) ; then
2494    echo "IGCM_sys_cdo :" $@
2495  fi
2496
2497  typeset status
2498
2499  \cdo $@ > /tmp/out_command.$$ 2>&1
2500  status=$?
2501  if [ ${status} -gt 0 ] ; then
2502    echo "IGCM_sys_cdo : error code ${status}"
2503    cat /tmp/out_command.$$
2504    \rm /tmp/out_command.$$
2505    IGCM_debug_PopStack "IGCM_sys_cdo"
2506    return 1
2507  else
2508    IGCM_debug_PopStack "IGCM_sys_cdo"
2509    return 0
2510  fi
2511
2512  IGCM_debug_PopStack "IGCM_sys_cdo"
2513}
Note: See TracBrowser for help on using the repository browser.