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

Last change on this file since 958 was 949, checked in by sdipsl, 11 years ago

obelix case. see #125

  • Property svn:keywords set to Revision Author Date
File size: 71.4 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  fi
824
825  typeset status
826
827  echo rm $@ > /tmp/out_command.$$ 2>&1
828  \rm $@ >> /tmp/out_command.$$ 2>&1
829  status=$?
830
831  if [ ${status} -gt 0 ] ; then
832    echo "IGCM_sys_RmRunDir : rm error code is ${status}."
833    cat /tmp/out_command.$$
834    IGCM_debug_Exit "IGCM_sys_RmRunDir"
835  else
836    \rm /tmp/out_command.$$
837  fi
838  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
839}
840
841#D-#==================================================
842#D-function IGCM_sys_Mv
843#D-* Purpose: generic move
844#D-* Examples:
845#D-
846function IGCM_sys_Mv {
847  IGCM_debug_PushStack "IGCM_sys_Mv" $@
848  if ( $DEBUG_sys ) ; then
849    echo "IGCM_sys_Mv :" $@
850  fi
851
852  if [ $DRYRUN = 0 ]; then
853
854    typeset status
855
856    echo mv $@ > /tmp/out_command.$$ 2>&1
857    \mv $@ >> /tmp/out_command.$$ 2>&1
858    status=$?
859
860    if [ ${status} -gt 0 ] ; then
861      echo "IGCM_sys_Mv : error code ${status}"
862      cat /tmp/out_command.$$
863      IGCM_debug_Exit "IGCM_sys_Mv"
864    else
865      \rm /tmp/out_command.$$
866    fi
867  fi
868  IGCM_debug_PopStack "IGCM_sys_Mv"
869}
870
871#D-#==================================================
872#D-function IGCM_sys_Put_Dir
873#D-* Purpose: Copy a complete directory on $(ARCHIVE)
874#D-* Examples:
875#D-
876function IGCM_sys_Put_Dir {
877  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
878  if ( $DEBUG_sys ) ; then
879    echo "IGCM_sys_Put_Dir :" $@
880  fi
881  if [ $DRYRUN = 0 ]; then
882    if [ ! -d ${1} ] ; then
883      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
884      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
885      return
886    fi
887
888    typeset status
889
890    # Only if we use rsync
891    #IGCM_sys_TestDirArchive $( dirname $2 )
892    #
893    #USUAL WAY
894    \cp -r $1 $2 > /tmp/out_command.$$ 2>&1
895    status=$?
896
897    if [ ${status} -gt 0 ] ; then
898      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
899      cat /tmp/out_command.$$
900      IGCM_debug_Exit "IGCM_sys_Put_Dir"
901    else
902      \rm /tmp/out_command.$$
903    fi
904  fi
905  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
906}
907
908#D-#==================================================
909#D-function IGCM_sys_Get_Dir
910#D-* Purpose: Copy a complete directory from ${ARCHIVE}
911#D-* Examples:
912#D-
913function IGCM_sys_Get_Dir {
914  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
915  if ( $DEBUG_sys ) ; then
916    echo "IGCM_sys_Get_Dir :" $@
917  fi
918  if [ $DRYRUN = 0 ]; then
919    if [ ! -d ${1} ] ; then
920      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
921      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
922      return
923    fi
924
925    typeset status
926
927    #USUAL WAY
928    \cp -ur $1 $2 > /tmp/out_command.$$ 2>&1
929    status=$?
930
931    if [ ${status} -gt 0 ] ; then
932      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
933      cat /tmp/out_command.$$
934      IGCM_debug_Exit "IGCM_sys_Get_Dir"
935    else
936      \rm /tmp/out_command.$$
937    fi
938  fi
939  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
940}
941
942#D-#==================================================
943#D-function IGCM_sys_Get_Master
944#D-* Purpose: Copy a complete directory from MASTER filesystem
945#D-* Examples:
946#D-
947function IGCM_sys_Get_Master {
948  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
949  if ( $DEBUG_sys ) ; then
950    echo "IGCM_sys_Get_Master :" $@
951  fi
952  if [ $DRYRUN = 0 ]; then
953    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
954      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
955      IGCM_debug_PopStack "IGCM_sys_Get_Master"
956      return
957    fi
958
959    typeset NB_ESSAI DELAI status i
960    # number of tentative
961    NB_ESSAI=3
962    # time delay between tentative
963    DELAI=2
964
965    i=0
966    while [ $i -lt $NB_ESSAI ] ; do
967      \cp -urL $1 $2 > /tmp/out_command.$$ 2>&1
968      status=$?
969      if [ ${status} -gt 0 ]; then
970        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
971        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
972        sleep $DELAI
973      else
974        break
975      fi
976      (( i = i + 1 ))
977    done
978
979    if [ ${status} -gt 0 ] ; then
980      echo "IGCM_sys_Get_Master : error."
981      cat /tmp/out_command.$$
982      IGCM_debug_Exit "IGCM_sys_Get_Master"
983    else
984      \rm /tmp/out_command.$$
985    fi
986  fi
987  IGCM_debug_PopStack "IGCM_sys_Get_Master"
988}
989
990#====================================================
991#- Call IGCM_sys_Mirror_libIGCM now !
992if ( $MirrorlibIGCM ) ; then
993  IGCM_sys_Mirror_libIGCM
994fi
995
996#D-#==================================================
997#D-function IGCM_sys_Put_Rest
998#D-* Purpose: Put computied restarts on ${ARCHIVE}.
999#D-           File and target directory must exist.
1000#D-* Examples:
1001#D-
1002function IGCM_sys_Put_Rest {
1003  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1004  if ( $DEBUG_sys ) ; then
1005    echo "IGCM_sys_Put_Rest :" $@
1006  fi
1007  if [ $DRYRUN = 0 ]; then
1008    if [ ! -f ${1} ] ; then
1009      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1010      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1011    fi
1012
1013    typeset status
1014    #
1015    if [ X${JobType} = XRUN ] ; then
1016      IGCM_sys_Chmod 444 ${1}
1017    fi
1018    #
1019    # Only if we use rsync
1020    #IGCM_sys_MkdirArchive $( dirname $2 )
1021    #
1022    #USUAL WAY
1023    \cp $1 $2 > /tmp/out_command.$$ 2>&1
1024    status=$?
1025
1026#       #RSYNC WITH NETWORK SSH CALL
1027#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > /tmp/out_command.$$ 2>&1
1028#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> /tmp/out_command.$$ 2>&1
1029
1030#       #RSYNC WITH NFS USE
1031#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > /tmp/out_command.$$ 2>&1
1032#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> /tmp/out_command.$$ 2>&1
1033
1034#       status=$?
1035#       IGCM_sys_Rsync_out $status
1036
1037#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command.$$
1038#       (( status=status+$? ))
1039
1040    if [ ${status} -gt 0 ] ; then
1041      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
1042      cat /tmp/out_command.$$
1043      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1044    else
1045      \rm /tmp/out_command.$$
1046    fi
1047  fi
1048  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1049}
1050
1051#D-#==================================================
1052#D-function IGCM_sys_PutBuffer_Rest
1053#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1054#D-           File and target directory must exist.
1055#D-* Examples:
1056#D-
1057function IGCM_sys_PutBuffer_Rest {
1058  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1059  if ( $DEBUG_sys ) ; then
1060    echo "IGCM_sys_PutBuffer_Rest :" $@
1061  fi
1062  if [ $DRYRUN = 0 ]; then
1063    if [ ! -f ${1} ] ; then
1064      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1065      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1066    fi
1067
1068    typeset status
1069    #
1070    if [ X${JobType} = XRUN ] ; then
1071      IGCM_sys_Chmod 444 ${1}
1072    fi
1073
1074    #
1075    # USUAL WAY
1076    \cp $1 $2 > /tmp/out_command.$$ 2>&1
1077    status=$?
1078
1079    if [ ${status} -gt 0 ] ; then
1080      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1081      [ -f ${2} ] && ls -l ${2}
1082      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1083      cat /tmp/out_command.$$
1084      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1085    else
1086      \rm /tmp/out_command.$$
1087    fi
1088  fi
1089  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1090}
1091
1092#D-#==================================================
1093#D-function IGCM_sys_PrepareTaredRestart
1094#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1095#D-* Examples:
1096#D-
1097function IGCM_sys_PrepareTaredRestart {
1098  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1099
1100  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1101}
1102
1103#D-#==================================================
1104#D-function IGCM_sys_Put_Out
1105#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1106#D-* Examples:
1107#D-
1108function IGCM_sys_Put_Out {
1109  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1110  if ( $DEBUG_sys ) ; then
1111    echo "IGCM_sys_Put_Out :" $@
1112  fi
1113
1114  typeset status
1115
1116  if [ $DRYRUN = 0 ]; then
1117    if [ ! -f ${1} ] ; then
1118      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1119      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1120      return 1
1121    fi
1122    #
1123    IGCM_sys_MkdirArchive $( dirname $2 )
1124    #
1125    if [ X${JobType} = XRUN ] ; then
1126      if [ X${3} = X ] ; then
1127        IGCM_sys_Chmod 444 ${1}
1128      fi
1129    fi
1130    #
1131
1132    echo ${RSYNC} ${RSYNC_opt} $1 $2 > /tmp/out_command.$$ 2>&1
1133    ${RSYNC} ${RSYNC_opt} $1 $2 >> /tmp/out_command.$$ 2>&1
1134    status=$?
1135    IGCM_sys_Rsync_out $status
1136
1137    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command.$$
1138    (( status=status+$? ))
1139
1140    if [ ${status} -gt 0 ] ; then
1141      IGCM_debug_Print 2 "IGCM_sys_Put_Out : rsync failed error code ${status}"
1142      cat /tmp/out_command.$$
1143      IGCM_debug_Exit "IGCM_sys_Put_Out"
1144    else
1145      \rm /tmp/out_command.$$
1146    fi
1147  fi
1148  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1149  return 0
1150}
1151
1152#D-#==================================================
1153#D-function IGCM_sys_PutBuffer_Out
1154#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1155#D-* Examples:
1156#D-
1157function IGCM_sys_PutBuffer_Out {
1158  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1159  if ( $DEBUG_sys ) ; then
1160    echo "IGCM_sys_PutBuffer_Out :" $@
1161  fi
1162
1163  typeset NB_ESSAI DELAI status i exist skip
1164
1165  # number of tentative
1166  NB_ESSAI=3
1167  # time delay between tentative
1168  DELAI=2
1169
1170  if [ $DRYRUN = 0 ]; then
1171    if [ ! -f ${1} ] ; then
1172      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1173      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1174      return 1
1175    fi
1176    #
1177    IGCM_sys_Mkdir $( dirname $2 )
1178    #
1179
1180    exist=false
1181    skip=false
1182    if [ -f $2 ] ; then
1183      IGCM_debug_Print 1 "$2 already exist"
1184      exist=true
1185      if [ "X$( diff $1 $2 )" = X ] ; then
1186        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1187        status=0
1188        skip=true
1189      else
1190        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1191        skip=false
1192      fi
1193    fi
1194    #
1195    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1196      IGCM_sys_Chmod u+w $2
1197    fi
1198
1199    if [ X${skip} = Xfalse ] ; then
1200      i=0
1201      while [ $i -lt $NB_ESSAI ] ; do
1202        # USUAL WAY
1203        \cp $1 $2 > /tmp/out_command.$$ 2>&1
1204        status=$?
1205        if [ ${status} -gt 0 ]; then
1206          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1207          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1208          [ -f ${2} ] && ls -l ${2}
1209          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1210          sleep $DELAI
1211        else
1212          break
1213        fi
1214        (( i = i + 1 ))
1215      done
1216    fi
1217
1218    if [ ${status} -gt 0 ] ; then
1219      echo "IGCM_sys_PutBuffer_Out : error."
1220      [ -f ${2} ] && ls -l ${2}
1221      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1222      cat /tmp/out_command.$$
1223      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1224    else
1225
1226      if [ X${JobType} = XRUN ] ; then
1227        if [ X${3} = X ] ; then
1228          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1229          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1230        fi
1231      fi
1232
1233      \rm /tmp/out_command.$$
1234    fi
1235  fi
1236  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1237  return 0
1238}
1239
1240#D-#==================================================
1241#D-function IGCM_sys_Get
1242#D-* Purpose: Get a file from ${ARCHIVE}
1243#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1244#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1245function IGCM_sys_Get {
1246  IGCM_debug_PushStack "IGCM_sys_Get" $@
1247
1248  typeset DEST status dm_liste
1249
1250  if ( $DEBUG_sys ) ; then
1251    echo "IGCM_sys_Get :" $@
1252  fi
1253  if [ $DRYRUN -le 2 ]; then
1254    if [ X${1} = X'/l' ] ; then
1255      eval set +A dm_liste \${${2}}
1256    else
1257      dm_liste=${1}
1258    fi
1259    eval DEST=\${${#}}
1260
1261    # test if the (first) file is present in the old computation :
1262    IGCM_sys_TestFileArchive ${dm_liste[0]}
1263    status=$?
1264    if [ ${status} -gt 0 ] ; then
1265      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1266      IGCM_debug_Exit "IGCM_sys_Get"
1267      return
1268    fi
1269
1270    #USUAL WAY
1271    \cp ${dm_liste[*]} ${DEST} > /tmp/out_command.$$ 2>&1
1272    status=$?
1273
1274    if [ ${status} -gt 0 ] ; then
1275      IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}"
1276      cat /tmp/out_command.$$
1277      IGCM_debug_Exit "IGCM_sys_Get"
1278    else
1279      \rm /tmp/out_command.$$
1280    fi
1281  fi
1282  IGCM_debug_PopStack "IGCM_sys_Get"
1283}
1284
1285#D-#==================================================
1286#D-function IGCM_sys_GetBuffer
1287#D-* Purpose: Get a file from ${SCRATCHDIR}
1288#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1289#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1290function IGCM_sys_GetBuffer {
1291  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1292
1293  typeset DEST buf_liste target file_work
1294  typeset NB_ESSAI DELAI status i
1295
1296  if ( $DEBUG_sys ) ; then
1297    echo "IGCM_sys_GetBuffer :" $@
1298  fi
1299
1300  # number of tentative
1301  NB_ESSAI=3
1302  # time delay between tentative
1303  DELAI=2
1304
1305  if [ $DRYRUN -le 2 ]; then
1306    if [ X${1} = X'/l' ] ; then
1307      eval set +A buf_liste \${${2}}
1308    else
1309      eval set +A buf_liste ${1}
1310    fi
1311    eval DEST=\${${#}}
1312
1313    #USUAL WAY
1314    if [ X${1} = X'/l' ] ; then
1315      for target in ${buf_liste[*]} ; do
1316        local_file=$( basename ${target} )
1317        i=0
1318        while [ $i -lt $NB_ESSAI ] ; do
1319          \cp ${target} ${DEST}/${local_file} >> /tmp/out_command.$$ 2>&1
1320          status=$?
1321          if [ ${status} -gt 0 ]; then
1322            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1323            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1324            sleep $DELAI
1325          else
1326            break
1327          fi
1328          (( i = i + 1 ))
1329        done
1330        if [ ${status} -gt 0 ] ; then
1331          echo "IGCM_sys_Get : error"
1332          cat /tmp/out_command.$$
1333          \rm /tmp/out_command.$$
1334          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1335        else
1336          \rm /tmp/out_command.$$
1337        fi
1338      done
1339    else
1340      i=0
1341      while [ $i -lt $NB_ESSAI ] ; do
1342        \cp ${buf_liste} ${DEST} >> /tmp/out_command.$$ 2>&1
1343        status=$?
1344        if [ ${status} -gt 0 ]; then
1345          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1346          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1347          sleep $DELAI
1348        else
1349          break
1350        fi
1351        (( i = i + 1 ))
1352      done
1353      if [ ${status} -gt 0 ] ; then
1354        echo "IGCM_sys_Get : error"
1355        cat /tmp/out_command.$$
1356        \rm /tmp/out_command.$$
1357        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1358      else
1359        \rm /tmp/out_command.$$
1360      fi
1361    fi
1362  fi
1363  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1364}
1365
1366#D-#==================================================
1367#D-function IGCM_sys_GetDate_FichWork
1368#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1369#D-* Examples:
1370#D-
1371function IGCM_sys_GetDate_FichWork {
1372  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1373  if ( $DEBUG_sys ) ; then
1374    echo "IGCM_sys_GetDate_FichWork :" $@
1375  fi
1376  typeset dateF
1377  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1378  eval ${2}=${dateF[5]}
1379
1380  # donne la date filesys d'un fichier sur la machine work
1381  IGCM_debug_PopStack "IGCM_sys_FichWork"
1382}
1383
1384#D-#==================================================
1385#D-function IGCM_sys_GetDate_FichArchive
1386#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1387#D-* Examples:
1388#D-
1389function IGCM_sys_GetDate_FichArchive {
1390  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1391  if ( $DEBUG_sys ) ; then
1392    echo "IGCM_sys_GetDate_FichArchive :" $@
1393  fi
1394  typeset dateF
1395  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1396  eval ${2}=${dateF[5]}
1397
1398  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1399}
1400
1401#D-#==================================================
1402#D-function IGCM_sys_Dods_Rm
1403#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1404#D-* Examples:
1405#D-
1406function IGCM_sys_Dods_Rm {
1407  if ( $DEBUG_sys ) ; then
1408    echo "IGCM_sys_Dods_Rm :" $@
1409  fi
1410  return 0
1411}
1412
1413#D-#==================================================
1414#D-function IGCM_sys_Dods_Cp
1415#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1416#D-* Examples:
1417#D-
1418function IGCM_sys_Dods_Cp {
1419  if ( $DEBUG_sys ) ; then
1420    echo "IGCM_sys_Dods_Cp :" $@
1421  fi
1422  return 0
1423}
1424
1425#D-#==================================================
1426#D-function IGCM_sys_Put_Dods
1427#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here
1428#D-* Examples:
1429#D-
1430function IGCM_sys_Put_Dods {
1431  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1432  if ( $DEBUG_sys ) ; then
1433    echo "IGCM_sys_Put_Dods :" $@
1434  fi
1435  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1436}
1437
1438##############################################################
1439# REBUILD OPERATOR
1440
1441#D-#==================================================
1442#D-function IGCM_sys_rebuild
1443#D-* Purpose: rebuild parallel files
1444#D-* Examples:
1445#D-
1446function IGCM_sys_rebuild {
1447  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1448  if ( $DEBUG_sys ) ; then
1449    echo "IGCM_sys_rebuild :" $@
1450  fi
1451
1452  typeset NB_ESSAI DELAI status i firstArg
1453  # number of tentative
1454  NB_ESSAI=3
1455  # time delay between tentative
1456  DELAI=2
1457
1458  i=0
1459  while [ $i -lt $NB_ESSAI ] ; do
1460    /home/users/igcmg/rebuild/bin/rebuild -f -o $@ > /tmp/out_command.$$ 2>&1
1461    status=$?
1462    if [ ${status} -gt 0 ] ; then
1463      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1464      cat /tmp/out_command.$$
1465      \rm /tmp/out_command.$$
1466      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1467      firstArg=${1}
1468      \rm ${firstArg}
1469      sleep $DELAI
1470    else
1471      \rm /tmp/out_command.$$
1472      break
1473    fi
1474    (( i = i + 1 ))
1475  done
1476
1477  if [ ${status} -gt 0 ] ; then
1478    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1479    IGCM_debug_Exit "rebuild"
1480  fi
1481
1482  IGCM_debug_PopStack "IGCM_sys_rebuild"
1483}
1484
1485#D-#==================================================
1486#D-function IGCM_sys_rebuild_station
1487#D-* Purpose: rebuild parallel files describing station
1488#D-* Examples:
1489#D-
1490function IGCM_sys_rebuild_station {
1491  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1492  typeset i list_opt file_in file_out prefix_invert list_invert
1493  if ( $DEBUG_sys ) ; then
1494    echo "IGCM_sys_rebuild_station :" $@
1495  fi
1496  list_opt=$@
1497
1498  # Invert Axis : t,x -> x,t
1499  #               t,pres,x -> x,t,pres
1500  # So that we can concatenate along x
1501  i=0
1502  for file_in in ${list_opt} ; do
1503    (( i = i + 1))
1504    [ ${i} = 1 ] && file_out=${file_in} && continue
1505    prefix_invert=$( basename ${file_in} .nc )
1506    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1507    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1508  done
1509
1510  # Concatenate
1511  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1512
1513  # Re-ivert file
1514  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1515
1516  # Station re-ordering is too expansive to be run within libIGCM
1517  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1518  # This re-ordering must be done "in memory" by the cmorization process
1519  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1520  # BEGIN reordering
1521
1522  # Only LMDZ text output contains the exact ordering of the station.
1523  # We isolate this in the code below:
1524  #  0  38  -157.5000000000000  70.98591549295774
1525  #  0  54  27.49999999999999   67.18309859154928
1526  #  0  56  -62.50000000000001  82.39436619718309
1527  #  0  79  12.49999999999999   78.59154929577466
1528  #  0  116 -165.0000000000000  76.05633802816901
1529  #  0  117 130.0000000000000   70.98591549295774
1530  #  0  118 110.0000000000000   87.46478873239437
1531  #  1  40  4.999999999999995   51.97183098591550
1532#  typeset iStation iProc list_opt file_in file_out prefix_invert
1533#  typeset -Z4 j4
1534#  typeset -Z3 j3
1535
1536#  unset list_opt
1537#  set +A list_opt $@
1538
1539  # Filename after rebuild
1540#  file_out=${list_opt[0]}
1541  # Prefix of output files
1542#  prefix_invert=$( basename ${file_out} .nc )
1543  # Number of procs
1544#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1545
1546#  iProc=0
1547#  while [ ${iProc} -lt ${num_proc} ] ; do
1548    # Array containing Station as a number
1549#    unset proc_stn
1550#    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}' )
1551    # Number of stations produced by processor proc
1552#    stationLast=${#proc_stn[*]}
1553    # Proc number on 4 digits
1554#    j4=${iProc}
1555    # Init
1556#    iStation=0
1557#    while [ ${iStation} -lt ${stationLast} ] ; do
1558      # Station number on 3 digits
1559#      j3=${proc_stn[${iStation}]}
1560      # Extract station
1561      # Invert Axis : t,x -> x,t
1562      #               t,pres,x -> x,t,pres
1563      # So that we can concatenate along x
1564#      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
1565#      (( iStation = iStation + 1 ))
1566#    done
1567#    (( iProc = iProc + 1 ))
1568#  done
1569
1570  # Concatenate all station along x
1571#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1572
1573  # Re-invert file
1574#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1575
1576  # END reordering
1577
1578  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1579}
1580
1581############################################################
1582# Activate Running Environnment Variables
1583
1584#D-#==================================================
1585#D-function IGCM_sys_desactiv_variables
1586#D-* Purpose: set environement variables prior to execution
1587#D-* Examples:
1588#D-
1589function IGCM_sys_activ_variables {
1590  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1591  if ( $DEBUG_sys ) ; then
1592    echo "IGCM_sys_activ_variables"
1593  fi
1594
1595# --------------------------------------------------------------------
1596#D- MPI specifications
1597# --------------------------------------------------------------------
1598
1599# --------------------------------------------------------------------
1600#D- Other specifications
1601# --------------------------------------------------------------------
1602
1603  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1604}
1605
1606############################################################
1607# Desactivate Running Environnment Variables
1608
1609#D-#==================================================
1610#D-function IGCM_sys_desactiv_variables
1611#D-* Purpose: unset environement variables after execution
1612#D-* Examples:
1613#D-
1614function IGCM_sys_desactiv_variables {
1615  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1616  if ( $DEBUG_sys ) ; then
1617    echo "IGCM_sys_desactiv_variables"
1618  fi
1619# --------------------------------------------------------------------
1620#D- MPI specifications
1621# --------------------------------------------------------------------
1622
1623# --------------------------------------------------------------------
1624#D- Other specifications
1625# --------------------------------------------------------------------
1626
1627  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1628}
1629
1630############################################################
1631# Build MPI/OMP scripts run file (dummy function)
1632
1633#D-#==================================================
1634#D-function IGCM_sys_build_run_file
1635#D-* Purpose: build run file (deprecated)
1636#D-* Examples:
1637#D-
1638function IGCM_sys_build_run_file {
1639
1640  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1641
1642}
1643
1644############################################################
1645# Build MPI/OMP scripts
1646
1647#D-#==================================================
1648#D-function IGCM_sys_build_execution_scripts
1649#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1650#D-* Examples:
1651#D-
1652function IGCM_sys_build_execution_scripts
1653{
1654  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1655  if ( $DEBUG_sys ) ; then
1656    echo "IGCM_sys_build_execution_scripts " $@
1657  fi
1658  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1659  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1660  typeset num_corempi nombre_restant_node nombre_restant_comp
1661
1662  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1663    IGCM_debug_Exit "IGCM_sys_obelix build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1664  fi
1665
1666  if ( ${OK_PARA_MPMD} ) ; then
1667
1668    if [ -f run_file ] ; then
1669      IGCM_sys_Rm -f run_file
1670    fi
1671    touch run_file
1672
1673    if ( ${OK_PARA_OMP} ) ; then
1674
1675      #  Hosts treatment
1676
1677      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1678
1679      i=0
1680      rm -f hosts
1681      IGCM_debug_Print 1 "sys Obelix, Hosts avaible :"
1682      for nodes in `cat hosts.tmp` ; do
1683        host[$i]=$nodes
1684        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1685        IGCM_debug_Print 1 ${host[$i]}
1686        i=$((i+1))
1687      done
1688      rm -f hosts.tmp
1689
1690      listnodes=${host[*]}
1691
1692      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1693
1694      # Initialisation
1695
1696      init_node=y
1697      node_num_current=0
1698      start_num=0
1699      init_exec=n
1700
1701      # Test : if oasis is there, we put it at the first position
1702
1703      for comp in ${config_ListOfComponents[*]} ; do
1704
1705        if [ "X${comp}" = "XCPL" ]  ; then
1706
1707          eval ExeNameIn=\${config_Executable_${comp}[0]}
1708          eval ExeNameOut=\${config_Executable_${comp}[1]}
1709
1710          echo "#!/bin/ksh" > 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 "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1716          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1717
1718          init_node=n
1719
1720          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1721          node_num_current=0
1722          node_current=${host[${node_num_current}]}
1723
1724          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1725
1726          init_exec=y
1727          start_num=1
1728
1729        fi
1730
1731      done
1732
1733      # Then loop on the components (except for oasis)
1734
1735      for comp in ${config_ListOfComponents[*]} ; do
1736
1737        eval ExeNameIn=\${config_Executable_${comp}[0]}
1738        eval ExeNameOut=\${config_Executable_${comp}[1]}
1739
1740        # Only if we really have an executable for the component :
1741        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1742
1743          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1744          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1745
1746          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1747          # echo "set -vx" >> script_${ExeNameOut}.ksh
1748          echo ""  >> script_${ExeNameOut}.ksh
1749          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1750          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1751          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1752          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1753          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1754          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1755          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1756
1757          node_num=0
1758
1759          # We define the number of MPI process to be assigned for the component
1760
1761          nombre_restant_comp=${comp_proc_mpi_loc}
1762
1763          # Loop on the allocated nodes
1764
1765          for node in ${listnodes} ; do
1766
1767            # We go to the current node
1768            if [ ${node_num} = ${node_num_current} ] ; then
1769
1770              node_current=${host[${node_num_current}]}
1771
1772              # If first time on the node : initialisation
1773
1774              if [ ${init_node} = y ] ; then
1775                nombre_restant_node=${NUM_COREPERNODE}
1776              fi
1777
1778              # Test on the number of OMP threads
1779
1780              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1781                (( node_num = node_num + 1 ))
1782                node_num_current=${node_num}
1783                init_node=y
1784                continue
1785              fi
1786
1787              # Number of MPI process to assign
1788
1789              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1790
1791              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1792                num_corempi=${nombre_restant_comp}
1793              fi
1794
1795              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1796              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1797
1798              if [ ${init_exec} = y ] ; then
1799                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1800              else
1801                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1802                init_exec=y
1803              fi
1804
1805              ((  start_num = num_corempi + start_num ))
1806
1807            else
1808
1809              (( node_num = node_num + 1 ))
1810              continue
1811            fi
1812
1813            # Test on the number of core/process remaining on the node/component
1814
1815            if [ ${nombre_restant_node} = 0 ] ; then
1816              (( node_num = node_num + 1 ))
1817              node_num_current=${node_num}
1818              init_node=y
1819
1820              if [ ${nombre_restant_comp} = 0 ] ; then
1821                break 1
1822              fi
1823            else
1824
1825              node_num_current=${node_num}
1826              init_node=n
1827
1828              if [ ${nombre_restant_comp} = 0 ] ; then
1829                break 1
1830              fi
1831            fi
1832          done
1833        fi
1834      done
1835
1836    else
1837
1838      # Then first loop on the components for the coupler ie oasis
1839
1840      ## the coupler ie oasis must be the first one
1841      for comp in ${config_ListOfComponents[*]} ; do
1842
1843        eval ExeNameOut=\${config_Executable_${comp}[1]}
1844
1845        # for CPL component only
1846        if [ "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
1852      # Then second loop on the components
1853
1854      for comp in ${config_ListOfComponents[*]} ; do
1855
1856        eval ExeNameOut=\${config_Executable_${comp}[1]}
1857
1858        # Only if we really have an executable for the component and not the coupler ie oasis:
1859        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1860          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1861          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1862        fi
1863      done
1864      IGCM_sys_Chmod u+x run_file
1865
1866      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1867
1868    fi
1869
1870  else # Only one executable. launch it.
1871
1872    for comp in ${config_ListOfComponents[*]} ; do
1873
1874      # Only if we really have an executable for the component :
1875      eval ExeNameOut=\${config_Executable_${comp}[1]}
1876      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1877
1878        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1879        echo ""  >> script_${ExeNameOut}.ksh
1880        if ( ${OK_PARA_OMP} ) ; then
1881          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1882          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1883        fi
1884        if  ( ${OK_PARA_MPI} ) ; then
1885          # Default : mpirun used if nb_proc gt 1
1886          # pour sortie out/err par process
1887          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1888          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1889          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1890          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1891        else
1892          # Default : mpirun is NOT used if nb_proc eq 1
1893          # pour sortie out/err par process
1894          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1895          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1896          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1897          EXECUTION="time ./script_${ExeNameOut}.ksh"
1898        fi
1899      fi
1900    done
1901
1902  fi
1903
1904  IGCM_debug_Print 1 "sys Obelix : execution command is"
1905  IGCM_debug_Print 1 "$EXECUTION"
1906
1907  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1908}
1909
1910#D-#==================================================
1911#D-function IGCM_sys_check_path
1912#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1913#D-* do not point to an important use directory. Stop immediately in that case.
1914#D-* Examples:
1915#D-
1916function IGCM_sys_check_path {
1917  IGCM_debug_PushStack "IGCM_sys_check_path"
1918  if ( $DEBUG_sys ) ; then
1919    echo "IGCM_sys_check_path"
1920  fi
1921
1922  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
1923    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1924    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1925    IGCM_debug_Exit "This will stop the job"
1926  fi
1927  IGCM_debug_PopStack "IGCM_sys_check_path"
1928}
1929
1930#D-#==================================================
1931#D-function IGCM_sys_check_quota. Dummy call here
1932#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1933#D-* Examples:
1934#D-
1935function IGCM_sys_check_quota {
1936  IGCM_debug_PushStack "IGCM_sys_check_quota"
1937  if ( $DEBUG_sys ) ; then
1938    echo "IGCM_sys_check_quota"
1939  fi
1940  IGCM_debug_PopStack "IGCM_sys_check_quota"
1941}
1942
1943#D-#==================================================
1944#D-function IGCM_sys_CountJobInQueue
1945#D-* Purpose: Check if job_name is currently
1946#D-  running or in queue
1947#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1948#D-
1949function IGCM_sys_CountJobInQueue {
1950  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1951  if ( $DEBUG_sys ) ; then
1952    echo "IGCM_sys_CountJobInQueue"
1953  fi
1954  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1955}
1956
1957##############################################################
1958# NCO OPERATOR
1959
1960#D-#==================================================
1961#D-function IGCM_sys_ncap2
1962#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1963#D-* Examples:
1964#D-
1965function IGCM_sys_ncap2 {
1966  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1967  if ( $DEBUG_sys ) ; then
1968    echo "IGCM_sys_ncap2 :" $@
1969  fi
1970
1971  typeset NB_ESSAI DELAI status i
1972  # number of tentative
1973  NB_ESSAI=3
1974  # time delay between tentative
1975  DELAI=2
1976
1977  i=0
1978  while [ $i -lt $NB_ESSAI ] ; do
1979    ncap2 "$@" > /tmp/out_command.$$ 2>&1
1980    status=$?
1981    if [ ${status} -gt 0 ] ; then
1982      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1983      cat /tmp/out_command.$$
1984      \rm /tmp/out_command.$$
1985      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1986      sleep $DELAI
1987    else
1988      \rm /tmp/out_command.$$
1989      break
1990    fi
1991    (( i = i + 1 ))
1992  done
1993
1994  if [ ${status} -gt 0 ] ; then
1995    echo "IGCM_sys_ncap2 : ncap2 error"
1996    IGCM_debug_Exit "ncap2"
1997  fi
1998
1999  IGCM_debug_PopStack "IGCM_sys_ncap2"
2000}
2001
2002#D-#==================================================
2003#D-function IGCM_sys_ncatted
2004#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2005#D-* Examples:
2006#D-
2007function IGCM_sys_ncatted {
2008  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2009  if ( $DEBUG_sys ) ; then
2010    echo "IGCM_sys_ncatted :" $@
2011  fi
2012
2013  typeset NB_ESSAI DELAI status i
2014  # number of tentative
2015  NB_ESSAI=3
2016  # time delay between tentative
2017  DELAI=2
2018
2019  i=0
2020  while [ $i -lt $NB_ESSAI ] ; do
2021    ncatted "$@" > /tmp/out_command.$$ 2>&1
2022    status=$?
2023    if [ ${status} -gt 0 ] ; then
2024      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2025      cat /tmp/out_command.$$
2026      \rm /tmp/out_command.$$
2027      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2028      sleep $DELAI
2029    else
2030      \rm /tmp/out_command.$$
2031      break
2032    fi
2033    (( i = i + 1 ))
2034  done
2035
2036  if [ ${status} -gt 0 ] ; then
2037    echo "IGCM_sys_ncatted : ncatted error"
2038    IGCM_debug_Exit "ncatted"
2039  fi
2040
2041  IGCM_debug_PopStack "IGCM_sys_ncatted"
2042}
2043
2044#D-#==================================================
2045#D-function IGCM_sys_ncbo
2046#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2047#D-* Examples:
2048#D-
2049function IGCM_sys_ncbo {
2050  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2051  if ( $DEBUG_sys ) ; then
2052    echo "IGCM_sys_ncbo :" $@
2053  fi
2054
2055  typeset NB_ESSAI DELAI status i
2056  # number of tentative
2057  NB_ESSAI=3
2058  # time delay between tentative
2059  DELAI=2
2060
2061  i=0
2062  while [ $i -lt $NB_ESSAI ] ; do
2063    ncbo $@ > /tmp/out_command.$$ 2>&1
2064    status=$?
2065    if [ ${status} -gt 0 ] ; then
2066      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2067      cat /tmp/out_command.$$
2068      \rm /tmp/out_command.$$
2069      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2070      sleep $DELAI
2071    else
2072      \rm /tmp/out_command.$$
2073      break
2074    fi
2075    (( i = i + 1 ))
2076  done
2077
2078  if [ ${status} -gt 0 ] ; then
2079    echo "IGCM_sys_ncbo : ncbo error"
2080    IGCM_debug_Exit "ncbo"
2081  fi
2082
2083  IGCM_debug_PopStack "IGCM_sys_ncbo"
2084}
2085
2086#D-#==================================================
2087#D-function IGCM_sys_ncdif
2088#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2089#D-* Examples:
2090#D-
2091function IGCM_sys_ncdiff {
2092  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2093  if ( $DEBUG_sys ) ; then
2094    echo "IGCM_sys_ncdiff :" $@
2095  fi
2096
2097  typeset NB_ESSAI DELAI status i
2098  # number of tentative
2099  NB_ESSAI=3
2100  # time delay between tentative
2101  DELAI=2
2102
2103  i=0
2104  while [ $i -lt $NB_ESSAI ] ; do
2105    ncdiff $@ > /tmp/out_command.$$ 2>&1
2106    status=$?
2107    if [ ${status} -gt 0 ] ; then
2108      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2109      cat /tmp/out_command.$$
2110      \rm /tmp/out_command.$$
2111      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2112      sleep $DELAI
2113    else
2114      \rm /tmp/out_command.$$
2115      break
2116    fi
2117    (( i = i + 1 ))
2118  done
2119
2120  if [ ${status} -gt 0 ] ; then
2121    echo "IGCM_sys_ncdiff : ncdiff error"
2122    IGCM_debug_Exit "ncdiff"
2123  fi
2124
2125  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2126}
2127
2128#D-#==================================================
2129#D-function IGCM_sys_ncea
2130#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2131#D-* Examples:
2132#D-
2133function IGCM_sys_ncea {
2134  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2135  if ( $DEBUG_sys ) ; then
2136    echo "IGCM_sys_ncea :" $@
2137  fi
2138
2139  typeset NB_ESSAI DELAI status i
2140  # number of tentative
2141  NB_ESSAI=3
2142  # time delay between tentative
2143  DELAI=2
2144
2145  i=0
2146  while [ $i -lt $NB_ESSAI ] ; do
2147    ncea $@ > /tmp/out_command.$$ 2>&1
2148    status=$?
2149    if [ ${status} -gt 0 ] ; then
2150      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2151      cat /tmp/out_command.$$
2152      \rm /tmp/out_command.$$
2153      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2154      sleep $DELAI
2155    else
2156      \rm /tmp/out_command.$$
2157      break
2158    fi
2159    (( i = i + 1 ))
2160  done
2161
2162  if [ ${status} -gt 0 ] ; then
2163    echo "IGCM_sys_ncea : ncea error"
2164    IGCM_debug_Exit "ncea"
2165  fi
2166
2167  IGCM_debug_PopStack "IGCM_sys_ncea"
2168}
2169
2170#D-#==================================================
2171#D-function IGCM_sys_ncecat
2172#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2173#D-* Examples:
2174#D-
2175function IGCM_sys_ncecat {
2176  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2177  if ( $DEBUG_sys ) ; then
2178    echo "IGCM_sys_ncecat :" $@
2179  fi
2180
2181  typeset NB_ESSAI DELAI status i
2182  # number of tentative
2183  NB_ESSAI=3
2184  # time delay between tentative
2185  DELAI=2
2186
2187  i=0
2188  while [ $i -lt $NB_ESSAI ] ; do
2189    ncecat $@ > /tmp/out_command.$$ 2>&1
2190    status=$?
2191    if [ ${status} -gt 0 ] ; then
2192      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2193      cat /tmp/out_command.$$
2194      \rm /tmp/out_command.$$
2195      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2196      sleep $DELAI
2197    else
2198      \rm /tmp/out_command.$$
2199      break
2200    fi
2201    (( i = i + 1 ))
2202  done
2203
2204  if [ ${status} -gt 0 ] ; then
2205    echo "IGCM_sys_ncecat : ncecat error"
2206    IGCM_debug_Exit "ncecat"
2207  fi
2208
2209  IGCM_debug_PopStack "IGCM_sys_ncecat"
2210}
2211
2212#D-#==================================================
2213#D-function IGCM_sys_ncflint
2214#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2215#D-* Examples:
2216#D-
2217function IGCM_sys_ncflint {
2218  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2219  if ( $DEBUG_sys ) ; then
2220    echo "IGCM_sys_ncflint :" $@
2221  fi
2222
2223  typeset NB_ESSAI DELAI status i
2224  # number of tentative
2225  NB_ESSAI=3
2226  # time delay between tentative
2227  DELAI=2
2228
2229  i=0
2230  while [ $i -lt $NB_ESSAI ] ; do
2231    ncflint $@ > /tmp/out_command.$$ 2>&1
2232    status=$?
2233    if [ ${status} -gt 0 ] ; then
2234      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2235      cat /tmp/out_command.$$
2236      \rm /tmp/out_command.$$
2237      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2238      sleep $DELAI
2239    else
2240      \rm /tmp/out_command.$$
2241      break
2242    fi
2243    (( i = i + 1 ))
2244  done
2245
2246  if [ ${status} -gt 0 ] ; then
2247    echo "IGCM_sys_ncflint : ncflint error"
2248    IGCM_debug_Exit "ncflint"
2249  fi
2250
2251  IGCM_debug_PopStack "IGCM_sys_ncflint"
2252}
2253
2254#D-#==================================================
2255#D-function IGCM_sys_ncks
2256#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2257#D-* Examples:
2258#D-
2259function IGCM_sys_ncks {
2260  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2261  if ( $DEBUG_sys ) ; then
2262    echo "IGCM_sys_ncks :" $@
2263  fi
2264
2265  typeset NB_ESSAI DELAI status i
2266  # number of tentative
2267  NB_ESSAI=3
2268  # time delay between tentative
2269  DELAI=2
2270
2271  i=0
2272  while [ $i -lt $NB_ESSAI ] ; do
2273    ncks $@ > /tmp/out_command.$$ 2>&1
2274    status=$?
2275    if [ ${status} -gt 0 ] ; then
2276      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2277      cat /tmp/out_command.$$
2278      \rm /tmp/out_command.$$
2279      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2280      sleep $DELAI
2281    else
2282      \rm /tmp/out_command.$$
2283      break
2284    fi
2285    (( i = i + 1 ))
2286  done
2287
2288  if [ ${status} -gt 0 ] ; then
2289    echo "IGCM_sys_ncks : ncks error"
2290    IGCM_debug_Exit "ncks"
2291  fi
2292
2293  IGCM_debug_PopStack "IGCM_sys_ncks"
2294}
2295
2296#D-#==================================================
2297#D-function IGCM_sys_ncpdq
2298#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2299#D-* Examples:
2300#D-
2301function IGCM_sys_ncpdq {
2302  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2303  if ( $DEBUG_sys ) ; then
2304    echo "IGCM_sys_ncpdq :" $@
2305  fi
2306
2307  typeset NB_ESSAI DELAI status i
2308  # number of tentative
2309  NB_ESSAI=3
2310  # time delay between tentative
2311  DELAI=2
2312
2313  i=0
2314  while [ $i -lt $NB_ESSAI ] ; do
2315    ncpdq $@ > /tmp/out_command.$$ 2>&1
2316    status=$?
2317    if [ ${status} -gt 0 ] ; then
2318      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2319      cat /tmp/out_command.$$
2320      \rm /tmp/out_command.$$
2321      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2322      sleep $DELAI
2323    else
2324      \rm /tmp/out_command.$$
2325      break
2326    fi
2327    (( i = i + 1 ))
2328  done
2329
2330  if [ ${status} -gt 0 ] ; then
2331    echo "IGCM_sys_ncpdq : ncpdq error"
2332    IGCM_debug_Exit "ncpdq"
2333  fi
2334
2335  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2336}
2337
2338#D-#==================================================
2339#D-function IGCM_sys_ncra
2340#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2341#D-* Examples:
2342#D-
2343function IGCM_sys_ncra {
2344  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2345  if ( $DEBUG_sys ) ; then
2346    echo "IGCM_sys_ncra :" $@
2347  fi
2348
2349  typeset NB_ESSAI DELAI status i
2350  # number of tentative
2351  NB_ESSAI=3
2352  # time delay between tentative
2353  DELAI=2
2354
2355  i=0
2356  while [ $i -lt $NB_ESSAI ] ; do
2357    ncra $@ > /tmp/out_command.$$ 2>&1
2358    status=$?
2359    if [ ${status} -gt 0 ] ; then
2360      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2361      cat /tmp/out_command.$$
2362      \rm /tmp/out_command.$$
2363      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2364      sleep $DELAI
2365    else
2366      \rm /tmp/out_command.$$
2367      break
2368    fi
2369    (( i = i + 1 ))
2370  done
2371
2372  if [ ${status} -gt 0 ] ; then
2373    echo "IGCM_sys_ncra : ncra error"
2374    IGCM_debug_Exit "ncra"
2375  fi
2376
2377  IGCM_debug_PopStack "IGCM_sys_ncra"
2378}
2379
2380#D-#==================================================
2381#D-function IGCM_sys_ncrcat
2382#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2383#D-* Examples:
2384#D-
2385function IGCM_sys_ncrcat {
2386  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2387  if ( $DEBUG_sys ) ; then
2388    echo "IGCM_sys_ncrcat :" $@
2389  fi
2390
2391  typeset NB_ESSAI DELAI status i lastArg
2392  # number of tentative
2393  NB_ESSAI=3
2394  # time delay between tentative
2395  DELAI=2
2396
2397  i=0
2398  while [ $i -lt $NB_ESSAI ] ; do
2399    ncrcat $@ > /tmp/out_command.$$ 2>&1
2400    status=$?
2401    if [ ${status} -gt 0 ] ; then
2402      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2403      cat /tmp/out_command.$$
2404      \rm /tmp/out_command.$$
2405      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2406      sleep $DELAI
2407    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command.$$ )" = "X" ] ; then
2408      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2409      cat /tmp/out_command.$$
2410      # remove files having corrupted time axis
2411      eval lastArg=\${$#}
2412      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2413      \rm ${lastArg}
2414      \rm /tmp/out_command.$$
2415      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2416      sleep $DELAI
2417    else
2418      \rm /tmp/out_command.$$
2419      break
2420    fi
2421    (( i = i + 1 ))
2422  done
2423
2424  if [ ${status} -gt 0 ] ; then
2425    echo "IGCM_sys_ncrcat : ncrcat error"
2426    #IGCM_debug_Exit "ncrcat"
2427  fi
2428
2429  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2430}
2431
2432#D-#==================================================
2433#D-function IGCM_sys_ncrename
2434#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2435#D-* Examples:
2436#D-
2437function IGCM_sys_ncrename {
2438  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2439  if ( $DEBUG_sys ) ; then
2440    echo "IGCM_sys_ncrename :" $@
2441  fi
2442
2443  typeset NB_ESSAI DELAI status i
2444  # number of tentative
2445  NB_ESSAI=3
2446  # time delay between tentative
2447  DELAI=2
2448
2449  i=0
2450  while [ $i -lt $NB_ESSAI ] ; do
2451    ncrename $@ > /tmp/out_command.$$ 2>&1
2452    status=$?
2453    if [ ${status} -gt 0 ] ; then
2454      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2455      cat /tmp/out_command.$$
2456      \rm /tmp/out_command.$$
2457      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2458      sleep $DELAI
2459    else
2460      \rm /tmp/out_command.$$
2461      break
2462    fi
2463    (( i = i + 1 ))
2464  done
2465
2466  if [ ${status} -gt 0 ] ; then
2467    echo "IGCM_sys_ncrename : ncrename error"
2468    IGCM_debug_Exit "ncrename"
2469  fi
2470
2471  IGCM_debug_PopStack "IGCM_sys_ncrename"
2472}
2473
2474#D-#==================================================
2475#D-function IGCM_sys_ncwa
2476#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2477#D-* Examples:
2478#D-
2479function IGCM_sys_ncwa {
2480  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2481  if ( $DEBUG_sys ) ; then
2482    echo "IGCM_sys_ncwa :" $@
2483  fi
2484
2485  typeset NB_ESSAI DELAI status i
2486  # number of tentative
2487  NB_ESSAI=3
2488  # time delay between tentative
2489  DELAI=2
2490
2491  i=0
2492  while [ $i -lt $NB_ESSAI ] ; do
2493    ncwa $@ > /tmp/out_command.$$ 2>&1
2494    status=$?
2495    if [ ${status} -gt 0 ] ; then
2496      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2497      cat /tmp/out_command.$$
2498      \rm /tmp/out_command.$$
2499      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2500      sleep $DELAI
2501    else
2502      \rm /tmp/out_command.$$
2503      break
2504    fi
2505    (( i = i + 1 ))
2506  done
2507
2508  if [ ${status} -gt 0 ] ; then
2509    echo "IGCM_sys_ncwa : ncwa error"
2510    IGCM_debug_Exit "ncwa"
2511  fi
2512
2513  IGCM_debug_PopStack "IGCM_sys_ncwa"
2514}
2515
2516##############################################################
2517# CDO OPERATOR
2518
2519#D-#==================================================
2520#D-function IGCM_sys_cdo
2521#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2522#D-* Examples:
2523#D-
2524function IGCM_sys_cdo {
2525  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2526  if ( $DEBUG_sys ) ; then
2527    echo "IGCM_sys_cdo :" $@
2528  fi
2529
2530  typeset status
2531
2532  \cdo $@ > /tmp/out_command.$$ 2>&1
2533  status=$?
2534  if [ ${status} -gt 0 ] ; then
2535    echo "IGCM_sys_cdo : error code ${status}"
2536    cat /tmp/out_command.$$
2537    \rm /tmp/out_command.$$
2538    IGCM_debug_PopStack "IGCM_sys_cdo"
2539    return 1
2540  else
2541    IGCM_debug_PopStack "IGCM_sys_cdo"
2542    return 0
2543  fi
2544
2545  IGCM_debug_PopStack "IGCM_sys_cdo"
2546}
Note: See TracBrowser for help on using the repository browser.