source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_mercure.ksh @ 801

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