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

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