source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh @ 964

Last change on this file since 964 was 964, checked in by jgipsl, 11 years ago

At obelix, the sceduler does the cleaning.

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