source: tags/libIGCM_v2.3/libIGCM_sys/libIGCM_sys_obelix.ksh

Last change on this file was 1002, checked in by jgipsl, 10 years ago

Add print of script_exec file as already done on curie.

  • Property svn:keywords set to Revision Author Date
File size: 72.3 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 SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
116else
117  typeset SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
118fi
119
120#====================================================
121#- IN
122typeset -r R_IN=${R_IN:=/home/orchideeshare/igcmg/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_${LOGIN}.$$ 2>&1
581  status=$?
582
583  cat /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ )
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_${LOGIN}.$$ 2>&1
606  status=$?
607
608  cat /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ )
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_${LOGIN}.$$ 2>&1
749  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> /tmp/out_command_${LOGIN}.$$ 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_${LOGIN}.$$
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_${LOGIN}.$$ 2>&1
773  \cp $@ >> /tmp/out_command_${LOGIN}.$$ 2>&1
774  status=$?
775
776  if [ ${status} -gt 0 ] ; then
777    echo "IGCM_sys_Cp : error code ${status}"
778    cat /tmp/out_command_${LOGIN}.$$
779    IGCM_debug_Exit "IGCM_sys_Cp"
780  else
781    \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 2>&1
800  \rm $@ >> /tmp/out_command_${LOGIN}.$$ 2>&1
801  status=$?
802
803  if [ ${status} -gt 0 ] ; then
804    echo "IGCM_sys_Rm : error code ${status}"
805    cat /tmp/out_command_${LOGIN}.$$
806    IGCM_debug_Exit "IGCM_sys_Rm"
807  else
808    \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 2>&1
844    \mv $@ >> /tmp/out_command_${LOGIN}.$$ 2>&1
845    status=$?
846
847    if [ ${status} -gt 0 ] ; then
848      echo "IGCM_sys_Mv : error code ${status}"
849      cat /tmp/out_command_${LOGIN}.$$
850      IGCM_debug_Exit "IGCM_sys_Mv"
851    else
852      \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 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_${LOGIN}.$$
887      IGCM_debug_Exit "IGCM_sys_Put_Dir"
888    else
889      \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 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_${LOGIN}.$$
921      IGCM_debug_Exit "IGCM_sys_Get_Dir"
922    else
923      \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 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_${LOGIN}.$$
969      IGCM_debug_Exit "IGCM_sys_Get_Master"
970    else
971      \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 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_${LOGIN}.$$ 2>&1
1015#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> /tmp/out_command_${LOGIN}.$$ 2>&1
1016
1017#       #RSYNC WITH NFS USE
1018#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > /tmp/out_command_${LOGIN}.$$ 2>&1
1019#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> /tmp/out_command_${LOGIN}.$$ 2>&1
1020
1021#       status=$?
1022#       IGCM_sys_Rsync_out $status
1023
1024#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$
1030      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1031    else
1032      \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 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_${LOGIN}.$$
1071      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1072    else
1073      \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 2>&1
1120    ${RSYNC} ${RSYNC_opt} $1 $2 >> /tmp/out_command_${LOGIN}.$$ 2>&1
1121    status=$?
1122    IGCM_sys_Rsync_out $status
1123
1124    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$
1130      IGCM_debug_Exit "IGCM_sys_Put_Out"
1131    else
1132      \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 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_${LOGIN}.$$
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_${LOGIN}.$$
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_${LOGIN}.$$ 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_${LOGIN}.$$
1264      IGCM_debug_Exit "IGCM_sys_Get"
1265    else
1266      \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 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_${LOGIN}.$$
1320          \rm /tmp/out_command_${LOGIN}.$$
1321          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1322        else
1323          \rm /tmp/out_command_${LOGIN}.$$
1324        fi
1325      done
1326    else
1327      i=0
1328      while [ $i -lt $NB_ESSAI ] ; do
1329        \cp ${buf_liste} ${DEST} >> /tmp/out_command_${LOGIN}.$$ 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_${LOGIN}.$$
1343        \rm /tmp/out_command_${LOGIN}.$$
1344        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1345      else
1346        \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$ 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_${LOGIN}.$$
1452      \rm /tmp/out_command_${LOGIN}.$$
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_${LOGIN}.$$
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
1887        IGCM_debug_Print 1 "sys Obelix : script_${ExeNameOut}.ksh contains"
1888        cat script_${ExeNameOut}.ksh
1889
1890      fi
1891    done
1892
1893  fi
1894
1895  IGCM_debug_Print 1 "sys Obelix : execution command is"
1896  IGCM_debug_Print 1 "$EXECUTION"
1897
1898  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1899}
1900
1901#D-#==================================================
1902#D-function IGCM_sys_check_path
1903#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1904#D-* do not point to an important use directory. Stop immediately in that case.
1905#D-* Examples:
1906#D-
1907function IGCM_sys_check_path {
1908  IGCM_debug_PushStack "IGCM_sys_check_path"
1909  if ( $DEBUG_sys ) ; then
1910    echo "IGCM_sys_check_path"
1911  fi
1912
1913  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
1914    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1915    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1916    IGCM_debug_Exit "This will stop the job"
1917  fi
1918  IGCM_debug_PopStack "IGCM_sys_check_path"
1919}
1920
1921#D-#==================================================
1922#D-function IGCM_sys_check_quota. Dummy call here
1923#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1924#D-* Examples:
1925#D-
1926function IGCM_sys_check_quota {
1927  IGCM_debug_PushStack "IGCM_sys_check_quota"
1928  if ( $DEBUG_sys ) ; then
1929    echo "IGCM_sys_check_quota"
1930  fi
1931  IGCM_debug_PopStack "IGCM_sys_check_quota"
1932}
1933
1934#D-#==================================================
1935#D-function IGCM_sys_CountJobInQueue
1936#D-* Purpose: Check if job_name is currently
1937#D-  running or in queue
1938#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1939#D-
1940function IGCM_sys_CountJobInQueue {
1941  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1942  if ( $DEBUG_sys ) ; then
1943    echo "IGCM_sys_CountJobInQueue"
1944  fi
1945  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1946}
1947
1948##############################################################
1949# NCO OPERATOR
1950
1951#D-#==================================================
1952#D-function IGCM_sys_ncap2
1953#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1954#D-* Examples:
1955#D-
1956function IGCM_sys_ncap2 {
1957  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1958  if ( $DEBUG_sys ) ; then
1959    echo "IGCM_sys_ncap2 :" $@
1960  fi
1961
1962  typeset NB_ESSAI DELAI status i
1963  # number of tentative
1964  NB_ESSAI=3
1965  # time delay between tentative
1966  DELAI=2
1967
1968  i=0
1969  while [ $i -lt $NB_ESSAI ] ; do
1970    ncap2 "$@" > /tmp/out_command_${LOGIN}.$$ 2>&1
1971    status=$?
1972    if [ ${status} -gt 0 ] ; then
1973      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1974      cat /tmp/out_command_${LOGIN}.$$
1975      \rm /tmp/out_command_${LOGIN}.$$
1976      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1977      sleep $DELAI
1978    else
1979      \rm /tmp/out_command_${LOGIN}.$$
1980      break
1981    fi
1982    (( i = i + 1 ))
1983  done
1984
1985  if [ ${status} -gt 0 ] ; then
1986    echo "IGCM_sys_ncap2 : ncap2 error"
1987    IGCM_debug_Exit "ncap2"
1988  fi
1989
1990  IGCM_debug_PopStack "IGCM_sys_ncap2"
1991}
1992
1993#D-#==================================================
1994#D-function IGCM_sys_ncatted
1995#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
1996#D-* Examples:
1997#D-
1998function IGCM_sys_ncatted {
1999  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2000  if ( $DEBUG_sys ) ; then
2001    echo "IGCM_sys_ncatted :" $@
2002  fi
2003
2004  typeset NB_ESSAI DELAI status i
2005  # number of tentative
2006  NB_ESSAI=3
2007  # time delay between tentative
2008  DELAI=2
2009
2010  i=0
2011  while [ $i -lt $NB_ESSAI ] ; do
2012    ncatted "$@" > /tmp/out_command_${LOGIN}.$$ 2>&1
2013    status=$?
2014    if [ ${status} -gt 0 ] ; then
2015      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2016      cat /tmp/out_command_${LOGIN}.$$
2017      \rm /tmp/out_command_${LOGIN}.$$
2018      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2019      sleep $DELAI
2020    else
2021      \rm /tmp/out_command_${LOGIN}.$$
2022      break
2023    fi
2024    (( i = i + 1 ))
2025  done
2026
2027  if [ ${status} -gt 0 ] ; then
2028    echo "IGCM_sys_ncatted : ncatted error"
2029    IGCM_debug_Exit "ncatted"
2030  fi
2031
2032  IGCM_debug_PopStack "IGCM_sys_ncatted"
2033}
2034
2035#D-#==================================================
2036#D-function IGCM_sys_ncbo
2037#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2038#D-* Examples:
2039#D-
2040function IGCM_sys_ncbo {
2041  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2042  if ( $DEBUG_sys ) ; then
2043    echo "IGCM_sys_ncbo :" $@
2044  fi
2045
2046  typeset NB_ESSAI DELAI status i
2047  # number of tentative
2048  NB_ESSAI=3
2049  # time delay between tentative
2050  DELAI=2
2051
2052  i=0
2053  while [ $i -lt $NB_ESSAI ] ; do
2054    ncbo $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2055    status=$?
2056    if [ ${status} -gt 0 ] ; then
2057      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2058      cat /tmp/out_command_${LOGIN}.$$
2059      \rm /tmp/out_command_${LOGIN}.$$
2060      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2061      sleep $DELAI
2062    else
2063      \rm /tmp/out_command_${LOGIN}.$$
2064      break
2065    fi
2066    (( i = i + 1 ))
2067  done
2068
2069  if [ ${status} -gt 0 ] ; then
2070    echo "IGCM_sys_ncbo : ncbo error"
2071    IGCM_debug_Exit "ncbo"
2072  fi
2073
2074  IGCM_debug_PopStack "IGCM_sys_ncbo"
2075}
2076
2077#D-#==================================================
2078#D-function IGCM_sys_ncdif
2079#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2080#D-* Examples:
2081#D-
2082function IGCM_sys_ncdiff {
2083  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2084  if ( $DEBUG_sys ) ; then
2085    echo "IGCM_sys_ncdiff :" $@
2086  fi
2087
2088  typeset NB_ESSAI DELAI status i
2089  # number of tentative
2090  NB_ESSAI=3
2091  # time delay between tentative
2092  DELAI=2
2093
2094  i=0
2095  while [ $i -lt $NB_ESSAI ] ; do
2096    ncdiff $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2097    status=$?
2098    if [ ${status} -gt 0 ] ; then
2099      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2100      cat /tmp/out_command_${LOGIN}.$$
2101      \rm /tmp/out_command_${LOGIN}.$$
2102      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2103      sleep $DELAI
2104    else
2105      \rm /tmp/out_command_${LOGIN}.$$
2106      break
2107    fi
2108    (( i = i + 1 ))
2109  done
2110
2111  if [ ${status} -gt 0 ] ; then
2112    echo "IGCM_sys_ncdiff : ncdiff error"
2113    IGCM_debug_Exit "ncdiff"
2114  fi
2115
2116  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2117}
2118
2119#D-#==================================================
2120#D-function IGCM_sys_ncea
2121#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2122#D-* Examples:
2123#D-
2124function IGCM_sys_ncea {
2125  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2126  if ( $DEBUG_sys ) ; then
2127    echo "IGCM_sys_ncea :" $@
2128  fi
2129
2130  typeset NB_ESSAI DELAI status i
2131  # number of tentative
2132  NB_ESSAI=3
2133  # time delay between tentative
2134  DELAI=2
2135
2136  i=0
2137  while [ $i -lt $NB_ESSAI ] ; do
2138    ncea $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2139    status=$?
2140    if [ ${status} -gt 0 ] ; then
2141      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2142      cat /tmp/out_command_${LOGIN}.$$
2143      \rm /tmp/out_command_${LOGIN}.$$
2144      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2145      sleep $DELAI
2146    else
2147      \rm /tmp/out_command_${LOGIN}.$$
2148      break
2149    fi
2150    (( i = i + 1 ))
2151  done
2152
2153  if [ ${status} -gt 0 ] ; then
2154    echo "IGCM_sys_ncea : ncea error"
2155    IGCM_debug_Exit "ncea"
2156  fi
2157
2158  IGCM_debug_PopStack "IGCM_sys_ncea"
2159}
2160
2161#D-#==================================================
2162#D-function IGCM_sys_ncecat
2163#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2164#D-* Examples:
2165#D-
2166function IGCM_sys_ncecat {
2167  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2168  if ( $DEBUG_sys ) ; then
2169    echo "IGCM_sys_ncecat :" $@
2170  fi
2171
2172  typeset NB_ESSAI DELAI status i
2173  # number of tentative
2174  NB_ESSAI=3
2175  # time delay between tentative
2176  DELAI=2
2177
2178  i=0
2179  while [ $i -lt $NB_ESSAI ] ; do
2180    ncecat $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2181    status=$?
2182    if [ ${status} -gt 0 ] ; then
2183      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2184      cat /tmp/out_command_${LOGIN}.$$
2185      \rm /tmp/out_command_${LOGIN}.$$
2186      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2187      sleep $DELAI
2188    else
2189      \rm /tmp/out_command_${LOGIN}.$$
2190      break
2191    fi
2192    (( i = i + 1 ))
2193  done
2194
2195  if [ ${status} -gt 0 ] ; then
2196    echo "IGCM_sys_ncecat : ncecat error"
2197    IGCM_debug_Exit "ncecat"
2198  fi
2199
2200  IGCM_debug_PopStack "IGCM_sys_ncecat"
2201}
2202
2203#D-#==================================================
2204#D-function IGCM_sys_ncflint
2205#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2206#D-* Examples:
2207#D-
2208function IGCM_sys_ncflint {
2209  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2210  if ( $DEBUG_sys ) ; then
2211    echo "IGCM_sys_ncflint :" $@
2212  fi
2213
2214  typeset NB_ESSAI DELAI status i
2215  # number of tentative
2216  NB_ESSAI=3
2217  # time delay between tentative
2218  DELAI=2
2219
2220  i=0
2221  while [ $i -lt $NB_ESSAI ] ; do
2222    ncflint $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2223    status=$?
2224    if [ ${status} -gt 0 ] ; then
2225      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2226      cat /tmp/out_command_${LOGIN}.$$
2227      \rm /tmp/out_command_${LOGIN}.$$
2228      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2229      sleep $DELAI
2230    else
2231      \rm /tmp/out_command_${LOGIN}.$$
2232      break
2233    fi
2234    (( i = i + 1 ))
2235  done
2236
2237  if [ ${status} -gt 0 ] ; then
2238    echo "IGCM_sys_ncflint : ncflint error"
2239    IGCM_debug_Exit "ncflint"
2240  fi
2241
2242  IGCM_debug_PopStack "IGCM_sys_ncflint"
2243}
2244
2245#D-#==================================================
2246#D-function IGCM_sys_ncks
2247#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2248#D-* Examples:
2249#D-
2250function IGCM_sys_ncks {
2251  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2252  if ( $DEBUG_sys ) ; then
2253    echo "IGCM_sys_ncks :" $@
2254  fi
2255
2256  typeset NB_ESSAI DELAI status i
2257  # number of tentative
2258  NB_ESSAI=3
2259  # time delay between tentative
2260  DELAI=2
2261
2262  i=0
2263  while [ $i -lt $NB_ESSAI ] ; do
2264    ncks $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2265    status=$?
2266    if [ ${status} -gt 0 ] ; then
2267      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2268      cat /tmp/out_command_${LOGIN}.$$
2269      \rm /tmp/out_command_${LOGIN}.$$
2270      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2271      sleep $DELAI
2272    else
2273      \rm /tmp/out_command_${LOGIN}.$$
2274      break
2275    fi
2276    (( i = i + 1 ))
2277  done
2278
2279  if [ ${status} -gt 0 ] ; then
2280    echo "IGCM_sys_ncks : ncks error"
2281    IGCM_debug_Exit "ncks"
2282  fi
2283
2284  IGCM_debug_PopStack "IGCM_sys_ncks"
2285}
2286
2287#D-#==================================================
2288#D-function IGCM_sys_ncpdq
2289#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2290#D-* Examples:
2291#D-
2292function IGCM_sys_ncpdq {
2293  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2294  if ( $DEBUG_sys ) ; then
2295    echo "IGCM_sys_ncpdq :" $@
2296  fi
2297
2298  typeset NB_ESSAI DELAI status i
2299  # number of tentative
2300  NB_ESSAI=3
2301  # time delay between tentative
2302  DELAI=2
2303
2304  i=0
2305  while [ $i -lt $NB_ESSAI ] ; do
2306    ncpdq $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2307    status=$?
2308    if [ ${status} -gt 0 ] ; then
2309      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2310      cat /tmp/out_command_${LOGIN}.$$
2311      \rm /tmp/out_command_${LOGIN}.$$
2312      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2313      sleep $DELAI
2314    else
2315      \rm /tmp/out_command_${LOGIN}.$$
2316      break
2317    fi
2318    (( i = i + 1 ))
2319  done
2320
2321  if [ ${status} -gt 0 ] ; then
2322    echo "IGCM_sys_ncpdq : ncpdq error"
2323    IGCM_debug_Exit "ncpdq"
2324  fi
2325
2326  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2327}
2328
2329#D-#==================================================
2330#D-function IGCM_sys_ncra
2331#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2332#D-* Examples:
2333#D-
2334function IGCM_sys_ncra {
2335  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2336  if ( $DEBUG_sys ) ; then
2337    echo "IGCM_sys_ncra :" $@
2338  fi
2339
2340  typeset NB_ESSAI DELAI status i
2341  # number of tentative
2342  NB_ESSAI=3
2343  # time delay between tentative
2344  DELAI=2
2345
2346  i=0
2347  while [ $i -lt $NB_ESSAI ] ; do
2348    ncra $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2349    status=$?
2350    if [ ${status} -gt 0 ] ; then
2351      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2352      cat /tmp/out_command_${LOGIN}.$$
2353      \rm /tmp/out_command_${LOGIN}.$$
2354      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2355      sleep $DELAI
2356    else
2357      \rm /tmp/out_command_${LOGIN}.$$
2358      break
2359    fi
2360    (( i = i + 1 ))
2361  done
2362
2363  if [ ${status} -gt 0 ] ; then
2364    echo "IGCM_sys_ncra : ncra error"
2365    IGCM_debug_Exit "ncra"
2366  fi
2367
2368  IGCM_debug_PopStack "IGCM_sys_ncra"
2369}
2370
2371#D-#==================================================
2372#D-function IGCM_sys_ncrcat
2373#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2374#D-* Examples:
2375#D-
2376function IGCM_sys_ncrcat {
2377  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2378  if ( $DEBUG_sys ) ; then
2379    echo "IGCM_sys_ncrcat :" $@
2380  fi
2381
2382  typeset NB_ESSAI DELAI status i lastArg
2383  # number of tentative
2384  NB_ESSAI=3
2385  # time delay between tentative
2386  DELAI=2
2387
2388  i=0
2389  while [ $i -lt $NB_ESSAI ] ; do
2390    ncrcat $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2391    status=$?
2392    if [ ${status} -gt 0 ] ; then
2393      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2394      cat /tmp/out_command_${LOGIN}.$$
2395      \rm /tmp/out_command_${LOGIN}.$$
2396      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2397      sleep $DELAI
2398    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command_${LOGIN}.$$ )" = "X" ] ; then
2399      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2400      cat /tmp/out_command_${LOGIN}.$$
2401      # remove files having corrupted time axis
2402      eval lastArg=\${$#}
2403      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2404      \rm ${lastArg}
2405      \rm /tmp/out_command_${LOGIN}.$$
2406      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2407      sleep $DELAI
2408    else
2409      \rm /tmp/out_command_${LOGIN}.$$
2410      break
2411    fi
2412    (( i = i + 1 ))
2413  done
2414
2415  if [ ${status} -gt 0 ] ; then
2416    echo "IGCM_sys_ncrcat : ncrcat error"
2417    #IGCM_debug_Exit "ncrcat"
2418  fi
2419
2420  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2421}
2422
2423#D-#==================================================
2424#D-function IGCM_sys_ncrename
2425#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2426#D-* Examples:
2427#D-
2428function IGCM_sys_ncrename {
2429  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2430  if ( $DEBUG_sys ) ; then
2431    echo "IGCM_sys_ncrename :" $@
2432  fi
2433
2434  typeset NB_ESSAI DELAI status i
2435  # number of tentative
2436  NB_ESSAI=3
2437  # time delay between tentative
2438  DELAI=2
2439
2440  i=0
2441  while [ $i -lt $NB_ESSAI ] ; do
2442    ncrename $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2443    status=$?
2444    if [ ${status} -gt 0 ] ; then
2445      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2446      cat /tmp/out_command_${LOGIN}.$$
2447      \rm /tmp/out_command_${LOGIN}.$$
2448      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2449      sleep $DELAI
2450    else
2451      \rm /tmp/out_command_${LOGIN}.$$
2452      break
2453    fi
2454    (( i = i + 1 ))
2455  done
2456
2457  if [ ${status} -gt 0 ] ; then
2458    echo "IGCM_sys_ncrename : ncrename error"
2459    IGCM_debug_Exit "ncrename"
2460  fi
2461
2462  IGCM_debug_PopStack "IGCM_sys_ncrename"
2463}
2464
2465#D-#==================================================
2466#D-function IGCM_sys_ncwa
2467#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2468#D-* Examples:
2469#D-
2470function IGCM_sys_ncwa {
2471  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2472  if ( $DEBUG_sys ) ; then
2473    echo "IGCM_sys_ncwa :" $@
2474  fi
2475
2476  typeset NB_ESSAI DELAI status i
2477  # number of tentative
2478  NB_ESSAI=3
2479  # time delay between tentative
2480  DELAI=2
2481
2482  i=0
2483  while [ $i -lt $NB_ESSAI ] ; do
2484    ncwa $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2485    status=$?
2486    if [ ${status} -gt 0 ] ; then
2487      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2488      cat /tmp/out_command_${LOGIN}.$$
2489      \rm /tmp/out_command_${LOGIN}.$$
2490      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2491      sleep $DELAI
2492    else
2493      \rm /tmp/out_command_${LOGIN}.$$
2494      break
2495    fi
2496    (( i = i + 1 ))
2497  done
2498
2499  if [ ${status} -gt 0 ] ; then
2500    echo "IGCM_sys_ncwa : ncwa error"
2501    IGCM_debug_Exit "ncwa"
2502  fi
2503
2504  IGCM_debug_PopStack "IGCM_sys_ncwa"
2505}
2506
2507##############################################################
2508# CDO OPERATOR
2509
2510#D-#==================================================
2511#D-function IGCM_sys_cdo
2512#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2513#D-* Examples:
2514#D-
2515function IGCM_sys_cdo {
2516  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2517  if ( $DEBUG_sys ) ; then
2518    echo "IGCM_sys_cdo :" $@
2519  fi
2520
2521  typeset status
2522
2523  \cdo $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2524  status=$?
2525  if [ ${status} -gt 0 ] ; then
2526    echo "IGCM_sys_cdo : error code ${status}"
2527    cat /tmp/out_command_${LOGIN}.$$
2528    \rm /tmp/out_command_${LOGIN}.$$
2529    IGCM_debug_PopStack "IGCM_sys_cdo"
2530    return 1
2531  else
2532    IGCM_debug_PopStack "IGCM_sys_cdo"
2533    return 0
2534  fi
2535
2536  IGCM_debug_PopStack "IGCM_sys_cdo"
2537}
Note: See TracBrowser for help on using the repository browser.