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

Last change on this file since 720 was 719, checked in by sdipsl, 12 years ago
  • curie, titane, mercurex9, mercure : minor bugfixes coming from r716 and r717. Further systematic loop over cp command
  • obelix, vargas, ulam : cosmetics
  • Property svn:keywords set to Revision Author Date
File size: 61.0 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for Mercure X64
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69
70#D-
71#D-#==================================================
72#D-Program used in libIGCM
73#D-#==================================================
74
75# rsync with path
76typeset -r RSYNC=/usr/bin/rsync
77# RSYNC_opt args to rsync
78typeset -r RSYNC_opt="-va"
79# ie storage filesystem
80typeset -r RHOST=mercure
81
82#====================================================
83# Set environment tools (ferret, nco, cdo)
84#====================================================
85. /home/cont003/p86ipsl/.atlas_env_mercure01_ksh
86
87#====================================================
88# Host specific DIRECTORIES
89#====================================================
90
91#====================================================
92#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
93typeset -r R_EXE="${MODIPSL}/bin"
94
95#====================================================
96# For interactive jobs on mercure
97PBS_O_WORKDIR=${PBS_O_WORKDIR:=$(pwd)}
98
99#====================================================
100#- SUBMIT_DIR : submission dir
101typeset SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
102
103#====================================================
104#- 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  status=$1
562  if [ ! $status ] ; then
563    echo "rsync error !"
564  fi
565
566  if [ $MYLANG = "fr" ]; then
567    case $status 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 :" $status
616      return;;
617    esac
618  elif [ $MYLANG = "en" ] ; then
619    case $status 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 :" $status
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 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    #   #RSYNC WITH NETWORK SSH CALL
1283    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1284    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1285
1286    #   #RSYNC WITH NFS USE
1287    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1288    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1289
1290    #   status=$?
1291    #   IGCM_sys_Rsync_out $status
1292
1293    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1294    #   (( status=status+$? ))
1295
1296    #USUAL WAY
1297    if [ X${1} = X'/l' ] ; then
1298      for target in ${dm_liste[*]} ; do
1299        local_file=$( basename ${target} )
1300        # test if the target file is present before the loop
1301        IGCM_sys_TestFileArchive ${target}
1302        status=$?
1303        if [ ${status} -gt 0 ] ; then
1304          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1305          IGCM_debug_Exit "IGCM_sys_Get"
1306        else
1307          i=0
1308          while [ $i -lt $NB_ESSAI ] ; do
1309            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1310            status=$?
1311            if [ ${status} -gt 0 ]; then
1312              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1313              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1314              sleep $DELAI
1315            else
1316              break
1317            fi
1318            (( i = i + 1 ))
1319          done
1320          if [ ${status} -gt 0 ] ; then
1321            echo "IGCM_sys_Get : error"
1322            cat out_rsync
1323            \rm out_rsync
1324            IGCM_debug_Exit "IGCM_sys_Get"
1325          else
1326            \rm out_rsync
1327          fi
1328        fi
1329      done
1330    else
1331      i=0
1332      while [ $i -lt $NB_ESSAI ] ; do
1333        \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1334        status=$?
1335        if [ ${status} -gt 0 ]; then
1336          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1337          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1338          sleep $DELAI
1339        else
1340          break
1341        fi
1342        (( i = i + 1 ))
1343      done
1344      if [ ${status} -gt 0 ] ; then
1345        echo "IGCM_sys_Get : error"
1346        cat out_rsync
1347        \rm out_rsync
1348        IGCM_debug_Exit "IGCM_sys_Get"
1349      else
1350        \rm out_rsync
1351      fi
1352    fi
1353  else
1354    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1355  fi
1356  IGCM_debug_PopStack "IGCM_sys_Get"
1357}
1358
1359#D-#==================================================
1360#D-function IGCM_sys_GetBuffer
1361#D-* Purpose: Get a file from ${SCRATCHDIR}
1362#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1363#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1364function IGCM_sys_GetBuffer {
1365  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1366
1367  typeset DEST buf_liste ifile target file_work
1368  typeset NB_ESSAI DELAI status i
1369
1370  if ( $DEBUG_sys ) ; then
1371    echo "IGCM_sys_GetBuffer :" $@
1372  fi
1373
1374  # number of tentative
1375  NB_ESSAI=3
1376  # time delay between tentative
1377  DELAI=2
1378
1379  if [ $DRYRUN -le 2 ]; then
1380    if [ X${1} = X'/l' ] ; then
1381      # test if the first file is present in the old computation :
1382      eval set +A buf_liste \${${2}}
1383    else
1384      eval set +A buf_liste ${1}
1385    fi
1386    eval DEST=\${${#}}
1387
1388    #USUAL WAY
1389    if [ X${1} = X'/l' ] ; then
1390      for target in ${buf_liste[*]} ; do
1391        local_file=$( basename ${target} )
1392        i=0
1393        while [ $i -lt $NB_ESSAI ] ; do
1394          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1395          status=$?
1396          if [ ${status} -gt 0 ]; then
1397            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1398            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1399            sleep $DELAI
1400          else
1401            break
1402          fi
1403          (( i = i + 1 ))
1404        done
1405        if [ ${status} -gt 0 ] ; then
1406          echo "IGCM_sys_Get : error"
1407          cat out_rsync
1408          \rm out_rsync
1409          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1410        else
1411          \rm out_rsync
1412        fi
1413      done
1414    else
1415      i=0
1416      while [ $i -lt $NB_ESSAI ] ; do
1417        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1418        status=$?
1419        if [ ${status} -gt 0 ]; then
1420          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1421          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1422          sleep $DELAI
1423        else
1424          break
1425        fi
1426        (( i = i + 1 ))
1427      done
1428      if [ ${status} -gt 0 ] ; then
1429        echo "IGCM_sys_Get : error"
1430        cat out_rsync
1431        \rm out_rsync
1432        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1433      else
1434        \rm out_rsync
1435      fi
1436    fi
1437  else
1438    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1439  fi
1440  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1441}
1442
1443#D-#==================================================
1444#D-function IGCM_sys_GetDate_FichWork
1445#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1446#D-* Examples:
1447#D-
1448function IGCM_sys_GetDate_FichWork {
1449  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1450  if ( $DEBUG_sys ) ; then
1451    echo "IGCM_sys_GetDate_FichWork :" $@
1452  fi
1453  # donne la date filesys d'un fichier sur la machine work
1454  IGCM_debug_PopStack "IGCM_sys_FichWork"
1455}
1456
1457#D-#==================================================
1458#D-function IGCM_sys_GetDate_FichArchive
1459#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1460#D-* Examples:
1461#D-
1462function IGCM_sys_GetDate_FichArchive {
1463  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1464  if ( $DEBUG_sys ) ; then
1465    echo "IGCM_sys_GetDate_FichArchive :" $@
1466  fi
1467  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1468}
1469
1470#D-#==================================================
1471#D-function IGCM_sys_Dods_Rm
1472#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1473#D-* Examples:
1474#D-
1475function IGCM_sys_Dods_Rm {
1476  if ( $DEBUG_sys ) ; then
1477    echo "IGCM_sys_Dods_Rm :" $@
1478  fi
1479  typeset status
1480  if [ $DRYRUN = 0 ]; then
1481
1482#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1483#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1484#      echo "Nothing has been done."
1485#      return
1486#    fi
1487
1488    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1489    status=$?
1490
1491#       if [ ${status} -gt 0 ] ; then
1492#           echo "IGCM_sys_Dods_Rm : error."
1493#           cat out_dods_rm
1494#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1495#       else
1496#           rm out_dods_rm
1497#       fi
1498
1499  else
1500    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1501  fi
1502  return $status
1503}
1504
1505#D-#==================================================
1506#D-function IGCM_sys_Dods_Cp
1507#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1508#D-* Examples:
1509#D-
1510function IGCM_sys_Dods_Cp {
1511  if ( $DEBUG_sys ) ; then
1512    echo "IGCM_sys_Dods_Cp :" $@
1513  fi
1514  typeset status
1515  if [ $DRYRUN = 0 ]; then
1516
1517#    if [ ! -d ${R_SAVE}/${1} ] ; then
1518#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1519#      echo "Nothing has been done."
1520#      return
1521#    fi
1522
1523    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1524    status=$?
1525
1526#       if [ ${status} -gt 0 ] ; then
1527#           echo "IGCM_sys_Dods_Cp : error."
1528#           cat out_dods_cp
1529#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1530#       else
1531#           rm out_dods_cp
1532#       fi
1533
1534  else
1535    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1536  fi
1537  return $status
1538}
1539
1540#D-#==================================================
1541#D-function IGCM_sys_Put_Dods
1542#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1543#D-* Examples:
1544#D-
1545function IGCM_sys_Put_Dods {
1546  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1547  if ( $DEBUG_sys ) ; then
1548    echo "IGCM_sys_Put_Dods :" $@
1549  fi
1550  #set -vx
1551  typeset status
1552  if [ $DRYRUN = 0 ]; then
1553    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1554      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1555      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1556      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1557      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1558      return
1559    fi
1560
1561    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1562      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1563      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1564      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1565      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1566      return
1567    fi
1568    #
1569    if [ -d ${R_SAVE}/${1} ] ; then
1570      cd ${R_SAVE}
1571    elif [ -d ${R_FIGR}/${1} ] ; then
1572      cd ${R_FIGR}
1573    fi
1574
1575    IGCM_sys_Dods_Rm ${1}
1576    IGCM_sys_Dods_Cp ${1}
1577    status=0
1578
1579    if [ ${status} -gt 0 ] ; then
1580      echo "IGCM_sys_Put_Dods : error."
1581      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1582    fi
1583  else
1584    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1585  fi
1586  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1587}
1588
1589##############################################################
1590# REBUILD OPERATOR
1591
1592function IGCM_sys_rebuild {
1593  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1594  if ( $DEBUG_sys ) ; then
1595    echo "IGCM_sys_rebuild :" $@
1596  fi
1597
1598  typeset NB_ESSAI DELAI status i
1599  # number of tentative
1600  NB_ESSAI=3
1601  # time delay between tentative
1602  DELAI=2
1603
1604  i=0
1605  while [ $i -lt $NB_ESSAI ] ; do
1606    /home/cont003/p86ipsl/X86_64/bin/rebuild -f -o $@ > out_rsync 2>&1
1607    status=$?
1608    if [ ${status} -gt 0 ] ; then
1609      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1610      cat out_rsync
1611      \rm out_rsync
1612      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1613    else
1614      \rm out_rsync
1615      break
1616    fi
1617    (( i = i + 1 ))
1618  done
1619
1620  if [ $? -gt 0 ] ; then
1621    echo "IGCM_sys_rebuild : rebuild error"
1622    IGCM_debug_Exit "rebuild"
1623  fi
1624
1625  IGCM_debug_PopStack "IGCM_sys_rebuild"
1626}
1627
1628function IGCM_sys_rebuild_station {
1629  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1630  typeset i list_opt file_in file_out prefix_invert list_invert
1631  if ( $DEBUG_sys ) ; then
1632    echo "IGCM_sys_rebuild_station :" $@
1633  fi
1634  list_opt=$@
1635
1636  # Invert Axis : t,x -> x,t
1637  #               t,pres,x -> x,t,pres
1638  # So that we can concatenate along x
1639  i=0
1640  for file_in in ${list_opt} ; do
1641    (( i = i + 1))
1642    [ ${i} = 1 ] && file_out=${file_in} && continue
1643    prefix_invert=$( basename ${file_in} .nc )
1644    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1645    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1646  done
1647
1648  # Concatenate
1649  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1650
1651  # Re-ivert file
1652  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1653
1654  # Station re-ordering is too expansive to be run within libICGM
1655  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1656  # This re-ordering must be done "in memory" by the cmorization process
1657  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1658  # BEGIN reordering
1659
1660  # Only LMDZ text output contains the exact ordering of the station.
1661  # We isolate this in the code below:
1662  #  0  38  -157.5000000000000  70.98591549295774
1663  #  0  54  27.49999999999999   67.18309859154928
1664  #  0  56  -62.50000000000001  82.39436619718309
1665  #  0  79  12.49999999999999   78.59154929577466
1666  #  0  116 -165.0000000000000  76.05633802816901
1667  #  0  117 130.0000000000000   70.98591549295774
1668  #  0  118 110.0000000000000   87.46478873239437
1669  #  1  40  4.999999999999995   51.97183098591550
1670#  typeset iStation iProc list_opt file_in file_out prefix_invert
1671#  typeset -Z4 j4
1672#  typeset -Z3 j3
1673
1674#  unset list_opt
1675#  set +A list_opt $@
1676
1677  # Filename after rebuild
1678#  file_out=${list_opt[0]}
1679  # Prefix of output files
1680#  prefix_invert=$( basename ${file_out} .nc )
1681  # Number of procs
1682#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1683
1684#  iProc=0
1685#  while [ ${iProc} -lt ${num_proc} ] ; do
1686    # Array containing Station as a number
1687#    unset proc_stn
1688#    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}' )
1689    # Number of stations produced by processor proc
1690#    stationLast=${#proc_stn[*]}
1691    # Proc number on 4 digits
1692#    j4=${iProc}
1693    # Init
1694#    iStation=0
1695#    while [ ${iStation} -lt ${stationLast} ] ; do
1696      # Station number on 3 digits
1697#      j3=${proc_stn[${iStation}]}
1698      # Extract station
1699      # Invert Axis : t,x -> x,t
1700      #               t,pres,x -> x,t,pres
1701      # So that we can concatenate along x
1702#      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
1703#      (( iStation = iStation + 1 ))
1704#    done
1705#    (( iProc = iProc + 1 ))
1706#  done
1707
1708  # Concatenate all station along x
1709#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1710
1711  # Re-invert file
1712#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1713
1714  # END reordering
1715
1716  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1717}
1718
1719############################################################
1720# Check of space available on temporary filesytems
1721function IGCM_sys_check_quota {
1722    IGCM_debug_PushStack "IGCM_sys_check_quota"
1723    if ( $DEBUG_sys ) ; then
1724        echo "IGCM_sys_check_quota"
1725    fi
1726    IGCM_debug_PopStack "IGCM_sys_check_quota"
1727}
1728
1729##############################################################
1730# NCO OPERATOR
1731
1732function IGCM_sys_ncap2 {
1733  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1734  if ( $DEBUG_sys ) ; then
1735    echo "IGCM_sys_ncap2 :" $@
1736  fi
1737
1738  typeset NB_ESSAI DELAI status i
1739  # number of tentative
1740  NB_ESSAI=3
1741  # time delay between tentative
1742  DELAI=2
1743
1744  i=0
1745  while [ $i -lt $NB_ESSAI ] ; do
1746    ncap2 "$@" > out_rsync 2>&1
1747    status=$?
1748    if [ ${status} -gt 0 ] ; then
1749      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1750      cat out_rsync
1751      \rm out_rsync
1752      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1753    else
1754      \rm out_rsync
1755      break
1756    fi
1757    (( i = i + 1 ))
1758  done
1759
1760  if [ ${status} -gt 0 ] ; then
1761      echo "IGCM_sys_ncap2 : ncap2 error"
1762      IGCM_debug_Exit "ncap2"
1763  fi
1764
1765  IGCM_debug_PopStack "IGCM_sys_ncap2"
1766}
1767
1768function IGCM_sys_ncatted {
1769  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1770  if ( $DEBUG_sys ) ; then
1771    echo "IGCM_sys_ncatted :" $@
1772  fi
1773
1774  typeset NB_ESSAI DELAI status i
1775  # number of tentative
1776  NB_ESSAI=3
1777  # time delay between tentative
1778  DELAI=2
1779
1780  i=0
1781  while [ $i -lt $NB_ESSAI ] ; do
1782    ncatted "$@" > out_rsync 2>&1
1783    status=$?
1784    if [ ${status} -gt 0 ] ; then
1785      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1786      cat out_rsync
1787      \rm out_rsync
1788      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1789    else
1790      \rm out_rsync
1791      break
1792    fi
1793    (( i = i + 1 ))
1794  done
1795
1796  if [ ${status} -gt 0 ] ; then
1797      echo "IGCM_sys_ncatted : ncatted error"
1798      IGCM_debug_Exit "ncatted"
1799  fi
1800
1801  IGCM_debug_PopStack "IGCM_sys_ncatted"
1802}
1803
1804function IGCM_sys_ncbo {
1805  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1806  if ( $DEBUG_sys ) ; then
1807    echo "IGCM_sys_ncbo :" $@
1808  fi
1809
1810  typeset NB_ESSAI DELAI status i
1811  # number of tentative
1812  NB_ESSAI=3
1813  # time delay between tentative
1814  DELAI=2
1815
1816  i=0
1817  while [ $i -lt $NB_ESSAI ] ; do
1818    ncbo $@ > out_rsync 2>&1
1819    status=$?
1820    if [ ${status} -gt 0 ] ; then
1821      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1822      cat out_rsync
1823      \rm out_rsync
1824      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1825    else
1826      \rm out_rsync
1827      break
1828    fi
1829    (( i = i + 1 ))
1830  done
1831
1832  if [ ${status} -gt 0 ] ; then
1833      echo "IGCM_sys_ncbo : ncbo error"
1834      IGCM_debug_Exit "ncbo"
1835  fi
1836
1837  IGCM_debug_PopStack "IGCM_sys_ncbo"
1838}
1839
1840function IGCM_sys_ncdiff {
1841  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1842  if ( $DEBUG_sys ) ; then
1843    echo "IGCM_sys_ncdiff :" $@
1844  fi
1845
1846  typeset NB_ESSAI DELAI status i
1847  # number of tentative
1848  NB_ESSAI=3
1849  # time delay between tentative
1850  DELAI=2
1851
1852  i=0
1853  while [ $i -lt $NB_ESSAI ] ; do
1854    ncdiff $@ > out_rsync 2>&1
1855    status=$?
1856    if [ ${status} -gt 0 ] ; then
1857      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1858      cat out_rsync
1859      \rm out_rsync
1860      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1861    else
1862      \rm out_rsync
1863      break
1864    fi
1865    (( i = i + 1 ))
1866  done
1867
1868  if [ ${status} -gt 0 ] ; then
1869      echo "IGCM_sys_ncdiff : ncdiff error"
1870      IGCM_debug_Exit "ncdiff"
1871  fi
1872
1873  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1874}
1875
1876function IGCM_sys_ncea {
1877  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1878  if ( $DEBUG_sys ) ; then
1879    echo "IGCM_sys_ncea :" $@
1880  fi
1881
1882  typeset NB_ESSAI DELAI status i
1883  # number of tentative
1884  NB_ESSAI=3
1885  # time delay between tentative
1886  DELAI=2
1887
1888  i=0
1889  while [ $i -lt $NB_ESSAI ] ; do
1890    ncea $@ > out_rsync 2>&1
1891    status=$?
1892    if [ ${status} -gt 0 ] ; then
1893      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1894      cat out_rsync
1895      \rm out_rsync
1896      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1897    else
1898      \rm out_rsync
1899      break
1900    fi
1901    (( i = i + 1 ))
1902  done
1903
1904  if [ ${status} -gt 0 ] ; then
1905      echo "IGCM_sys_ncea : ncea error"
1906      IGCM_debug_Exit "ncea"
1907  fi
1908
1909  IGCM_debug_PopStack "IGCM_sys_ncea"
1910}
1911
1912function IGCM_sys_ncecat {
1913  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1914  if ( $DEBUG_sys ) ; then
1915    echo "IGCM_sys_ncecat :" $@
1916  fi
1917
1918  typeset NB_ESSAI DELAI status i
1919  # number of tentative
1920  NB_ESSAI=3
1921  # time delay between tentative
1922  DELAI=2
1923
1924  i=0
1925  while [ $i -lt $NB_ESSAI ] ; do
1926    ncecat $@ > out_rsync 2>&1
1927    status=$?
1928    if [ ${status} -gt 0 ] ; then
1929      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1930      cat out_rsync
1931      \rm out_rsync
1932      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
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_ncecat : ncecat error"
1942      IGCM_debug_Exit "ncecat"
1943  fi
1944
1945  IGCM_debug_PopStack "IGCM_sys_ncecat"
1946}
1947
1948function IGCM_sys_ncflint {
1949  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1950  if ( $DEBUG_sys ) ; then
1951    echo "IGCM_sys_ncflint :" $@
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    ncflint $@ > out_rsync 2>&1
1963    status=$?
1964    if [ ${status} -gt 0 ] ; then
1965      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1966      cat out_rsync
1967      \rm out_rsync
1968      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1969    else
1970      \rm out_rsync
1971      break
1972    fi
1973    (( i = i + 1 ))
1974  done
1975
1976  if [ ${status} -gt 0 ] ; then
1977      echo "IGCM_sys_ncflint : ncflint error"
1978      IGCM_debug_Exit "ncflint"
1979  fi
1980
1981  IGCM_debug_PopStack "IGCM_sys_ncflint"
1982}
1983
1984function IGCM_sys_ncks {
1985  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1986  if ( $DEBUG_sys ) ; then
1987    echo "IGCM_sys_ncks :" $@
1988  fi
1989
1990  typeset NB_ESSAI DELAI status i
1991  # number of tentative
1992  NB_ESSAI=3
1993  # time delay between tentative
1994  DELAI=2
1995
1996  i=0
1997  while [ $i -lt $NB_ESSAI ] ; do
1998    ncks $@ > out_rsync 2>&1
1999    status=$?
2000    if [ ${status} -gt 0 ] ; then
2001      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2002      cat out_rsync
2003      \rm out_rsync
2004      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2005    else
2006      \rm out_rsync
2007      break
2008    fi
2009    (( i = i + 1 ))
2010  done
2011
2012  if [ ${status} -gt 0 ] ; then
2013      echo "IGCM_sys_ncks : ncks error"
2014      IGCM_debug_Exit "ncks"
2015  fi
2016
2017  IGCM_debug_PopStack "IGCM_sys_ncks"
2018}
2019
2020function IGCM_sys_ncpdq {
2021  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2022  if ( $DEBUG_sys ) ; then
2023    echo "IGCM_sys_ncpdq :" $@
2024  fi
2025
2026  typeset NB_ESSAI DELAI status i
2027  # number of tentative
2028  NB_ESSAI=3
2029  # time delay between tentative
2030  DELAI=2
2031
2032  i=0
2033  while [ $i -lt $NB_ESSAI ] ; do
2034    ncpdq $@ > out_rsync 2>&1
2035    status=$?
2036    if [ ${status} -gt 0 ] ; then
2037      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2038      cat out_rsync
2039      \rm out_rsync
2040      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2041    else
2042      \rm out_rsync
2043      break
2044    fi
2045    (( i = i + 1 ))
2046  done
2047
2048  if [ ${status} -gt 0 ] ; then
2049      echo "IGCM_sys_ncpdq : ncpdq error"
2050      IGCM_debug_Exit "ncpdq"
2051  fi
2052
2053  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2054}
2055
2056function IGCM_sys_ncra {
2057  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2058  if ( $DEBUG_sys ) ; then
2059    echo "IGCM_sys_ncra :" $@
2060  fi
2061
2062  typeset NB_ESSAI DELAI status i
2063  # number of tentative
2064  NB_ESSAI=3
2065  # time delay between tentative
2066  DELAI=2
2067
2068  i=0
2069  while [ $i -lt $NB_ESSAI ] ; do
2070    ncra $@ > out_rsync 2>&1
2071    status=$?
2072    if [ ${status} -gt 0 ] ; then
2073      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2074      cat out_rsync
2075      \rm out_rsync
2076      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2077    else
2078      \rm out_rsync
2079      break
2080    fi
2081    (( i = i + 1 ))
2082  done
2083
2084  if [ ${status} -gt 0 ] ; then
2085      echo "IGCM_sys_ncra : ncra error"
2086      IGCM_debug_Exit "ncra"
2087  fi
2088
2089  IGCM_debug_PopStack "IGCM_sys_ncra"
2090}
2091
2092function IGCM_sys_ncrcat {
2093  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2094  if ( $DEBUG_sys ) ; then
2095    echo "IGCM_sys_ncrcat :" $@
2096  fi
2097
2098  typeset NB_ESSAI DELAI status i
2099  # number of tentative
2100  NB_ESSAI=3
2101  # time delay between tentative
2102  DELAI=2
2103
2104  i=0
2105  while [ $i -lt $NB_ESSAI ] ; do
2106    ncrcat $@ > out_rsync 2>&1
2107    status=$?
2108    if [ ${status} -gt 0 ] ; then
2109      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2110      cat out_rsync
2111      \rm out_rsync
2112      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2113    else
2114      \rm out_rsync
2115      break
2116    fi
2117    (( i = i + 1 ))
2118  done
2119
2120  if [ ${status} -gt 0 ] ; then
2121      echo "IGCM_sys_ncrcat : ncrcat error"
2122      #IGCM_debug_Exit "ncrcat"
2123  fi
2124
2125  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2126}
2127
2128function IGCM_sys_ncrename {
2129  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2130  if ( $DEBUG_sys ) ; then
2131    echo "IGCM_sys_ncrename :" $@
2132  fi
2133
2134  typeset NB_ESSAI DELAI status i
2135  # number of tentative
2136  NB_ESSAI=3
2137  # time delay between tentative
2138  DELAI=2
2139
2140  i=0
2141  while [ $i -lt $NB_ESSAI ] ; do
2142    ncrename $@ > out_rsync 2>&1
2143    status=$?
2144    if [ ${status} -gt 0 ] ; then
2145      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2146      cat out_rsync
2147      \rm out_rsync
2148      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2149    else
2150      \rm out_rsync
2151      break
2152    fi
2153    (( i = i + 1 ))
2154  done
2155
2156  if [ ${status} -gt 0 ] ; then
2157      echo "IGCM_sys_ncrename : ncrename error"
2158      IGCM_debug_Exit "ncrename"
2159  fi
2160
2161  IGCM_debug_PopStack "IGCM_sys_ncrename"
2162}
2163
2164function IGCM_sys_ncwa {
2165  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2166  if ( $DEBUG_sys ) ; then
2167    echo "IGCM_sys_ncwa :" $@
2168  fi
2169
2170  typeset NB_ESSAI DELAI status i
2171  # number of tentative
2172  NB_ESSAI=3
2173  # time delay between tentative
2174  DELAI=2
2175
2176  i=0
2177  while [ $i -lt $NB_ESSAI ] ; do
2178    ncwa $@ > out_rsync 2>&1
2179    status=$?
2180    if [ ${status} -gt 0 ] ; then
2181      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2182      cat out_rsync
2183      \rm out_rsync
2184      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2185    else
2186      \rm out_rsync
2187      break
2188    fi
2189    (( i = i + 1 ))
2190  done
2191
2192  if [ ${status} -gt 0 ] ; then
2193      echo "IGCM_sys_ncwa : ncwa error"
2194      IGCM_debug_Exit "ncwa"
2195  fi
2196
2197  IGCM_debug_PopStack "IGCM_sys_ncwa"
2198}
2199
2200##############################################################
2201# CDO OPERATOR
2202
2203function IGCM_sys_cdo {
2204  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2205  if ( $DEBUG_sys ) ; then
2206    echo "IGCM_sys_cdo :" $@
2207  fi
2208
2209  typeset status
2210
2211  \cdo $@ > out_rsync 2>&1
2212  status=$?
2213  if [ ${status} -gt 0 ] ; then
2214    echo "IGCM_sys_cdo : error code ${status}"
2215    cat out_rsync
2216    \rm out_rsync
2217    IGCM_debug_PopStack "IGCM_sys_cdo"
2218    return 1
2219  else
2220    IGCM_debug_PopStack "IGCM_sys_cdo"
2221    return 0
2222  fi
2223
2224  IGCM_debug_PopStack "IGCM_sys_cdo"
2225}
2226
2227############################################################
2228# Activate Running Environnment Variables
2229
2230function IGCM_sys_activ_variables {
2231  IGCM_debug_PushStack "IGCM_sys_activ_variables"
2232  if ( $DEBUG_sys ) ; then
2233    echo "IGCM_sys_activ_variables"
2234  fi
2235  IGCM_debug_PopStack "IGCM_sys_activ_variables"
2236}
2237
2238############################################################
2239# Desactivate Running Environnment Variables
2240
2241function IGCM_sys_desactiv_variables {
2242  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
2243  if ( $DEBUG_sys ) ; then
2244    echo "IGCM_sys_desactiv_variables"
2245  fi
2246  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
2247}
2248
2249############################################################
2250# Build run file
2251
2252function IGCM_sys_build_run_file {
2253  IGCM_debug_PushStack "IGCM_sys_build_run_file"
2254  if ( $DEBUG_sys ) ; then
2255    echo "IGCM_sys_build_run_file"
2256  fi
2257  IGCM_debug_PopStack "IGCM_sys_build_run_file"
2258}
Note: See TracBrowser for help on using the repository browser.