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

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