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

Last change on this file since 637 was 618, checked in by sdipsl, 12 years ago
  • Bugfix in IGCM_sys_IsFileArchived
  • Property svn:keywords set to Revision Author Date
File size: 45.3 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for Mercure X64
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69
70#D-
71#D-#==================================================
72#D-Program used in libIGCM
73#D-#==================================================
74
75# 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:=/dmnfs/cont003/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#D-#==================================================
144#D-function IGCM_sys_RshMaster
145#D-* Purpose: Just a fake command to wrapp
146#D-           IGCM_card call in post-treatment
147#D-           Ulam do not see brodie filesystem
148#D-           Cesium do not see all mercure filesystem
149#D-           That's why we need this hack.
150#D-* Examples:
151#D-
152function IGCM_sys_RshMaster {
153  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
154  /bin/ksh <<-EOF
155    export libIGCM=${libIGCM}
156    export DEBUG_debug=${DEBUG_debug}
157    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
158    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
159    ${@}
160EOF
161  if [ $? -gt 0 ] ; then
162    echo "IGCM_sys_RshMaster : erreur."
163    IGCM_debug_Exit "IGCM_sys_RshMaster"
164  fi
165  IGCM_debug_PopStack "IGCM_sys_RshMaster"
166}
167
168#D-#==================================================
169#D-function IGCM_sys_RshArchive
170#D-* Purpose: Archive rsh command
171#D-* Examples:
172#D-
173function IGCM_sys_RshArchive {
174  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
175  /bin/ksh <<-EOF
176    ${@}
177EOF
178  if [ $? -gt 0 ] ; then
179    echo "IGCM_sys_RshArchive : erreur."
180    IGCM_debug_Exit "IGCM_sys_RshArchive"
181  fi
182  IGCM_debug_PopStack "IGCM_sys_RshArchive"
183}
184
185#D-#==================================================
186#D-function IGCM_sys_RshPost
187#D-* Purpose: Post-process rsh command
188#D-* Examples:
189#D-
190function IGCM_sys_RshPost {
191  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
192  if ( $DEBUG_sys ) ; then
193    echo "IGCM_sys_RshPost :" $@
194  fi
195  /bin/ksh ${@}
196  if [ $? -gt 0 ] ; then
197    echo "IGCM_sys_RshPost : erreur."
198    IGCM_debug_Exit "IGCM_sys_RshPost"
199  fi
200  IGCM_debug_PopStack "IGCM_sys_RshPost"
201}
202
203#D-#==================================================
204#D-function IGCM_sys_SendMail
205#D-* Purpose: Send mail when simulation is over
206#D-* Examples:
207#D-
208function IGCM_sys_SendMail {
209  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
210  if ( $DEBUG_sys ) ; then
211    echo "IGCM_sys_SendMail :" $@
212  fi
213
214  if ( ${ExitFlag} ) ; then
215    status=failed
216  else
217    status=completed
218  fi
219  cat  << END_MAIL > job_end.mail
220Dear ${LOGIN},
221
222  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
223  Job started : ${DateBegin}
224  Job ended   : ${DateEnd}
225  Output files are available in ${R_SAVE}
226  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
227END_MAIL
228
229  if  [ X"${config_UserChoices_MailName}" != X ] ; then
230    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
231  elif [ -f ~/.forward ] ; then
232    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
233  else
234    mailx -s "${config_UserChoices_JobName} ${status}" ${LOGIN} < job_end.mail
235  fi
236
237  if [ $? -gt 0 ] ; then
238    echo "IGCM_sys_SendMail : erreur."
239    IGCM_debug_Exit "IGCM_sys_SendMail"
240  fi
241  IGCM_debug_PopStack "IGCM_sys_SendMail"
242}
243
244#D-#==================================================
245#D-function IGCM_sys_Mkdir
246#D-* Purpose: Master locale mkdir command
247#D-* Examples:
248#D-
249function IGCM_sys_Mkdir {
250  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
251  if ( $DEBUG_sys ) ; then
252    echo "IGCM_sys_Mkdir :" $@
253  fi
254  if [ ! -d ${1} ]; then
255    \mkdir -p $1
256    if [ $? -gt 0 ] ; then
257      echo "IGCM_sys_Mkdir : erreur."
258      IGCM_debug_Exit "IGCM_sys_Mkdir"
259    fi
260  fi
261  # vérification :
262  if [ ! -d ${1} ] ; then
263    echo "IGCM_sys_Mkdir : erreur."
264    IGCM_debug_Exit "IGCM_sys_Mkdir"
265  fi
266  IGCM_debug_PopStack "IGCM_sys_Mkdir"
267}
268
269#D-#==================================================
270#D-function IGCM_sys_MkdirArchive
271#D-* Purpose: Mkdir on Archive
272#D-* Examples:
273#D-
274function IGCM_sys_MkdirArchive {
275  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
276  if ( $DEBUG_sys ) ; then
277    echo "IGCM_sys_MkdirArchive :" $@
278  fi
279  #- creation de repertoire sur le serveur fichier
280  if [ ! -d ${1} ]; then 
281    \mkdir -p $1
282    if [ $? -gt 0 ] ; then
283      echo "IGCM_sys_MkdirArchive : erreur."
284      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
285    fi
286  fi
287  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
288}
289
290#D-#==================================================
291#D-function IGCM_sys_MkdirWork
292#D-* Purpose: Mkdir on Work
293#D-* Examples:
294#D-
295function IGCM_sys_MkdirWork {
296  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
297  if ( $DEBUG_sys ) ; then
298    echo "IGCM_sys_MkdirWork :" $@
299  fi
300  #- creation de repertoire sur le serveur fichier
301  if [ ! -d ${1} ]; then 
302    \mkdir -p $1
303    if [ $? -gt 0 ] ; then
304      echo "IGCM_sys_MkdirWork : erreur."
305      IGCM_debug_Exit "IGCM_sys_MkdirWork"
306    fi
307  fi
308  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
309}
310
311#D-#==================================================
312#D-function IGCM_sys_Cd
313#D-* Purpose: master cd command
314#D-* Examples:
315#D-
316function IGCM_sys_Cd {
317  IGCM_debug_PushStack "IGCM_sys_Cd" $@
318  if ( $DEBUG_sys ) ; then
319    echo "IGCM_sys_Cd :" $@
320  fi
321  \cd $1
322  if [ $? -gt 0 ] ; then
323    echo "IGCM_sys_Cd : erreur."
324    IGCM_debug_Exit "IGCM_sys_Cd"
325  fi
326  IGCM_debug_PopStack "IGCM_sys_Cd"
327}
328
329#D-#==================================================
330#D-function IGCM_sys_Chmod
331#D-* Purpose: Chmod
332#D-* Examples:
333#D-
334function IGCM_sys_Chmod {
335  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
336  if ( $DEBUG_sys ) ; then
337    echo "IGCM_sys_Chmod :" $@
338  fi
339  if [ $DRYRUN -le 1 ]; then
340    \chmod $@
341    if [ $? -gt 0 ] ; then
342      echo "IGCM_sys_Chmod : erreur."
343      IGCM_debug_Exit "IGCM_sys_Chmod"
344    fi
345  else
346    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
347  fi
348  IGCM_debug_PopStack "IGCM_sys_Chmod"
349}
350
351#D-#==================================================
352#D-function IGCM_sys_FileSize
353#D-* Purpose: Filesize
354#D-* Examples:
355#D-
356function IGCM_sys_FileSize {
357  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
358
359  typeset sizeF
360  set +A sizeF -- $( ls -la ${1} )
361  if [ $? -gt 0 ] ; then
362    IGCM_debug_Exit "IGCM_sys_FileSize"
363  fi
364  eval ${2}=${sizeF[4]}
365
366  IGCM_debug_PopStack "IGCM_sys_FileSize"
367}
368
369#D-#==================================================
370#D-function IGCM_sys_TestDir
371#D-* Purpose: Test Directory that must exists
372#D-* Examples:
373#D-
374function IGCM_sys_TestDir {
375  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
376  if ( $DEBUG_sys ) ; then
377    echo "IGCM_sys_TestDir :" $@
378  fi
379  typeset ExistFlag
380  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
381  IGCM_debug_PopStack "IGCM_sys_TestDir"
382
383  return ${ExistFlag}
384}
385
386#D-#==================================================
387#D-function IGCM_sys_TestDirArchive
388#D-* Purpose: Test Directory that must exists on Archive
389#D-* Examples:
390#D-
391function IGCM_sys_TestDirArchive {
392  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
393  if ( $DEBUG_sys ) ; then
394    echo "IGCM_sys_TestDirArchive :" $@
395  fi
396  typeset ExistFlag
397  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
398  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
399
400  return ${ExistFlag}
401}
402
403#D-#==================================================
404#D-function IGCM_sys_IsFileArchived
405#D-* Purpose: Test file that must NOT EXISTS on Archive
406#D-* Examples:
407#D-
408function IGCM_sys_IsFileArchived {
409  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
410  if ( $DEBUG_sys ) ; then
411    echo "IGCM_sys_IsFileArchived :" $@
412  fi
413  typeset IsArchivedFlag
414  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
415  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
416
417  return ${IsArchivedFlag}
418}
419
420#D-#==================================================
421#D-function IGCM_sys_TestFileArchive
422#D-* Purpose: Test file that must NOT EXISTS on Archive
423#D-* Examples:
424#D-
425function IGCM_sys_TestFileArchive {
426  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
427  if ( $DEBUG_sys ) ; then
428    echo "IGCM_sys_TestFileArchive :" $@
429  fi
430  typeset ExistFlag
431  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
432  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
433
434  return ${ExistFlag}
435}
436
437#D-#==================================================
438#D-function IGCM_sys_TestFileBuffer
439#D-* Purpose: Test file that must NOT EXISTS on Buffer
440#D-* Examples:
441#D-
442function IGCM_sys_TestFileBuffer {
443  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
444  typeset ExistFlag
445  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
446  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
447
448  return ${ExistFlag}
449}
450
451#D-#==================================================
452#D-function IGCM_sys_CountFileArchive
453#D-* Purpose: Count files on Archive filesystem
454#D-* Examples:
455#D-
456function IGCM_sys_CountFileArchive {
457  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
458  ls ${@} 2>/dev/null | wc -l
459  if [ $? -gt 0 ] ; then
460    echo "IGCM_sys_CountFileArchive : erreur."
461  fi
462  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
463}
464
465#D-#==================================================
466#D-function IGCM_sys_CountFileBuffer
467#D-* Purpose: Count files on Scratch filesystem
468#D-* Examples:
469#D-
470function IGCM_sys_CountFileBuffer {
471  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
472  ls ${@} 2>/dev/null | wc -l
473  if [ $? -gt 0 ] ; then
474    echo "IGCM_sys_CountFileBuffer : erreur."
475  fi
476  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
477}
478
479#D-#==================================================
480#D-function IGCM_sys_Tree
481#D-* Purpose: Tree directories with files on ${ARCHIVE}
482#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
483#D-
484function IGCM_sys_Tree {
485  IGCM_debug_PushStack "IGCM_sys_Tree" $@
486  if ( $DEBUG_sys ) ; then
487    echo "IGCM_sys_Tree :" $@
488  fi
489
490  \tree -f $@
491
492  IGCM_debug_PopStack "IGCM_sys_Tree"
493}
494
495#D-#==================================================
496#D-function IGCM_sys_Tar
497#D-* Purpose: master tar command
498#D-* Examples:
499#D-
500function IGCM_sys_Tar {
501  IGCM_debug_PushStack "IGCM_sys_Tar" $@
502  if ( $DEBUG_sys ) ; then
503    echo "IGCM_sys_Tar :" $@
504  fi
505  \tar cf $@
506  if [ $? -gt 0 ] ; then
507    echo "IGCM_sys_Tar : erreur."
508    IGCM_debug_Exit "IGCM_sys_Tar"
509  fi
510  IGCM_debug_PopStack "IGCM_sys_Tar"
511}
512
513#D-#==================================================
514#D-function IGCM_sys_UnTar
515#D-* Purpose: master un-tar command
516#D-* Examples:
517#D-
518function IGCM_sys_UnTar {
519  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
520  if ( $DEBUG_sys ) ; then
521    echo "IGCM_sys_UnTar :" $@
522  fi
523  \tar xvf $1
524  if [ $? -gt 0 ] ; then
525    echo "IGCM_sys_UnTar : erreur."
526    IGCM_debug_Exit "IGCM_sys_UnTar"
527  fi
528  IGCM_debug_PopStack "IGCM_sys_UnTar"
529}
530
531#D-#==================================================
532#D-function IGCM_sys_QsubPost
533#D-* Purpose: Qsub new job on scalaire
534#D-* Examples:
535#D-
536function IGCM_sys_QsubPost {
537  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
538  if ( $DEBUG_sys ) ; then
539    echo "IGCM_sys_QsubPost :" $@
540  fi
541  /usr/bin/nqsII/qsub -q scalaire -o ${POST_DIR}/${Script_Post_Output}.out ${libIGCM}/$1.job -v ${listVarEnv}
542  if [ $? -gt 0 ] ; then
543    echo "IGCM_sys_QsubPost : erreur " $@
544    IGCM_debug_Exit "IGCM_sys_QsubPost"
545  fi
546  IGCM_debug_PopStack "IGCM_sys_QsubPost"
547}
548
549#D-*************************
550#D- File transfer functions
551#D-*************************
552#D-
553
554#D-#==================================================
555#D-function IGCM_sys_Rsync_out
556#D-* Purpose: treat return val of rsync
557#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
558#D-  Error values and explanations can depend on your system version.
559function IGCM_sys_Rsync_out {
560  RET=$1
561  if [ ! $RET ] ; then
562    echo "rsync error !"
563  fi
564
565  if [ $MYLANG = "fr" ]; then
566    case $RET in
567    0)  return ;;
568    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
569      echo "Erreur de syntaxe ou d'utilisation."
570      return;;
571    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
572      echo "Incompatibilité de protocole."
573      return;;
574    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
575      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
576      echo "répertoires"
577      return;;
578    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
579      echo "Action demandée non supportée : une tentative de manipulation de"
580      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
581      echo "été faite ; ou une option qui est supportée par le  client  mais"
582      echo "pas par le serveur a été spécifiée."
583      return;;
584    10) echo "Erreur de rsync ; RERR_SOCKETIO"
585      echo "Erreur dans le socket d'entrée sortie"
586      return;;
587    11) echo "Erreur de rsync ; RERR_FILEIO"
588      echo "Erreur d'entrée sortie fichier"
589      return;;
590    12) echo "Erreur de rsync ; RERR_STREAMIO"
591      echo "Erreur dans flux de donnée du protocole rsync"
592      return;;
593    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
594      echo "Erreur avec les diagnostics du programme"
595      return;;
596    14) echo "Erreur de rsync ; RERR_IPC"
597      echo "Erreur dans le code IPC"
598      return;;
599    20) echo "Erreur de rsync ; RERR_SIGNAL"
600      echo "SIGUSR1 ou SIGINT reçu"
601      return;;
602    21) echo "Erreur de rsync ; RERR_WAITCHILD"
603      echo "Une erreur retournée par waitpid()"
604      return;;
605    22) echo "Erreur de rsync ; RERR_MALLOC"
606      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
607      return;;
608    23) echo ""
609      echo "Erreur fichier inexistant"
610      return;;
611    30) echo "Erreur de rsync ; RERR_TIMEOUT"
612      echo "Temps d'attente écoulé dans l'envoi/réception de données"
613      return;;
614    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
615      return;;
616    esac
617  elif [ $MYLANG = "en" ] ; then
618    case $RET in
619    0)  return;;               
620    1)  echo "rsync error : Syntax or usage error "
621      return;;
622    2)  echo "rsync error : Protocol incompatibility "
623      return;;
624    3)  echo "rsync error : Errors selecting input/output files, dirs"
625      return;;
626    4)  echo "rsync error : Requested action not supported: an attempt"
627      echo "was made to manipulate 64-bit files on a platform that cannot support"
628      echo "them; or an option was specified that is supported by the client and"
629      echo "not by the server."
630      return;;
631    5)  echo "rsync error : Error starting client-server protocol"
632      return;;
633    10) echo "rsync error : Error in socket I/O "
634      return;;
635    11) echo "rsync error : Error in file I/O "
636      return;;
637    12) echo "rsync error : Error in rsync protocol data stream "
638      return;;
639    13) echo "rsync error : Errors with program diagnostics "
640      return;;
641    14) echo "rsync error : Error in IPC code "
642      return;;
643    20) echo "rsync error : Received SIGUSR1 or SIGINT "
644      return;;
645    21) echo "rsync error : Some error returned by waitpid() "
646      return;;
647    22) echo "rsync error : Error allocating core memory buffers "
648      return;;
649    23) echo "rsync error : Partial transfer due to error"
650      return;;
651    24) echo "rsync error : Partial transfer due to vanished source files"
652      return;;
653    30) echo "rsync error : Timeout in data send/receive "
654      return;;
655    *)  echo "rsync error : return code of rsync unknown :" $RET
656      return;;
657    esac
658  else
659    echo "unknown language $MYLANG."
660    return
661  fi
662}
663
664#D-#==================================================
665#D-function IGCM_sys_Cp
666#D-* Purpose: generic cp
667#D-* Examples:
668#D-
669function IGCM_sys_Cp {
670  IGCM_debug_PushStack "IGCM_sys_Cp" $@
671  if ( $DEBUG_sys ) ; then
672    echo "IGCM_sys_Cp :" $@
673  fi
674
675  typeset RET
676
677  echo cp $@ > out_rsync 2>&1
678  \cp $@ >> out_rsync 2>&1
679  RET=$?
680
681  if [ ${RET} -gt 0 ] ; then
682    echo "IGCM_sys_Cp : error."
683    cat out_rsync
684    IGCM_debug_Exit "IGCM_sys_Cp"
685  else
686    \rm out_rsync
687  fi
688  IGCM_debug_PopStack "IGCM_sys_Cp"
689}
690
691#D-#==================================================
692#D-function IGCM_sys_Rm
693#D-* Purpose: generic rm
694#D-* Examples:
695#D-
696function IGCM_sys_Rm {
697  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
698  if ( $DEBUG_sys ) ; then
699    echo "IGCM_sys_Rm :" $@
700  fi
701
702  typeset RET
703
704  echo rm $@ > out_rsync 2>&1
705  \rm $@ >> out_rsync 2>&1
706  RET=$?
707
708  if [ ${RET} -gt 0 ] ; then
709    echo "IGCM_sys_Rm : error."
710    cat out_rsync
711    IGCM_debug_Exit "IGCM_sys_Rm"
712  else
713    \rm out_rsync
714  fi
715  IGCM_debug_PopStack "IGCM_sys_Rm"
716}
717
718#D-#==================================================
719#D-function IGCM_sys_RmRunDir
720#D-* Purpose: rm tmpdir (dummy function most of the time batch
721#D-                      scheduler will do the job)
722#D-           Dummy function on mercure front-end
723#D-* Examples:
724#D-
725function IGCM_sys_RmRunDir {
726    IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
727    if ( $DEBUG_sys ) ; then
728        echo "IGCM_sys_RmRunDir :" $@
729        echo "Dummy call, let the scheduler do that."
730    fi
731    IGCM_debug_PopStack "IGCM_sys_RmRunDir"
732}
733
734#D-#==================================================
735#D-function IGCM_sys_Mv
736#D-* Purpose: generic move
737#D-* Examples:
738#D-
739function IGCM_sys_Mv {
740  IGCM_debug_PushStack "IGCM_sys_Mv" $@
741  if ( $DEBUG_sys ) ; then
742    echo "IGCM_sys_Mv :" $@
743  fi
744
745  if [ $DRYRUN = 0 ]; then
746
747    typeset RET
748   
749    echo mv $@ > out_rsync 2>&1
750    \mv $@ >> out_rsync 2>&1
751    RET=$?
752   
753    if [ ${RET} -gt 0 ] ; then
754      echo "IGCM_sys_Mv : error in mv."
755      cat out_rsync
756      IGCM_debug_Exit "IGCM_sys_Mv"
757    else
758      \rm out_rsync
759    fi
760  else
761    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
762  fi
763
764  IGCM_debug_PopStack "IGCM_sys_Mv"
765}
766
767#D-#==================================================
768#D-function IGCM_sys_Put_Dir
769#D-* Purpose: Copy a complete directory on $(ARCHIVE)
770#D-* Examples:
771#D-
772function IGCM_sys_Put_Dir {
773  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
774  if ( $DEBUG_sys ) ; then
775    echo "IGCM_sys_Put_Dir :" $@
776  fi
777  if [ $DRYRUN = 0 ]; then
778    if [ ! -d ${1} ] ; then
779      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
780      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
781      return
782    fi
783
784    typeset RET
785
786    # Only if we use rsync
787    #IGCM_sys_TestDirArchive $( dirname $2 )
788    #
789    #USUAL WAY
790    \cp -r $1 $2 > out_rsync 2>&1
791    RET=$?
792
793    if [ ${RET} -gt 0 ] ; then
794      echo "IGCM_sys_Put_Dir : error."
795      cat out_rsync
796      IGCM_debug_Exit "IGCM_sys_Put_Dir"
797    else
798      \rm out_rsync
799    fi
800  else
801    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
802  fi
803  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
804}
805
806#D-#==================================================
807#D-function IGCM_sys_Get_Dir
808#D-* Purpose: Copy a complete directory from $(ARCHIVE)
809#D-* Examples:
810#D-
811function IGCM_sys_Get_Dir {
812  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
813  if ( $DEBUG_sys ) ; then
814    echo "IGCM_sys_Get_Dir :" $@
815  fi
816  if [ $DRYRUN = 0 ]; then
817#       if [ ! -d ${1} ] ; then
818#           echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
819#           IGCM_debug_PopStack "IGCM_sys_Get_Dir"
820#           return
821#       fi
822
823    typeset RET
824
825    # Only if we use rsync
826    #IGCM_sys_TestDirArchive $( dirname $2 )
827    #
828    #USUAL WAY
829    # add dmget (to demigrate all offline files) to reduce time of this command :
830    #dmget $1/*
831    ccc_hsm get $1/*
832    \cp -r $1 $2 > out_rsync 2>&1
833    RET=$?
834
835    if [ ${RET} -gt 0 ] ; then
836      echo "IGCM_sys_Get_Dir : error."
837      cat out_rsync
838      IGCM_debug_Exit "IGCM_sys_Get_Dir"
839    else
840      \rm out_rsync
841    fi
842  else
843    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
844  fi
845  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
846}
847
848#D-#==================================================
849#D-function IGCM_sys_Get_Master
850#D-* Purpose: Copy a complete directory from MASTER filesystem
851#D-* Examples:
852#D-
853function IGCM_sys_Get_Master {
854  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
855  if ( $DEBUG_sys ) ; then
856    echo "IGCM_sys_Get_Master :" $@
857  fi
858  if [ $DRYRUN = 0 ]; then
859    if [ ! -d ${1} ] ; then
860      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
861      IGCM_debug_PopStack "IGCM_sys_Get_Master"
862      return
863    fi
864
865    typeset RET
866
867    #USUAL WAY
868    \cp -r $1 $2 > out_rsync 2>&1
869    RET=$?
870
871    if [ ${RET} -gt 0 ] ; then
872      echo "IGCM_sys_Get_Master : error."
873      cat out_rsync
874      IGCM_debug_Exit "IGCM_sys_Get_Master"
875    else
876      \rm out_rsync
877    fi
878  else
879    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
880  fi
881  IGCM_debug_PopStack "IGCM_sys_Get_Master"
882}
883
884#D-#==================================================
885#D-function IGCM_sys_Put_Rest
886#D-* Purpose: Put computied restarts on ${ARCHIVE}.
887#D-           File and target directory must exist.
888#D-* Examples:
889#D-
890function IGCM_sys_Put_Rest {
891  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
892  if ( $DEBUG_sys ) ; then
893    echo "IGCM_sys_Put_Rest :" $@
894  fi
895  if [ $DRYRUN = 0 ]; then
896    if [ ! -f ${1} ] ; then
897      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
898      IGCM_debug_Exit "IGCM_sys_Put_Rest"
899    fi
900
901    typeset RET
902    #
903    if [ X${JobType} = XRUN ] ; then
904      IGCM_sys_Chmod 444 ${1}
905    fi
906
907    #
908    # USUAL WAY
909    \cp $1 $2 > out_rsync 2>&1
910    RET=$?
911
912#       #RSYNC WITH NETWORK SSH CALL
913#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
914#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
915
916#       #RSYNC WITH NFS USE
917#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
918#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
919
920#       RET=$?
921#       IGCM_sys_Rsync_out $RET
922
923#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
924#       (( RET=RET+$? ))
925
926    if [ ${RET} -gt 0 ] ; then
927      echo "IGCM_sys_Put_Rest : error."
928      cat out_rsync
929      IGCM_debug_Exit "IGCM_sys_Put_Rest"
930    else
931      \rm out_rsync
932    fi
933  else
934    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
935  fi
936  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
937}
938
939#D-#==================================================
940#D-function IGCM_sys_PutBuffer_Rest
941#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
942#D-           File and target directory must exist.
943#D-* Examples:
944#D-
945function IGCM_sys_PutBuffer_Rest {
946  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
947  if ( $DEBUG_sys ) ; then
948    echo "IGCM_sys_PutBuffer_Rest :" $@
949  fi
950  if [ $DRYRUN = 0 ]; then
951    if [ ! -f ${1} ] ; then
952      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
953      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
954    fi
955
956    typeset RET
957    #
958    if [ X${JobType} = XRUN ] ; then
959      IGCM_sys_Chmod 444 ${1}
960    fi
961
962    #
963    # USUAL WAY
964    \cp $1 $2 > out_rsync 2>&1
965    RET=$?
966
967    if [ ${RET} -gt 0 ] ; then
968      echo "IGCM_sys_PutBuffer_Rest : error."
969      cat out_rsync
970      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
971    else
972      \rm out_rsync
973    fi
974  else
975    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
976  fi
977  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
978}
979
980#D-#==================================================
981#D-function IGCM_sys_Put_Out
982#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
983#D-* Examples:
984#D-
985function IGCM_sys_Put_Out {
986  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
987  if ( $DEBUG_sys ) ; then
988    echo "IGCM_sys_Put_Out :" $@
989  fi
990  if [ $DRYRUN = 0 ]; then
991    if [ ! -f ${1} ] ; then
992      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
993      IGCM_debug_PopStack "IGCM_sys_Put_Out"
994      return 1
995    fi
996    #
997    IGCM_sys_MkdirArchive $( dirname $2 )
998    #
999    typeset RET exist skip
1000
1001    #=====================================================
1002    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1003    #=====================================================
1004
1005    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1006    #if [ $? -eq 0 ] ; then
1007    #    typeset WORKPATH FILEPATH
1008    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1009    #    IGCM_sys_MkdirWork ${WORKPATH}
1010    #    FILEPATH=${WORKPATH}/$( basename $2 )
1011    #    #
1012    #    IGCM_sys_Cp ${1} ${FILEPATH}
1013    #fi
1014
1015    if [ X${JobType} = XRUN ] ; then
1016      if [ X${3} = X ] ; then
1017        IGCM_sys_Chmod 444 ${1}
1018      fi
1019    fi
1020
1021    exist=false
1022    skip=false
1023    if [ -f $2 ] ; then
1024      IGCM_debug_Print 1 "$2 already exist"
1025      #dmget $2
1026      ccc_hsm get $2
1027      exist=true
1028      if [ "X$( diff $1 $2 )" = X ] ; then
1029        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1030        skip=true
1031      else
1032        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1033        skip=false
1034      fi
1035    fi
1036    #
1037    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1038      IGCM_sys_Chmod u+w $2
1039    fi
1040    # USUAL WAY
1041    if [ X${skip} = Xfalse ] ; then
1042      \cp $1 $2 > out_rsync 2>&1
1043      RET=$?
1044      if [ ${RET} -gt 0 ] ; then
1045        echo "IGCM_sys_Put_Out : error."
1046        cat out_rsync
1047        IGCM_debug_Exit "IGCM_sys_Put_Out"
1048      else
1049        \rm out_rsync
1050      fi
1051    fi
1052
1053#       #RSYNC WITH NETWORK SSH CALL
1054#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1055#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1056
1057#       #RSYNC WITH NFS USE
1058#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1059#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1060
1061#       RET=$?
1062#       IGCM_sys_Rsync_out $RET
1063
1064#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1065#       (( RET=RET+$? ))
1066
1067  else
1068    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1069  fi
1070  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1071  return 0
1072}
1073
1074#D-#==================================================
1075#D-function IGCM_sys_PutBuffer_Out
1076#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1077#D-* Examples:
1078#D-
1079function IGCM_sys_PutBuffer_Out {
1080  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1081  if ( $DEBUG_sys ) ; then
1082    echo "IGCM_sys_PutBuffer_Out :" $@
1083  fi
1084  if [ $DRYRUN = 0 ]; then
1085    if [ ! -f ${1} ] ; then
1086      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1087      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1088      return 1
1089    fi
1090    #
1091    IGCM_sys_Mkdir $( dirname $2 )
1092    #
1093    typeset RET
1094
1095    if [ X${JobType} = XRUN ] ; then
1096      if [ X${3} = X ] ; then
1097        IGCM_sys_Chmod 444 ${1}
1098      fi
1099    fi
1100    #
1101    # USUAL WAY
1102    \cp $1 $2 > out_rsync 2>&1
1103    RET=$?
1104
1105    if [ ${RET} -gt 0 ] ; then
1106      echo "IGCM_sys_PutBuffer_Out : error."
1107      cat out_rsync
1108      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1109    else
1110      \rm out_rsync
1111    fi
1112  else
1113    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1114  fi
1115  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1116  return 0
1117}
1118
1119#D-#==================================================
1120#D-function IGCM_sys_Get
1121#D-* Purpose: Get a file from ${ARCHIVE}
1122#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1123#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1124function IGCM_sys_Get {
1125  IGCM_debug_PushStack "IGCM_sys_Get" $@
1126
1127  typeset DEST RET dm_liste ifile target file_work
1128
1129  if ( $DEBUG_sys ) ; then
1130    echo "IGCM_sys_Get :" $@
1131  fi
1132  if [ $DRYRUN -le 2 ]; then
1133    if [ X${1} = X'/l' ] ; then
1134      # test if the first file is present in the old computation :
1135      eval set +A dm_liste \${${2}}
1136    else
1137      eval set +A dm_liste ${1}
1138    fi
1139    eval DEST=\${${#}}
1140
1141    #=====================================================
1142    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1143    #=====================================================
1144
1145    # Is it an R_OUT file (not R_IN) ?
1146    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1147    #if [ $? -eq 0 ] ; then
1148    #    # Yes  ? then we try to get it in SCRATCHDIR
1149    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1150    #    if [ -f ${file_work[0]} ] ; then
1151    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1152    #   IGCM_debug_PopStack "IGCM_sys_Get"
1153    #   return
1154    #    fi
1155    #fi
1156
1157    # test if the (first) file is present in the old computation :
1158    IGCM_sys_TestFileArchive ${dm_liste[0]}
1159    RET=$?
1160    if [ ${RET} -gt 0 ] ; then
1161      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1162      IGCM_debug_Exit "IGCM_sys_Get"
1163    fi
1164
1165    #dmget ${dm_liste[*]} > out_rsync 2>&1
1166    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1167    RET=$?
1168
1169    if [ ${RET} -gt 0 ] ; then
1170      echo "WARNING IGCM_sys_Get : demigration error."
1171      cat out_rsync
1172      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1173    fi
1174
1175    #if [ ${RET} -gt 0 ] ; then
1176    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1177    #   cat out_rsync
1178    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1179    #   sleep 30
1180    #   echo "We try another time"
1181    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1182    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1183    #   RET=$?
1184    #   if [ ${RET} -gt 0 ] ; then
1185    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1186    #       cat out_rsync
1187    #       IGCM_debug_Exit "IGCM_sys_Get"
1188    #   fi
1189    #    else
1190    #   echo "ERROR IGCM_sys_Get : demigration error :"
1191    #   cat out_rsync
1192    #   IGCM_debug_Exit "IGCM_sys_Get"
1193    #    fi
1194    #fi
1195
1196    #USUAL WAY
1197    if [ X${1} = X'/l' ] ; then
1198      (( RET=0 ))
1199      for target in ${dm_liste[*]} ; do
1200        local_file=$( basename ${target} )
1201        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1202        (( RET = RET + $? ))
1203      done
1204    else
1205      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1206      RET=$?
1207    fi
1208
1209#       #RSYNC WITH NETWORK SSH CALL
1210#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1211#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1212
1213#       #RSYNC WITH NFS USE
1214#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1215#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1216
1217#       RET=$?
1218#       IGCM_sys_Rsync_out $RET
1219
1220#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1221#       (( RET=RET+$? ))
1222
1223    if [ ${RET} -gt 0 ] ; then
1224      echo "IGCM_sys_Get : copy error."
1225      cat out_rsync
1226#      IGCM_debug_Exit "IGCM_sys_Get"
1227    else
1228      \rm out_rsync
1229    fi
1230  else
1231    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1232  fi
1233  IGCM_debug_PopStack "IGCM_sys_Get"
1234}
1235
1236#D-#==================================================
1237#D-function IGCM_sys_GetBuffer
1238#D-* Purpose: Get a file from ${SCRATCHDIR}
1239#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1240#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1241function IGCM_sys_GetBuffer {
1242  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1243
1244  typeset DEST RET buf_liste ifile target file_work
1245
1246  if ( $DEBUG_sys ) ; then
1247    echo "IGCM_sys_GetBuffer :" $@
1248  fi
1249  if [ $DRYRUN -le 2 ]; then
1250    if [ X${1} = X'/l' ] ; then
1251      # test if the first file is present in the old computation :
1252      eval set +A buf_liste \${${2}}
1253    else
1254      eval set +A buf_liste ${1}
1255    fi
1256    eval DEST=\${${#}}
1257
1258    #USUAL WAY
1259    if [ X${1} = X'/l' ] ; then
1260      (( RET=0 ))
1261      for target in ${buf_liste[*]} ; do
1262        local_file=$( basename ${target} )
1263        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1264        (( RET = RET + $? ))
1265      done
1266    else
1267      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1268      RET=$?
1269    fi
1270
1271    if [ ${RET} -gt 0 ] ; then
1272      echo "IGCM_sys_GetBuffer : copy error."
1273      cat out_rsync
1274      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1275    else
1276      \rm out_rsync
1277    fi
1278  else
1279    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1280  fi
1281  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1282}
1283
1284#D-#==================================================
1285#D-function IGCM_sys_GetDate_FichWork
1286#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1287#D-* Examples:
1288#D-
1289function IGCM_sys_GetDate_FichWork {
1290  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1291  if ( $DEBUG_sys ) ; then
1292    echo "IGCM_sys_GetDate_FichWork :" $@
1293  fi
1294  # donne la date filesys d'un fichier sur la machine work
1295  IGCM_debug_PopStack "IGCM_sys_FichWork"
1296}
1297
1298#D-#==================================================
1299#D-function IGCM_sys_GetDate_FichArchive
1300#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1301#D-* Examples:
1302#D-
1303function IGCM_sys_GetDate_FichArchive {
1304  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1305  if ( $DEBUG_sys ) ; then
1306    echo "IGCM_sys_GetDate_FichArchive :" $@
1307  fi
1308  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1309}
1310
1311#D-#==================================================
1312#D-function IGCM_sys_Dods_Rm
1313#D-* Purpose: DO NOTHING ! Put $(ARCHIVE) files on DODS internet protocole.
1314#D-* Examples:
1315#D-
1316function IGCM_sys_Dods_Rm {
1317  if ( $DEBUG_sys ) ; then
1318    echo "IGCM_sys_Dods_Rm :" $@
1319  fi
1320  typeset RET
1321  RET=0
1322  if [ $DRYRUN = 0 ]; then
1323
1324#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1325#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1326#      echo "Nothing has been done."
1327#      return
1328#    fi
1329
1330    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1331    RET=$?
1332   
1333#       if [ ${RET} -gt 0 ] ; then
1334#           echo "IGCM_sys_Dods_Rm : error."
1335#           cat out_dods_rm
1336#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1337#       else
1338#           rm out_dods_rm
1339#       fi
1340
1341  else
1342    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1343  fi
1344  return $RET
1345}
1346
1347#D-#==================================================
1348#D-function IGCM_sys_Dods_Cp
1349#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1350#D-* Examples:
1351#D-
1352function IGCM_sys_Dods_Cp {
1353  if ( $DEBUG_sys ) ; then
1354    echo "IGCM_sys_Dods_Cp :" $@
1355  fi
1356  typeset RET
1357  RET=0
1358  if [ $DRYRUN = 0 ]; then
1359
1360#    if [ ! -d ${R_SAVE}/${1} ] ; then
1361#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1362#      echo "Nothing has been done."
1363#      return
1364#    fi
1365
1366    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1367    RET=$?
1368
1369#       if [ ${RET} -gt 0 ] ; then
1370#           echo "IGCM_sys_Dods_Cp : error."
1371#           cat out_dods_cp
1372#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1373#       else
1374#           rm out_dods_cp
1375#       fi
1376
1377  else
1378    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1379  fi
1380  return $RET
1381}
1382
1383#D-#==================================================
1384#D-function IGCM_sys_Put_Dods
1385#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1386#D-* Examples:
1387#D-
1388function IGCM_sys_Put_Dods {
1389  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1390  if ( $DEBUG_sys ) ; then
1391    echo "IGCM_sys_Put_Dods :" $@
1392  fi
1393  typeset RET
1394  if [ $DRYRUN = 0 ]; then
1395    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1396      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1397      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1398      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1399      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1400      return
1401    fi
1402
1403    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1404      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1405      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1406      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1407      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1408      return
1409    fi
1410    #
1411    if [ -d ${R_SAVE}/${1} ] ; then
1412      cd ${R_SAVE}
1413    elif [ -d ${R_FIGR}/${1} ] ; then
1414      cd ${R_FIGR}
1415    fi
1416
1417    IGCM_sys_Dods_Rm ${1}
1418    IGCM_sys_Dods_Cp ${1}
1419    RET=0
1420   
1421    if [ ${RET} -gt 0 ] ; then
1422      echo "IGCM_sys_Put_Dods : error."
1423      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1424    fi
1425  else
1426    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1427  fi
1428  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1429}
1430
1431##############################################################
1432# REBUILD OPERATOR
1433
1434function IGCM_sys_rebuild {
1435  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1436  if ( $DEBUG_sys ) ; then
1437    echo "IGCM_sys_rebuild :" $@
1438  fi
1439  /home/cont003/p86ipsl/X86_64/bin/rebuild -f -o $@
1440  if [ $? -gt 0 ] ; then
1441    echo "IGCM_sys_rebuild : erreur ${@}."
1442    IGCM_debug_Exit "rebuild"
1443  fi
1444
1445  IGCM_debug_PopStack "IGCM_sys_rebuild"
1446}
1447
1448##############################################################
1449# NCO OPERATOR
1450
1451function IGCM_sys_ncap2 {
1452  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1453  if ( $DEBUG_sys ) ; then
1454    echo "IGCM_sys_ncap2 :" $@
1455  fi
1456  ncap2 "$@"
1457  if [ $? -gt 0 ] ; then
1458    echo "IGCM_sys_ncap2 : erreur ${@}."
1459    IGCM_debug_Exit "ncap2"
1460  fi
1461
1462  IGCM_debug_PopStack "IGCM_sys_ncap2"
1463}
1464
1465function IGCM_sys_ncatted {
1466  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1467  if ( $DEBUG_sys ) ; then
1468    echo "IGCM_sys_ncatted :" $@
1469  fi
1470  ncatted "$@"
1471  if [ $? -gt 0 ] ; then
1472    echo "IGCM_sys_ncatted : erreur ${@}."
1473    IGCM_debug_Exit "ncatted"
1474  fi
1475
1476  IGCM_debug_PopStack "IGCM_sys_ncatted"
1477}
1478
1479function IGCM_sys_ncbo {
1480  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1481  if ( $DEBUG_sys ) ; then
1482    echo "IGCM_sys_ncbo :" $@
1483  fi
1484  ncbo $@
1485  if [ $? -gt 0 ] ; then
1486    echo "IGCM_sys_ncbo : erreur ${@}."
1487    IGCM_debug_Exit "ncbo"
1488  fi
1489
1490  IGCM_debug_PopStack "IGCM_sys_ncbo"
1491}
1492
1493function IGCM_sys_ncdiff {
1494  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1495  if ( $DEBUG_sys ) ; then
1496    echo "IGCM_sys_ncdiff :" $@
1497  fi
1498  ncdiff $@
1499  if [ $? -gt 0 ] ; then
1500    echo "IGCM_sys_ncdiff : erreur ${@}."
1501    IGCM_debug_Exit "ncdiff"
1502  fi
1503
1504  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1505}
1506
1507function IGCM_sys_ncea {
1508  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1509  if ( $DEBUG_sys ) ; then
1510    echo "IGCM_sys_ncea :" $@
1511  fi
1512  ncea $@
1513  if [ $? -gt 0 ] ; then
1514    echo "IGCM_sys_ncea : erreur ${@}."
1515    IGCM_debug_Exit "ncea"
1516  fi
1517
1518  IGCM_debug_PopStack "IGCM_sys_ncea"
1519}
1520
1521function IGCM_sys_ncecat {
1522  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1523  if ( $DEBUG_sys ) ; then
1524    echo "IGCM_sys_ncecat :" $@
1525  fi
1526  ncecat $@
1527  if [ $? -gt 0 ] ; then
1528    echo "IGCM_sys_ncecat : erreur ${@}."
1529    IGCM_debug_Exit "ncecat"
1530  fi
1531
1532  IGCM_debug_PopStack "IGCM_sys_ncecat"
1533}
1534
1535function IGCM_sys_ncflint {
1536  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1537  if ( $DEBUG_sys ) ; then
1538    echo "IGCM_sys_ncflint :" $@
1539  fi
1540  ncflint $@
1541  if [ $? -gt 0 ] ; then
1542    echo "IGCM_sys_ncflint : erreur ${@}."
1543    IGCM_debug_Exit "ncflint"
1544  fi
1545
1546  IGCM_debug_PopStack "IGCM_sys_ncflint"
1547}
1548
1549function IGCM_sys_ncks {
1550  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1551  if ( $DEBUG_sys ) ; then
1552    echo "IGCM_sys_ncks :" $@
1553  fi
1554  ncks $@
1555  if [ $? -gt 0 ] ; then
1556    echo "IGCM_sys_ncks : erreur ${@}."
1557    IGCM_debug_Exit "ncks"
1558  fi
1559
1560  IGCM_debug_PopStack "IGCM_sys_ncks"
1561}
1562
1563function IGCM_sys_ncpdq {
1564  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1565  if ( $DEBUG_sys ) ; then
1566    echo "IGCM_sys_ncpdq :" $@
1567  fi
1568  ncpdq $@
1569  if [ $? -gt 0 ] ; then
1570    echo "IGCM_sys_ncpdq : erreur ${@}."
1571    IGCM_debug_Exit "ncpdq"
1572  fi
1573
1574  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1575}
1576
1577function IGCM_sys_ncra {
1578  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1579  if ( $DEBUG_sys ) ; then
1580    echo "IGCM_sys_ncra :" $@
1581  fi
1582  ncra $@
1583  if [ $? -gt 0 ] ; then
1584    echo "IGCM_sys_ncra : erreur ${@}."
1585    IGCM_debug_Exit "ncra"
1586  fi
1587
1588  IGCM_debug_PopStack "IGCM_sys_ncra"
1589}
1590
1591function IGCM_sys_ncrcat {
1592  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1593  if ( $DEBUG_sys ) ; then
1594    echo "IGCM_sys_ncrcat :" $@
1595  fi
1596  ncrcat $@
1597  if [ $? -gt 0 ] ; then
1598    echo "IGCM_sys_ncrcat : erreur ${@}."
1599#       IGCM_debug_Exit "ncrcat"
1600  fi
1601
1602  IGCM_debug_PopStack "IGCM_sys_ncrcat"
1603}
1604
1605function IGCM_sys_ncrename {
1606  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1607  if ( $DEBUG_sys ) ; then
1608    echo "IGCM_sys_ncrename :" $@
1609  fi
1610  ncrename $@
1611  if [ $? -gt 0 ] ; then
1612    echo "IGCM_sys_ncrename : erreur ${@}."
1613    IGCM_debug_Exit "ncrename"
1614  fi
1615
1616  IGCM_debug_PopStack "IGCM_sys_ncrename"
1617}
1618
1619function IGCM_sys_ncwa {
1620  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1621  if ( $DEBUG_sys ) ; then
1622    echo "IGCM_sys_ncwa :" $@
1623  fi
1624  ncwa $@
1625  if [ $? -gt 0 ] ; then
1626    echo "IGCM_sys_ncwa : erreur ${@}."
1627    IGCM_debug_Exit "ncwa"
1628  fi
1629
1630  IGCM_debug_PopStack "IGCM_sys_ncwa"
1631}
1632
1633##############################################################
1634# CDO OPERATOR
1635
1636function IGCM_sys_cdo {
1637  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
1638  if ( $DEBUG_sys ) ; then
1639    echo "IGCM_sys_cdo :" $@
1640  fi
1641  \cdo $@
1642  if [ $? -gt 0 ] ; then
1643    echo "IGCM_sys_cdo : erreur ${@}."
1644    IGCM_debug_PopStack "IGCM_sys_cdo"
1645    return 1
1646  else
1647    IGCM_debug_PopStack "IGCM_sys_cdo"
1648    return 0
1649  fi
1650
1651  IGCM_debug_PopStack "IGCM_sys_cdo"
1652}
1653
1654############################################################
1655# Activate Running Environnment Variables
1656
1657function IGCM_sys_activ_variables {
1658  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1659  if ( $DEBUG_sys ) ; then
1660    echo "IGCM_sys_activ_variables"
1661  fi
1662  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1663}
1664
1665############################################################
1666# Desactivate Running Environnment Variables
1667
1668function IGCM_sys_desactiv_variables {
1669  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1670  if ( $DEBUG_sys ) ; then
1671    echo "IGCM_sys_desactiv_variables"
1672  fi
1673  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1674}
1675
1676############################################################
1677# Build run file
1678
1679function IGCM_sys_build_run_file {
1680  IGCM_debug_PushStack "IGCM_sys_build_run_file"
1681  if ( $DEBUG_sys ) ; then
1682    echo "IGCM_sys_build_run_file"
1683  fi
1684  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1685}
Note: See TracBrowser for help on using the repository browser.