source: tags/libIGCM_v2.2/libIGCM_sys/libIGCM_sys_default.ksh

Last change on this file was 938, checked in by sdipsl, 11 years ago

cleanup.
replace out_rsync by /tmp/out_command.$$

  • 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.4 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    prefix_invert=$( basename ${file_in} .nc )
1469    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1470    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1471  done
1472
1473  # Concatenate
1474  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1475
1476  # Re-ivert file
1477  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1478
1479  # Station re-ordering is too expansive to be run within libIGCM
1480  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1481  # This re-ordering must be done "in memory" by the cmorization process
1482  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1483  # BEGIN reordering
1484
1485  # Only LMDZ text output contains the exact ordering of the station.
1486  # We isolate this in the code below:
1487  #  0  38  -157.5000000000000  70.98591549295774
1488  #  0  54  27.49999999999999   67.18309859154928
1489  #  0  56  -62.50000000000001  82.39436619718309
1490  #  0  79  12.49999999999999   78.59154929577466
1491  #  0  116 -165.0000000000000  76.05633802816901
1492  #  0  117 130.0000000000000   70.98591549295774
1493  #  0  118 110.0000000000000   87.46478873239437
1494  #  1  40  4.999999999999995   51.97183098591550
1495#  typeset iStation iProc list_opt file_in file_out prefix_invert
1496#  typeset -Z4 j4
1497#  typeset -Z3 j3
1498
1499#  unset list_opt
1500#  set +A list_opt $@
1501
1502  # Filename after rebuild
1503#  file_out=${list_opt[0]}
1504  # Prefix of output files
1505#  prefix_invert=$( basename ${file_out} .nc )
1506  # Number of procs
1507#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1508
1509#  iProc=0
1510#  while [ ${iProc} -lt ${num_proc} ] ; do
1511    # Array containing Station as a number
1512#    unset proc_stn
1513#    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}' )
1514    # Number of stations produced by processor proc
1515#    stationLast=${#proc_stn[*]}
1516    # Proc number on 4 digits
1517#    j4=${iProc}
1518    # Init
1519#    iStation=0
1520#    while [ ${iStation} -lt ${stationLast} ] ; do
1521      # Station number on 3 digits
1522#      j3=${proc_stn[${iStation}]}
1523      # Extract station
1524      # Invert Axis : t,x -> x,t
1525      #               t,pres,x -> x,t,pres
1526      # So that we can concatenate along x
1527#      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
1528#      (( iStation = iStation + 1 ))
1529#    done
1530#    (( iProc = iProc + 1 ))
1531#  done
1532
1533  # Concatenate all station along x
1534#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1535
1536  # Re-invert file
1537#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1538
1539  # END reordering
1540
1541  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1542}
1543
1544############################################################
1545# Activate Running Environnment Variables
1546
1547#D-#==================================================
1548#D-function IGCM_sys_desactiv_variables
1549#D-* Purpose: set environement variables prior to execution
1550#D-* Examples:
1551#D-
1552function IGCM_sys_activ_variables {
1553  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1554  if ( $DEBUG_sys ) ; then
1555    echo "IGCM_sys_activ_variables"
1556  fi
1557
1558# --------------------------------------------------------------------
1559#D- MPI specifications
1560# --------------------------------------------------------------------
1561
1562# --------------------------------------------------------------------
1563#D- Other specifications
1564# --------------------------------------------------------------------
1565
1566  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1567}
1568
1569############################################################
1570# Desactivate Running Environnment Variables
1571
1572#D-#==================================================
1573#D-function IGCM_sys_desactiv_variables
1574#D-* Purpose: unset environement variables after execution
1575#D-* Examples:
1576#D-
1577function IGCM_sys_desactiv_variables {
1578  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1579  if ( $DEBUG_sys ) ; then
1580    echo "IGCM_sys_desactiv_variables"
1581  fi
1582# --------------------------------------------------------------------
1583#D- MPI specifications
1584# --------------------------------------------------------------------
1585
1586# --------------------------------------------------------------------
1587#D- Other specifications
1588# --------------------------------------------------------------------
1589
1590  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1591}
1592
1593############################################################
1594# Build MPI/OMP scripts run file (dummy function)
1595
1596#D-#==================================================
1597#D-function IGCM_sys_build_run_file
1598#D-* Purpose: build run file (deprecated)
1599#D-* Examples:
1600#D-
1601function IGCM_sys_build_run_file {
1602
1603  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1604
1605}
1606
1607############################################################
1608# Build MPI/OMP scripts
1609
1610#D-#==================================================
1611#D-function IGCM_sys_build_execution_scripts
1612#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1613#D-* Examples:
1614#D-
1615function IGCM_sys_build_execution_scripts
1616{
1617  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1618  if ( $DEBUG_sys ) ; then
1619    echo "IGCM_sys_build_execution_scripts " $@
1620  fi
1621  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1622  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1623  typeset num_corempi nombre_restant_node nombre_restant_comp
1624
1625  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1626    IGCM_debug_Exit "IGCM_sys_default build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1627  fi
1628
1629  if ( ${OK_PARA_MPMD} ) ; then
1630
1631    if [ -f run_file ] ; then
1632      IGCM_sys_Rm -f run_file
1633    fi
1634    touch run_file
1635
1636    if ( ${OK_PARA_OMP} ) ; then
1637
1638      #  Hosts treatment
1639
1640      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1641
1642      i=0
1643      rm -f hosts
1644      IGCM_debug_Print 1 "sys $( hostname ), Hosts avaible :"
1645      for nodes in `cat hosts.tmp` ; do
1646        host[$i]=$nodes
1647        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1648        IGCM_debug_Print 1 ${host[$i]}
1649        i=$((i+1))
1650      done
1651      rm -f hosts.tmp
1652
1653      listnodes=${host[*]}
1654
1655      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1656
1657      # Initialisation
1658
1659      init_node=y
1660      node_num_current=0
1661      start_num=0
1662      init_exec=n
1663
1664      # Test : if oasis is there, we put it at the first position
1665
1666      for comp in ${config_ListOfComponents[*]} ; do
1667
1668        if [ "X${comp}" = "XCPL" ]  ; then
1669
1670          eval ExeNameIn=\${config_Executable_${comp}[0]}
1671          eval ExeNameOut=\${config_Executable_${comp}[1]}
1672
1673          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1674          echo ""  >> script_${ExeNameOut}.ksh
1675          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1676          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1677          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1678          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1679          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1680
1681          init_node=n
1682
1683          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1684          node_num_current=0
1685          node_current=${host[${node_num_current}]}
1686
1687          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1688
1689          init_exec=y
1690          start_num=1
1691
1692        fi
1693
1694      done
1695
1696      # Then loop on the components (except for oasis)
1697
1698      for comp in ${config_ListOfComponents[*]} ; do
1699
1700        eval ExeNameIn=\${config_Executable_${comp}[0]}
1701        eval ExeNameOut=\${config_Executable_${comp}[1]}
1702
1703        # Only if we really have an executable for the component :
1704        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1705
1706          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1707          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1708
1709          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1710          # echo "set -vx" >> script_${ExeNameOut}.ksh
1711          echo ""  >> script_${ExeNameOut}.ksh
1712          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1713          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1714          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1715          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1716          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1717          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1718          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1719
1720          node_num=0
1721
1722          # We define the number of MPI process to be assigned for the component
1723
1724          nombre_restant_comp=${comp_proc_mpi_loc}
1725
1726          # Loop on the allocated nodes
1727
1728          for node in ${listnodes} ; do
1729
1730            # We go to the current node
1731            if [ ${node_num} = ${node_num_current} ] ; then
1732
1733              node_current=${host[${node_num_current}]}
1734
1735              # If first time on the node : initialisation
1736
1737              if [ ${init_node} = y ] ; then
1738                nombre_restant_node=${NUM_COREPERNODE}
1739              fi
1740
1741              # Test on the number of OMP threads
1742
1743              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1744                (( node_num = node_num + 1 ))
1745                node_num_current=${node_num}
1746                init_node=y
1747                continue
1748              fi
1749
1750              # Number of MPI process to assign
1751
1752              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1753
1754              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1755                num_corempi=${nombre_restant_comp}
1756              fi
1757
1758              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1759              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1760
1761              if [ ${init_exec} = y ] ; then
1762                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1763              else
1764                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1765                init_exec=y
1766              fi
1767
1768              ((  start_num = num_corempi + start_num ))
1769
1770            else
1771
1772              (( node_num = node_num + 1 ))
1773              continue
1774            fi
1775
1776            # Test on the number of core/process remaining on the node/component
1777
1778            if [ ${nombre_restant_node} = 0 ] ; then
1779              (( node_num = node_num + 1 ))
1780              node_num_current=${node_num}
1781              init_node=y
1782
1783              if [ ${nombre_restant_comp} = 0 ] ; then
1784                break 1
1785              fi
1786            else
1787
1788              node_num_current=${node_num}
1789              init_node=n
1790
1791              if [ ${nombre_restant_comp} = 0 ] ; then
1792                break 1
1793              fi
1794            fi
1795          done
1796        fi
1797      done
1798
1799    else
1800
1801      # Then first loop on the components for the coupler ie oasis
1802
1803      ## the coupler ie oasis must be the first one
1804      for comp in ${config_ListOfComponents[*]} ; do
1805
1806        eval ExeNameOut=\${config_Executable_${comp}[1]}
1807
1808        # for CPL component only
1809        if [ "X${comp}" = "XCPL" ] ; then
1810          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1811          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1812        fi
1813      done
1814
1815      # Then second loop on the components
1816
1817      for comp in ${config_ListOfComponents[*]} ; do
1818
1819        eval ExeNameOut=\${config_Executable_${comp}[1]}
1820
1821        # Only if we really have an executable for the component and not the coupler ie oasis:
1822        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1823          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1824          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1825        fi
1826      done
1827      IGCM_sys_Chmod u+x run_file
1828
1829      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1830
1831    fi
1832
1833  else # Only one executable. launch it.
1834
1835    for comp in ${config_ListOfComponents[*]} ; do
1836
1837      # Only if we really have an executable for the component :
1838      eval ExeNameOut=\${config_Executable_${comp}[1]}
1839      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1840
1841        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1842        echo ""  >> script_${ExeNameOut}.ksh
1843        if ( ${OK_PARA_OMP} ) ; then
1844          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1845          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1846        fi
1847        if  ( ${OK_PARA_MPI} ) ; then
1848          # Default : mpirun used if nb_proc gt 1
1849          # pour sortie out/err par process
1850          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1851          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1852          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1853          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1854        else
1855          # Default : mpirun is NOT used if nb_proc eq 1
1856          # pour sortie out/err par process
1857          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1858          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1859          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1860          EXECUTION="time ./script_${ExeNameOut}.ksh"
1861        fi
1862      fi
1863    done
1864
1865  fi
1866
1867  IGCM_debug_Print 1 "sys $( hostname ) : execution command is"
1868  IGCM_debug_Print 1 "$EXECUTION"
1869
1870  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1871}
1872
1873#D-#==================================================
1874#D-function IGCM_sys_check_path
1875#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1876#D-* do not point to an important use directory. Stop immediately in that case.
1877#D-* Examples:
1878#D-
1879function IGCM_sys_check_path {
1880  IGCM_debug_PushStack "IGCM_sys_check_path"
1881  if ( $DEBUG_sys ) ; then
1882    echo "IGCM_sys_check_path"
1883  fi
1884
1885  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
1886    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1887    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1888    IGCM_debug_Exit "This will stop the job"
1889  fi
1890  IGCM_debug_PopStack "IGCM_sys_check_path"
1891}
1892
1893#D-#==================================================
1894#D-function IGCM_sys_check_quota. Dummy call here
1895#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1896#D-* Examples:
1897#D-
1898function IGCM_sys_check_quota {
1899  IGCM_debug_PushStack "IGCM_sys_check_quota"
1900  if ( $DEBUG_sys ) ; then
1901    echo "IGCM_sys_check_quota"
1902  fi
1903  IGCM_debug_PopStack "IGCM_sys_check_quota"
1904}
1905
1906#D-#==================================================
1907#D-function IGCM_sys_CountJobInQueue
1908#D-* Purpose: Check if job_name is currently
1909#D-  running or in queue
1910#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1911#D-
1912function IGCM_sys_CountJobInQueue {
1913  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1914  if ( $DEBUG_sys ) ; then
1915    echo "IGCM_sys_CountJobInQueue"
1916  fi
1917  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1918}
1919
1920##############################################################
1921# NCO OPERATOR
1922
1923#D-#==================================================
1924#D-function IGCM_sys_ncap2
1925#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1926#D-* Examples:
1927#D-
1928function IGCM_sys_ncap2 {
1929  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1930  if ( $DEBUG_sys ) ; then
1931    echo "IGCM_sys_ncap2 :" $@
1932  fi
1933
1934  typeset NB_ESSAI DELAI status i
1935  # number of tentative
1936  NB_ESSAI=3
1937  # time delay between tentative
1938  DELAI=2
1939
1940  i=0
1941  while [ $i -lt $NB_ESSAI ] ; do
1942    ncap2 "$@" > /tmp/out_command.$$ 2>&1
1943    status=$?
1944    if [ ${status} -gt 0 ] ; then
1945      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1946      cat /tmp/out_command.$$
1947      \rm /tmp/out_command.$$
1948      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1949      sleep $DELAI
1950    else
1951      \rm /tmp/out_command.$$
1952      break
1953    fi
1954    (( i = i + 1 ))
1955  done
1956
1957  if [ ${status} -gt 0 ] ; then
1958    echo "IGCM_sys_ncap2 : ncap2 error"
1959    IGCM_debug_Exit "ncap2"
1960  fi
1961
1962  IGCM_debug_PopStack "IGCM_sys_ncap2"
1963}
1964
1965#D-#==================================================
1966#D-function IGCM_sys_ncatted
1967#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
1968#D-* Examples:
1969#D-
1970function IGCM_sys_ncatted {
1971  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1972  if ( $DEBUG_sys ) ; then
1973    echo "IGCM_sys_ncatted :" $@
1974  fi
1975
1976  typeset NB_ESSAI DELAI status i
1977  # number of tentative
1978  NB_ESSAI=3
1979  # time delay between tentative
1980  DELAI=2
1981
1982  i=0
1983  while [ $i -lt $NB_ESSAI ] ; do
1984    ncatted "$@" > /tmp/out_command.$$ 2>&1
1985    status=$?
1986    if [ ${status} -gt 0 ] ; then
1987      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1988      cat /tmp/out_command.$$
1989      \rm /tmp/out_command.$$
1990      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1991      sleep $DELAI
1992    else
1993      \rm /tmp/out_command.$$
1994      break
1995    fi
1996    (( i = i + 1 ))
1997  done
1998
1999  if [ ${status} -gt 0 ] ; then
2000    echo "IGCM_sys_ncatted : ncatted error"
2001    IGCM_debug_Exit "ncatted"
2002  fi
2003
2004  IGCM_debug_PopStack "IGCM_sys_ncatted"
2005}
2006
2007#D-#==================================================
2008#D-function IGCM_sys_ncbo
2009#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2010#D-* Examples:
2011#D-
2012function IGCM_sys_ncbo {
2013  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2014  if ( $DEBUG_sys ) ; then
2015    echo "IGCM_sys_ncbo :" $@
2016  fi
2017
2018  typeset NB_ESSAI DELAI status i
2019  # number of tentative
2020  NB_ESSAI=3
2021  # time delay between tentative
2022  DELAI=2
2023
2024  i=0
2025  while [ $i -lt $NB_ESSAI ] ; do
2026    ncbo $@ > /tmp/out_command.$$ 2>&1
2027    status=$?
2028    if [ ${status} -gt 0 ] ; then
2029      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2030      cat /tmp/out_command.$$
2031      \rm /tmp/out_command.$$
2032      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2033      sleep $DELAI
2034    else
2035      \rm /tmp/out_command.$$
2036      break
2037    fi
2038    (( i = i + 1 ))
2039  done
2040
2041  if [ ${status} -gt 0 ] ; then
2042    echo "IGCM_sys_ncbo : ncbo error"
2043    IGCM_debug_Exit "ncbo"
2044  fi
2045
2046  IGCM_debug_PopStack "IGCM_sys_ncbo"
2047}
2048
2049#D-#==================================================
2050#D-function IGCM_sys_ncdif
2051#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2052#D-* Examples:
2053#D-
2054function IGCM_sys_ncdiff {
2055  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2056  if ( $DEBUG_sys ) ; then
2057    echo "IGCM_sys_ncdiff :" $@
2058  fi
2059
2060  typeset NB_ESSAI DELAI status i
2061  # number of tentative
2062  NB_ESSAI=3
2063  # time delay between tentative
2064  DELAI=2
2065
2066  i=0
2067  while [ $i -lt $NB_ESSAI ] ; do
2068    ncdiff $@ > /tmp/out_command.$$ 2>&1
2069    status=$?
2070    if [ ${status} -gt 0 ] ; then
2071      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2072      cat /tmp/out_command.$$
2073      \rm /tmp/out_command.$$
2074      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2075      sleep $DELAI
2076    else
2077      \rm /tmp/out_command.$$
2078      break
2079    fi
2080    (( i = i + 1 ))
2081  done
2082
2083  if [ ${status} -gt 0 ] ; then
2084    echo "IGCM_sys_ncdiff : ncdiff error"
2085    IGCM_debug_Exit "ncdiff"
2086  fi
2087
2088  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2089}
2090
2091#D-#==================================================
2092#D-function IGCM_sys_ncea
2093#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2094#D-* Examples:
2095#D-
2096function IGCM_sys_ncea {
2097  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2098  if ( $DEBUG_sys ) ; then
2099    echo "IGCM_sys_ncea :" $@
2100  fi
2101
2102  typeset NB_ESSAI DELAI status i
2103  # number of tentative
2104  NB_ESSAI=3
2105  # time delay between tentative
2106  DELAI=2
2107
2108  i=0
2109  while [ $i -lt $NB_ESSAI ] ; do
2110    ncea $@ > /tmp/out_command.$$ 2>&1
2111    status=$?
2112    if [ ${status} -gt 0 ] ; then
2113      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2114      cat /tmp/out_command.$$
2115      \rm /tmp/out_command.$$
2116      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2117      sleep $DELAI
2118    else
2119      \rm /tmp/out_command.$$
2120      break
2121    fi
2122    (( i = i + 1 ))
2123  done
2124
2125  if [ ${status} -gt 0 ] ; then
2126    echo "IGCM_sys_ncea : ncea error"
2127    IGCM_debug_Exit "ncea"
2128  fi
2129
2130  IGCM_debug_PopStack "IGCM_sys_ncea"
2131}
2132
2133#D-#==================================================
2134#D-function IGCM_sys_ncecat
2135#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2136#D-* Examples:
2137#D-
2138function IGCM_sys_ncecat {
2139  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2140  if ( $DEBUG_sys ) ; then
2141    echo "IGCM_sys_ncecat :" $@
2142  fi
2143
2144  typeset NB_ESSAI DELAI status i
2145  # number of tentative
2146  NB_ESSAI=3
2147  # time delay between tentative
2148  DELAI=2
2149
2150  i=0
2151  while [ $i -lt $NB_ESSAI ] ; do
2152    ncecat $@ > /tmp/out_command.$$ 2>&1
2153    status=$?
2154    if [ ${status} -gt 0 ] ; then
2155      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2156      cat /tmp/out_command.$$
2157      \rm /tmp/out_command.$$
2158      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2159      sleep $DELAI
2160    else
2161      \rm /tmp/out_command.$$
2162      break
2163    fi
2164    (( i = i + 1 ))
2165  done
2166
2167  if [ ${status} -gt 0 ] ; then
2168    echo "IGCM_sys_ncecat : ncecat error"
2169    IGCM_debug_Exit "ncecat"
2170  fi
2171
2172  IGCM_debug_PopStack "IGCM_sys_ncecat"
2173}
2174
2175#D-#==================================================
2176#D-function IGCM_sys_ncflint
2177#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2178#D-* Examples:
2179#D-
2180function IGCM_sys_ncflint {
2181  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2182  if ( $DEBUG_sys ) ; then
2183    echo "IGCM_sys_ncflint :" $@
2184  fi
2185
2186  typeset NB_ESSAI DELAI status i
2187  # number of tentative
2188  NB_ESSAI=3
2189  # time delay between tentative
2190  DELAI=2
2191
2192  i=0
2193  while [ $i -lt $NB_ESSAI ] ; do
2194    ncflint $@ > /tmp/out_command.$$ 2>&1
2195    status=$?
2196    if [ ${status} -gt 0 ] ; then
2197      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2198      cat /tmp/out_command.$$
2199      \rm /tmp/out_command.$$
2200      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2201      sleep $DELAI
2202    else
2203      \rm /tmp/out_command.$$
2204      break
2205    fi
2206    (( i = i + 1 ))
2207  done
2208
2209  if [ ${status} -gt 0 ] ; then
2210    echo "IGCM_sys_ncflint : ncflint error"
2211    IGCM_debug_Exit "ncflint"
2212  fi
2213
2214  IGCM_debug_PopStack "IGCM_sys_ncflint"
2215}
2216
2217#D-#==================================================
2218#D-function IGCM_sys_ncks
2219#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2220#D-* Examples:
2221#D-
2222function IGCM_sys_ncks {
2223  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2224  if ( $DEBUG_sys ) ; then
2225    echo "IGCM_sys_ncks :" $@
2226  fi
2227
2228  typeset NB_ESSAI DELAI status i
2229  # number of tentative
2230  NB_ESSAI=3
2231  # time delay between tentative
2232  DELAI=2
2233
2234  i=0
2235  while [ $i -lt $NB_ESSAI ] ; do
2236    ncks $@ > /tmp/out_command.$$ 2>&1
2237    status=$?
2238    if [ ${status} -gt 0 ] ; then
2239      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2240      cat /tmp/out_command.$$
2241      \rm /tmp/out_command.$$
2242      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2243      sleep $DELAI
2244    else
2245      \rm /tmp/out_command.$$
2246      break
2247    fi
2248    (( i = i + 1 ))
2249  done
2250
2251  if [ ${status} -gt 0 ] ; then
2252    echo "IGCM_sys_ncks : ncks error"
2253    IGCM_debug_Exit "ncks"
2254  fi
2255
2256  IGCM_debug_PopStack "IGCM_sys_ncks"
2257}
2258
2259#D-#==================================================
2260#D-function IGCM_sys_ncpdq
2261#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2262#D-* Examples:
2263#D-
2264function IGCM_sys_ncpdq {
2265  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2266  if ( $DEBUG_sys ) ; then
2267    echo "IGCM_sys_ncpdq :" $@
2268  fi
2269
2270  typeset NB_ESSAI DELAI status i
2271  # number of tentative
2272  NB_ESSAI=3
2273  # time delay between tentative
2274  DELAI=2
2275
2276  i=0
2277  while [ $i -lt $NB_ESSAI ] ; do
2278    ncpdq $@ > /tmp/out_command.$$ 2>&1
2279    status=$?
2280    if [ ${status} -gt 0 ] ; then
2281      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2282      cat /tmp/out_command.$$
2283      \rm /tmp/out_command.$$
2284      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2285      sleep $DELAI
2286    else
2287      \rm /tmp/out_command.$$
2288      break
2289    fi
2290    (( i = i + 1 ))
2291  done
2292
2293  if [ ${status} -gt 0 ] ; then
2294    echo "IGCM_sys_ncpdq : ncpdq error"
2295    IGCM_debug_Exit "ncpdq"
2296  fi
2297
2298  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2299}
2300
2301#D-#==================================================
2302#D-function IGCM_sys_ncra
2303#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2304#D-* Examples:
2305#D-
2306function IGCM_sys_ncra {
2307  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2308  if ( $DEBUG_sys ) ; then
2309    echo "IGCM_sys_ncra :" $@
2310  fi
2311
2312  typeset NB_ESSAI DELAI status i
2313  # number of tentative
2314  NB_ESSAI=3
2315  # time delay between tentative
2316  DELAI=2
2317
2318  i=0
2319  while [ $i -lt $NB_ESSAI ] ; do
2320    ncra $@ > /tmp/out_command.$$ 2>&1
2321    status=$?
2322    if [ ${status} -gt 0 ] ; then
2323      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2324      cat /tmp/out_command.$$
2325      \rm /tmp/out_command.$$
2326      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2327      sleep $DELAI
2328    else
2329      \rm /tmp/out_command.$$
2330      break
2331    fi
2332    (( i = i + 1 ))
2333  done
2334
2335  if [ ${status} -gt 0 ] ; then
2336    echo "IGCM_sys_ncra : ncra error"
2337    IGCM_debug_Exit "ncra"
2338  fi
2339
2340  IGCM_debug_PopStack "IGCM_sys_ncra"
2341}
2342
2343#D-#==================================================
2344#D-function IGCM_sys_ncrcat
2345#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2346#D-* Examples:
2347#D-
2348function IGCM_sys_ncrcat {
2349  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2350  if ( $DEBUG_sys ) ; then
2351    echo "IGCM_sys_ncrcat :" $@
2352  fi
2353
2354  typeset NB_ESSAI DELAI status i lastArg
2355  # number of tentative
2356  NB_ESSAI=3
2357  # time delay between tentative
2358  DELAI=2
2359
2360  i=0
2361  while [ $i -lt $NB_ESSAI ] ; do
2362    ncrcat $@ > /tmp/out_command.$$ 2>&1
2363    status=$?
2364    if [ ${status} -gt 0 ] ; then
2365      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2366      cat /tmp/out_command.$$
2367      \rm /tmp/out_command.$$
2368      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2369      sleep $DELAI
2370    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command.$$ )" = "X" ] ; then
2371      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2372      cat /tmp/out_command.$$
2373      # remove files having corrupted time axis
2374      eval lastArg=\${$#}
2375      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2376      \rm ${lastArg}
2377      \rm /tmp/out_command.$$
2378      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2379      sleep $DELAI
2380    else
2381      \rm /tmp/out_command.$$
2382      break
2383    fi
2384    (( i = i + 1 ))
2385  done
2386
2387  if [ ${status} -gt 0 ] ; then
2388    echo "IGCM_sys_ncrcat : ncrcat error"
2389    #IGCM_debug_Exit "ncrcat"
2390  fi
2391
2392  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2393}
2394
2395#D-#==================================================
2396#D-function IGCM_sys_ncrename
2397#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2398#D-* Examples:
2399#D-
2400function IGCM_sys_ncrename {
2401  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2402  if ( $DEBUG_sys ) ; then
2403    echo "IGCM_sys_ncrename :" $@
2404  fi
2405
2406  typeset NB_ESSAI DELAI status i
2407  # number of tentative
2408  NB_ESSAI=3
2409  # time delay between tentative
2410  DELAI=2
2411
2412  i=0
2413  while [ $i -lt $NB_ESSAI ] ; do
2414    ncrename $@ > /tmp/out_command.$$ 2>&1
2415    status=$?
2416    if [ ${status} -gt 0 ] ; then
2417      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2418      cat /tmp/out_command.$$
2419      \rm /tmp/out_command.$$
2420      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2421      sleep $DELAI
2422    else
2423      \rm /tmp/out_command.$$
2424      break
2425    fi
2426    (( i = i + 1 ))
2427  done
2428
2429  if [ ${status} -gt 0 ] ; then
2430    echo "IGCM_sys_ncrename : ncrename error"
2431    IGCM_debug_Exit "ncrename"
2432  fi
2433
2434  IGCM_debug_PopStack "IGCM_sys_ncrename"
2435}
2436
2437#D-#==================================================
2438#D-function IGCM_sys_ncwa
2439#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2440#D-* Examples:
2441#D-
2442function IGCM_sys_ncwa {
2443  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2444  if ( $DEBUG_sys ) ; then
2445    echo "IGCM_sys_ncwa :" $@
2446  fi
2447
2448  typeset NB_ESSAI DELAI status i
2449  # number of tentative
2450  NB_ESSAI=3
2451  # time delay between tentative
2452  DELAI=2
2453
2454  i=0
2455  while [ $i -lt $NB_ESSAI ] ; do
2456    ncwa $@ > /tmp/out_command.$$ 2>&1
2457    status=$?
2458    if [ ${status} -gt 0 ] ; then
2459      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2460      cat /tmp/out_command.$$
2461      \rm /tmp/out_command.$$
2462      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2463      sleep $DELAI
2464    else
2465      \rm /tmp/out_command.$$
2466      break
2467    fi
2468    (( i = i + 1 ))
2469  done
2470
2471  if [ ${status} -gt 0 ] ; then
2472    echo "IGCM_sys_ncwa : ncwa error"
2473    IGCM_debug_Exit "ncwa"
2474  fi
2475
2476  IGCM_debug_PopStack "IGCM_sys_ncwa"
2477}
2478
2479##############################################################
2480# CDO OPERATOR
2481
2482#D-#==================================================
2483#D-function IGCM_sys_cdo
2484#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2485#D-* Examples:
2486#D-
2487function IGCM_sys_cdo {
2488  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2489  if ( $DEBUG_sys ) ; then
2490    echo "IGCM_sys_cdo :" $@
2491  fi
2492
2493  typeset status
2494
2495  \cdo $@ > /tmp/out_command.$$ 2>&1
2496  status=$?
2497  if [ ${status} -gt 0 ] ; then
2498    echo "IGCM_sys_cdo : error code ${status}"
2499    cat /tmp/out_command.$$
2500    \rm /tmp/out_command.$$
2501    IGCM_debug_PopStack "IGCM_sys_cdo"
2502    return 1
2503  else
2504    IGCM_debug_PopStack "IGCM_sys_cdo"
2505    return 0
2506  fi
2507
2508  IGCM_debug_PopStack "IGCM_sys_cdo"
2509}
Note: See TracBrowser for help on using the repository browser.