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

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