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

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