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

Last change on this file since 725 was 725, checked in by sdipsl, 12 years ago
  • prepare sys lib to be able to run/store on scratchdir when running TEST simulation
  • bugfix : rebuild can't overwrite existing files neither write things in a tmp file before moving it to a final file. So we need to clean things up for him
  • cosmetics
  • Property svn:keywords set to Revision Author Date
File size: 61.8 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 lastArg
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      eval lastArg=\$$#
1635      \rm ${lastArg}
1636    else
1637      \rm out_rsync
1638      break
1639    fi
1640    (( i = i + 1 ))
1641  done
1642
1643  if [ ${status} -gt 0 ] ; then
1644    echo "IGCM_sys_rebuild : rebuild error"
1645    IGCM_debug_Exit "rebuild"
1646  fi
1647
1648  IGCM_debug_PopStack "IGCM_sys_rebuild"
1649}
1650
1651function IGCM_sys_rebuild_station {
1652  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1653  typeset i list_opt file_in file_out prefix_invert list_invert
1654  if ( $DEBUG_sys ) ; then
1655    echo "IGCM_sys_rebuild_station :" $@
1656  fi
1657  list_opt=$@
1658
1659  # Invert Axis : t,x -> x,t
1660  #               t,pres,x -> x,t,pres
1661  # So that we can concatenate along x
1662  i=0
1663  for file_in in ${list_opt} ; do
1664    (( i = i + 1))
1665    [ ${i} = 1 ] && file_out=${file_in} && continue
1666    prefix_invert=$( basename ${file_in} .nc )
1667    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1668    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1669  done
1670
1671  # Concatenate
1672  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1673
1674  # Re-ivert file
1675  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1676
1677  # Station re-ordering is too expansive to be run within libICGM
1678  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1679  # This re-ordering must be done "in memory" by the cmorization process
1680  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1681  # BEGIN reordering
1682
1683  # Only LMDZ text output contains the exact ordering of the station.
1684  # We isolate this in the code below:
1685  #  0  38  -157.5000000000000  70.98591549295774
1686  #  0  54  27.49999999999999   67.18309859154928
1687  #  0  56  -62.50000000000001  82.39436619718309
1688  #  0  79  12.49999999999999   78.59154929577466
1689  #  0  116 -165.0000000000000  76.05633802816901
1690  #  0  117 130.0000000000000   70.98591549295774
1691  #  0  118 110.0000000000000   87.46478873239437
1692  #  1  40  4.999999999999995   51.97183098591550
1693#  typeset iStation iProc list_opt file_in file_out prefix_invert
1694#  typeset -Z4 j4
1695#  typeset -Z3 j3
1696
1697#  unset list_opt
1698#  set +A list_opt $@
1699
1700  # Filename after rebuild
1701#  file_out=${list_opt[0]}
1702  # Prefix of output files
1703#  prefix_invert=$( basename ${file_out} .nc )
1704  # Number of procs
1705#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1706
1707#  iProc=0
1708#  while [ ${iProc} -lt ${num_proc} ] ; do
1709    # Array containing Station as a number
1710#    unset proc_stn
1711#    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}' )
1712    # Number of stations produced by processor proc
1713#    stationLast=${#proc_stn[*]}
1714    # Proc number on 4 digits
1715#    j4=${iProc}
1716    # Init
1717#    iStation=0
1718#    while [ ${iStation} -lt ${stationLast} ] ; do
1719      # Station number on 3 digits
1720#      j3=${proc_stn[${iStation}]}
1721      # Extract station
1722      # Invert Axis : t,x -> x,t
1723      #               t,pres,x -> x,t,pres
1724      # So that we can concatenate along x
1725#      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
1726#      (( iStation = iStation + 1 ))
1727#    done
1728#    (( iProc = iProc + 1 ))
1729#  done
1730
1731  # Concatenate all station along x
1732#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1733
1734  # Re-invert file
1735#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1736
1737  # END reordering
1738
1739  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1740}
1741
1742############################################################
1743# Check of space available on temporary filesytems
1744function IGCM_sys_check_quota {
1745    IGCM_debug_PushStack "IGCM_sys_check_quota"
1746    if ( $DEBUG_sys ) ; then
1747        echo "IGCM_sys_check_quota"
1748    fi
1749    IGCM_debug_PopStack "IGCM_sys_check_quota"
1750}
1751
1752##############################################################
1753# NCO OPERATOR
1754
1755function IGCM_sys_ncap2 {
1756  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1757  if ( $DEBUG_sys ) ; then
1758    echo "IGCM_sys_ncap2 :" $@
1759  fi
1760
1761  typeset NB_ESSAI DELAI status i
1762  # number of tentative
1763  NB_ESSAI=3
1764  # time delay between tentative
1765  DELAI=2
1766
1767  i=0
1768  while [ $i -lt $NB_ESSAI ] ; do
1769    ncap2 "$@" > out_rsync 2>&1
1770    status=$?
1771    if [ ${status} -gt 0 ] ; then
1772      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1773      cat out_rsync
1774      \rm out_rsync
1775      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1776    else
1777      \rm out_rsync
1778      break
1779    fi
1780    (( i = i + 1 ))
1781  done
1782
1783  if [ ${status} -gt 0 ] ; then
1784      echo "IGCM_sys_ncap2 : ncap2 error"
1785      IGCM_debug_Exit "ncap2"
1786  fi
1787
1788  IGCM_debug_PopStack "IGCM_sys_ncap2"
1789}
1790
1791function IGCM_sys_ncatted {
1792  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1793  if ( $DEBUG_sys ) ; then
1794    echo "IGCM_sys_ncatted :" $@
1795  fi
1796
1797  typeset NB_ESSAI DELAI status i
1798  # number of tentative
1799  NB_ESSAI=3
1800  # time delay between tentative
1801  DELAI=2
1802
1803  i=0
1804  while [ $i -lt $NB_ESSAI ] ; do
1805    ncatted "$@" > out_rsync 2>&1
1806    status=$?
1807    if [ ${status} -gt 0 ] ; then
1808      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1809      cat out_rsync
1810      \rm out_rsync
1811      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1812    else
1813      \rm out_rsync
1814      break
1815    fi
1816    (( i = i + 1 ))
1817  done
1818
1819  if [ ${status} -gt 0 ] ; then
1820      echo "IGCM_sys_ncatted : ncatted error"
1821      IGCM_debug_Exit "ncatted"
1822  fi
1823
1824  IGCM_debug_PopStack "IGCM_sys_ncatted"
1825}
1826
1827function IGCM_sys_ncbo {
1828  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1829  if ( $DEBUG_sys ) ; then
1830    echo "IGCM_sys_ncbo :" $@
1831  fi
1832
1833  typeset NB_ESSAI DELAI status i
1834  # number of tentative
1835  NB_ESSAI=3
1836  # time delay between tentative
1837  DELAI=2
1838
1839  i=0
1840  while [ $i -lt $NB_ESSAI ] ; do
1841    ncbo $@ > out_rsync 2>&1
1842    status=$?
1843    if [ ${status} -gt 0 ] ; then
1844      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1845      cat out_rsync
1846      \rm out_rsync
1847      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1848    else
1849      \rm out_rsync
1850      break
1851    fi
1852    (( i = i + 1 ))
1853  done
1854
1855  if [ ${status} -gt 0 ] ; then
1856      echo "IGCM_sys_ncbo : ncbo error"
1857      IGCM_debug_Exit "ncbo"
1858  fi
1859
1860  IGCM_debug_PopStack "IGCM_sys_ncbo"
1861}
1862
1863function IGCM_sys_ncdiff {
1864  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1865  if ( $DEBUG_sys ) ; then
1866    echo "IGCM_sys_ncdiff :" $@
1867  fi
1868
1869  typeset NB_ESSAI DELAI status i
1870  # number of tentative
1871  NB_ESSAI=3
1872  # time delay between tentative
1873  DELAI=2
1874
1875  i=0
1876  while [ $i -lt $NB_ESSAI ] ; do
1877    ncdiff $@ > out_rsync 2>&1
1878    status=$?
1879    if [ ${status} -gt 0 ] ; then
1880      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1881      cat out_rsync
1882      \rm out_rsync
1883      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1884    else
1885      \rm out_rsync
1886      break
1887    fi
1888    (( i = i + 1 ))
1889  done
1890
1891  if [ ${status} -gt 0 ] ; then
1892      echo "IGCM_sys_ncdiff : ncdiff error"
1893      IGCM_debug_Exit "ncdiff"
1894  fi
1895
1896  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1897}
1898
1899function IGCM_sys_ncea {
1900  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1901  if ( $DEBUG_sys ) ; then
1902    echo "IGCM_sys_ncea :" $@
1903  fi
1904
1905  typeset NB_ESSAI DELAI status i
1906  # number of tentative
1907  NB_ESSAI=3
1908  # time delay between tentative
1909  DELAI=2
1910
1911  i=0
1912  while [ $i -lt $NB_ESSAI ] ; do
1913    ncea $@ > out_rsync 2>&1
1914    status=$?
1915    if [ ${status} -gt 0 ] ; then
1916      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1917      cat out_rsync
1918      \rm out_rsync
1919      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1920    else
1921      \rm out_rsync
1922      break
1923    fi
1924    (( i = i + 1 ))
1925  done
1926
1927  if [ ${status} -gt 0 ] ; then
1928      echo "IGCM_sys_ncea : ncea error"
1929      IGCM_debug_Exit "ncea"
1930  fi
1931
1932  IGCM_debug_PopStack "IGCM_sys_ncea"
1933}
1934
1935function IGCM_sys_ncecat {
1936  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1937  if ( $DEBUG_sys ) ; then
1938    echo "IGCM_sys_ncecat :" $@
1939  fi
1940
1941  typeset NB_ESSAI DELAI status i
1942  # number of tentative
1943  NB_ESSAI=3
1944  # time delay between tentative
1945  DELAI=2
1946
1947  i=0
1948  while [ $i -lt $NB_ESSAI ] ; do
1949    ncecat $@ > out_rsync 2>&1
1950    status=$?
1951    if [ ${status} -gt 0 ] ; then
1952      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1953      cat out_rsync
1954      \rm out_rsync
1955      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1956    else
1957      \rm out_rsync
1958      break
1959    fi
1960    (( i = i + 1 ))
1961  done
1962
1963  if [ ${status} -gt 0 ] ; then
1964      echo "IGCM_sys_ncecat : ncecat error"
1965      IGCM_debug_Exit "ncecat"
1966  fi
1967
1968  IGCM_debug_PopStack "IGCM_sys_ncecat"
1969}
1970
1971function IGCM_sys_ncflint {
1972  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1973  if ( $DEBUG_sys ) ; then
1974    echo "IGCM_sys_ncflint :" $@
1975  fi
1976
1977  typeset NB_ESSAI DELAI status i
1978  # number of tentative
1979  NB_ESSAI=3
1980  # time delay between tentative
1981  DELAI=2
1982
1983  i=0
1984  while [ $i -lt $NB_ESSAI ] ; do
1985    ncflint $@ > out_rsync 2>&1
1986    status=$?
1987    if [ ${status} -gt 0 ] ; then
1988      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1989      cat out_rsync
1990      \rm out_rsync
1991      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1992    else
1993      \rm out_rsync
1994      break
1995    fi
1996    (( i = i + 1 ))
1997  done
1998
1999  if [ ${status} -gt 0 ] ; then
2000      echo "IGCM_sys_ncflint : ncflint error"
2001      IGCM_debug_Exit "ncflint"
2002  fi
2003
2004  IGCM_debug_PopStack "IGCM_sys_ncflint"
2005}
2006
2007function IGCM_sys_ncks {
2008  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2009  if ( $DEBUG_sys ) ; then
2010    echo "IGCM_sys_ncks :" $@
2011  fi
2012
2013  typeset NB_ESSAI DELAI status i
2014  # number of tentative
2015  NB_ESSAI=3
2016  # time delay between tentative
2017  DELAI=2
2018
2019  i=0
2020  while [ $i -lt $NB_ESSAI ] ; do
2021    ncks $@ > out_rsync 2>&1
2022    status=$?
2023    if [ ${status} -gt 0 ] ; then
2024      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2025      cat out_rsync
2026      \rm out_rsync
2027      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2028    else
2029      \rm out_rsync
2030      break
2031    fi
2032    (( i = i + 1 ))
2033  done
2034
2035  if [ ${status} -gt 0 ] ; then
2036      echo "IGCM_sys_ncks : ncks error"
2037      IGCM_debug_Exit "ncks"
2038  fi
2039
2040  IGCM_debug_PopStack "IGCM_sys_ncks"
2041}
2042
2043function IGCM_sys_ncpdq {
2044  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2045  if ( $DEBUG_sys ) ; then
2046    echo "IGCM_sys_ncpdq :" $@
2047  fi
2048
2049  typeset NB_ESSAI DELAI status i
2050  # number of tentative
2051  NB_ESSAI=3
2052  # time delay between tentative
2053  DELAI=2
2054
2055  i=0
2056  while [ $i -lt $NB_ESSAI ] ; do
2057    ncpdq $@ > out_rsync 2>&1
2058    status=$?
2059    if [ ${status} -gt 0 ] ; then
2060      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2061      cat out_rsync
2062      \rm out_rsync
2063      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2064    else
2065      \rm out_rsync
2066      break
2067    fi
2068    (( i = i + 1 ))
2069  done
2070
2071  if [ ${status} -gt 0 ] ; then
2072      echo "IGCM_sys_ncpdq : ncpdq error"
2073      IGCM_debug_Exit "ncpdq"
2074  fi
2075
2076  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2077}
2078
2079function IGCM_sys_ncra {
2080  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2081  if ( $DEBUG_sys ) ; then
2082    echo "IGCM_sys_ncra :" $@
2083  fi
2084
2085  typeset NB_ESSAI DELAI status i
2086  # number of tentative
2087  NB_ESSAI=3
2088  # time delay between tentative
2089  DELAI=2
2090
2091  i=0
2092  while [ $i -lt $NB_ESSAI ] ; do
2093    ncra $@ > out_rsync 2>&1
2094    status=$?
2095    if [ ${status} -gt 0 ] ; then
2096      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2097      cat out_rsync
2098      \rm out_rsync
2099      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2100    else
2101      \rm out_rsync
2102      break
2103    fi
2104    (( i = i + 1 ))
2105  done
2106
2107  if [ ${status} -gt 0 ] ; then
2108      echo "IGCM_sys_ncra : ncra error"
2109      IGCM_debug_Exit "ncra"
2110  fi
2111
2112  IGCM_debug_PopStack "IGCM_sys_ncra"
2113}
2114
2115function IGCM_sys_ncrcat {
2116  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2117  if ( $DEBUG_sys ) ; then
2118    echo "IGCM_sys_ncrcat :" $@
2119  fi
2120
2121  typeset NB_ESSAI DELAI status i
2122  # number of tentative
2123  NB_ESSAI=3
2124  # time delay between tentative
2125  DELAI=2
2126
2127  i=0
2128  while [ $i -lt $NB_ESSAI ] ; do
2129    ncrcat $@ > out_rsync 2>&1
2130    status=$?
2131    if [ ${status} -gt 0 ] ; then
2132      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2133      cat out_rsync
2134      \rm out_rsync
2135      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2136    else
2137      \rm out_rsync
2138      break
2139    fi
2140    (( i = i + 1 ))
2141  done
2142
2143  if [ ${status} -gt 0 ] ; then
2144      echo "IGCM_sys_ncrcat : ncrcat error"
2145      #IGCM_debug_Exit "ncrcat"
2146  fi
2147
2148  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2149}
2150
2151function IGCM_sys_ncrename {
2152  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2153  if ( $DEBUG_sys ) ; then
2154    echo "IGCM_sys_ncrename :" $@
2155  fi
2156
2157  typeset NB_ESSAI DELAI status i
2158  # number of tentative
2159  NB_ESSAI=3
2160  # time delay between tentative
2161  DELAI=2
2162
2163  i=0
2164  while [ $i -lt $NB_ESSAI ] ; do
2165    ncrename $@ > out_rsync 2>&1
2166    status=$?
2167    if [ ${status} -gt 0 ] ; then
2168      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2169      cat out_rsync
2170      \rm out_rsync
2171      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2172    else
2173      \rm out_rsync
2174      break
2175    fi
2176    (( i = i + 1 ))
2177  done
2178
2179  if [ ${status} -gt 0 ] ; then
2180      echo "IGCM_sys_ncrename : ncrename error"
2181      IGCM_debug_Exit "ncrename"
2182  fi
2183
2184  IGCM_debug_PopStack "IGCM_sys_ncrename"
2185}
2186
2187function IGCM_sys_ncwa {
2188  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2189  if ( $DEBUG_sys ) ; then
2190    echo "IGCM_sys_ncwa :" $@
2191  fi
2192
2193  typeset NB_ESSAI DELAI status i
2194  # number of tentative
2195  NB_ESSAI=3
2196  # time delay between tentative
2197  DELAI=2
2198
2199  i=0
2200  while [ $i -lt $NB_ESSAI ] ; do
2201    ncwa $@ > out_rsync 2>&1
2202    status=$?
2203    if [ ${status} -gt 0 ] ; then
2204      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2205      cat out_rsync
2206      \rm out_rsync
2207      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2208    else
2209      \rm out_rsync
2210      break
2211    fi
2212    (( i = i + 1 ))
2213  done
2214
2215  if [ ${status} -gt 0 ] ; then
2216      echo "IGCM_sys_ncwa : ncwa error"
2217      IGCM_debug_Exit "ncwa"
2218  fi
2219
2220  IGCM_debug_PopStack "IGCM_sys_ncwa"
2221}
2222
2223##############################################################
2224# CDO OPERATOR
2225
2226function IGCM_sys_cdo {
2227  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2228  if ( $DEBUG_sys ) ; then
2229    echo "IGCM_sys_cdo :" $@
2230  fi
2231
2232  typeset status
2233
2234  \cdo $@ > out_rsync 2>&1
2235  status=$?
2236  if [ ${status} -gt 0 ] ; then
2237    echo "IGCM_sys_cdo : error code ${status}"
2238    cat out_rsync
2239    \rm out_rsync
2240    IGCM_debug_PopStack "IGCM_sys_cdo"
2241    return 1
2242  else
2243    IGCM_debug_PopStack "IGCM_sys_cdo"
2244    return 0
2245  fi
2246
2247  IGCM_debug_PopStack "IGCM_sys_cdo"
2248}
2249
2250############################################################
2251# Activate Running Environnment Variables
2252
2253function IGCM_sys_activ_variables {
2254  IGCM_debug_PushStack "IGCM_sys_activ_variables"
2255  if ( $DEBUG_sys ) ; then
2256    echo "IGCM_sys_activ_variables"
2257  fi
2258  IGCM_debug_PopStack "IGCM_sys_activ_variables"
2259}
2260
2261############################################################
2262# Desactivate Running Environnment Variables
2263
2264function IGCM_sys_desactiv_variables {
2265  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
2266  if ( $DEBUG_sys ) ; then
2267    echo "IGCM_sys_desactiv_variables"
2268  fi
2269  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
2270}
2271
2272############################################################
2273# Build run file
2274
2275function IGCM_sys_build_run_file {
2276  IGCM_debug_PushStack "IGCM_sys_build_run_file"
2277  if ( $DEBUG_sys ) ; then
2278    echo "IGCM_sys_build_run_file"
2279  fi
2280  IGCM_debug_PopStack "IGCM_sys_build_run_file"
2281}
Note: See TracBrowser for help on using the repository browser.