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

Last change on this file since 645 was 645, checked in by sdipsl, 12 years ago
  • IGCM_sys_CountFileArchive must be a quiet function so as not to disturb tests making us of it
  • 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  typeset ExistFlag
428  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
429  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
430
431  return ${ExistFlag}
432}
433
434#D-#==================================================
435#D-function IGCM_sys_TestFileBuffer
436#D-* Purpose: Test file that must NOT EXISTS on Buffer
437#D-* Examples:
438#D-
439function IGCM_sys_TestFileBuffer {
440  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
441  typeset ExistFlag
442  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
443  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
444
445  return ${ExistFlag}
446}
447
448#D-#==================================================
449#D-function IGCM_sys_CountFileArchive
450#D-* Purpose: Count files on Archive filesystem
451#D-* Examples:
452#D-
453function IGCM_sys_CountFileArchive {
454  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
455  ls ${@} 2>/dev/null | wc -l
456  if [ $? -gt 0 ] ; then
457    echo "IGCM_sys_CountFileArchive : erreur."
458  fi
459  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
460}
461
462#D-#==================================================
463#D-function IGCM_sys_CountFileBuffer
464#D-* Purpose: Count files on Scratch filesystem
465#D-* Examples:
466#D-
467function IGCM_sys_CountFileBuffer {
468  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
469  ls ${@} 2>/dev/null | wc -l
470  if [ $? -gt 0 ] ; then
471    echo "IGCM_sys_CountFileBuffer : erreur."
472  fi
473  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
474}
475
476#D-#==================================================
477#D-function IGCM_sys_Tree
478#D-* Purpose: Tree directories with files on ${ARCHIVE}
479#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
480#D-
481function IGCM_sys_Tree {
482  IGCM_debug_PushStack "IGCM_sys_Tree" $@
483  if ( $DEBUG_sys ) ; then
484    echo "IGCM_sys_Tree :" $@
485  fi
486
487  \tree -f $@
488
489  IGCM_debug_PopStack "IGCM_sys_Tree"
490}
491
492#D-#==================================================
493#D-function IGCM_sys_Tar
494#D-* Purpose: master tar command
495#D-* Examples:
496#D-
497function IGCM_sys_Tar {
498  IGCM_debug_PushStack "IGCM_sys_Tar" $@
499  if ( $DEBUG_sys ) ; then
500    echo "IGCM_sys_Tar :" $@
501  fi
502  \tar cf $@
503  if [ $? -gt 0 ] ; then
504    echo "IGCM_sys_Tar : erreur."
505    IGCM_debug_Exit "IGCM_sys_Tar"
506  fi
507  IGCM_debug_PopStack "IGCM_sys_Tar"
508}
509
510#D-#==================================================
511#D-function IGCM_sys_UnTar
512#D-* Purpose: master un-tar command
513#D-* Examples:
514#D-
515function IGCM_sys_UnTar {
516  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
517  if ( $DEBUG_sys ) ; then
518    echo "IGCM_sys_UnTar :" $@
519  fi
520  \tar xvf $1
521  if [ $? -gt 0 ] ; then
522    echo "IGCM_sys_UnTar : erreur."
523    IGCM_debug_Exit "IGCM_sys_UnTar"
524  fi
525  IGCM_debug_PopStack "IGCM_sys_UnTar"
526}
527
528#D-#==================================================
529#D-function IGCM_sys_QsubPost
530#D-* Purpose: Qsub new job on scalaire
531#D-* Examples:
532#D-
533function IGCM_sys_QsubPost {
534  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
535  if ( $DEBUG_sys ) ; then
536    echo "IGCM_sys_QsubPost :" $@
537  fi
538  /usr/bin/nqsII/qsub -q scalaire -o ${POST_DIR}/${Script_Post_Output}.out ${libIGCM}/$1.job -v ${listVarEnv}
539  if [ $? -gt 0 ] ; then
540    echo "IGCM_sys_QsubPost : erreur " $@
541    IGCM_debug_Exit "IGCM_sys_QsubPost"
542  fi
543  IGCM_debug_PopStack "IGCM_sys_QsubPost"
544}
545
546#D-*************************
547#D- File transfer functions
548#D-*************************
549#D-
550
551#D-#==================================================
552#D-function IGCM_sys_Rsync_out
553#D-* Purpose: treat return val of rsync
554#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
555#D-  Error values and explanations can depend on your system version.
556function IGCM_sys_Rsync_out {
557  RET=$1
558  if [ ! $RET ] ; then
559    echo "rsync error !"
560  fi
561
562  if [ $MYLANG = "fr" ]; then
563    case $RET in
564    0)  return ;;
565    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
566      echo "Erreur de syntaxe ou d'utilisation."
567      return;;
568    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
569      echo "Incompatibilité de protocole."
570      return;;
571    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
572      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
573      echo "répertoires"
574      return;;
575    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
576      echo "Action demandée non supportée : une tentative de manipulation de"
577      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
578      echo "été faite ; ou une option qui est supportée par le  client  mais"
579      echo "pas par le serveur a été spécifiée."
580      return;;
581    10) echo "Erreur de rsync ; RERR_SOCKETIO"
582      echo "Erreur dans le socket d'entrée sortie"
583      return;;
584    11) echo "Erreur de rsync ; RERR_FILEIO"
585      echo "Erreur d'entrée sortie fichier"
586      return;;
587    12) echo "Erreur de rsync ; RERR_STREAMIO"
588      echo "Erreur dans flux de donnée du protocole rsync"
589      return;;
590    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
591      echo "Erreur avec les diagnostics du programme"
592      return;;
593    14) echo "Erreur de rsync ; RERR_IPC"
594      echo "Erreur dans le code IPC"
595      return;;
596    20) echo "Erreur de rsync ; RERR_SIGNAL"
597      echo "SIGUSR1 ou SIGINT reçu"
598      return;;
599    21) echo "Erreur de rsync ; RERR_WAITCHILD"
600      echo "Une erreur retournée par waitpid()"
601      return;;
602    22) echo "Erreur de rsync ; RERR_MALLOC"
603      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
604      return;;
605    23) echo ""
606      echo "Erreur fichier inexistant"
607      return;;
608    30) echo "Erreur de rsync ; RERR_TIMEOUT"
609      echo "Temps d'attente écoulé dans l'envoi/réception de données"
610      return;;
611    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
612      return;;
613    esac
614  elif [ $MYLANG = "en" ] ; then
615    case $RET in
616    0)  return;;               
617    1)  echo "rsync error : Syntax or usage error "
618      return;;
619    2)  echo "rsync error : Protocol incompatibility "
620      return;;
621    3)  echo "rsync error : Errors selecting input/output files, dirs"
622      return;;
623    4)  echo "rsync error : Requested action not supported: an attempt"
624      echo "was made to manipulate 64-bit files on a platform that cannot support"
625      echo "them; or an option was specified that is supported by the client and"
626      echo "not by the server."
627      return;;
628    5)  echo "rsync error : Error starting client-server protocol"
629      return;;
630    10) echo "rsync error : Error in socket I/O "
631      return;;
632    11) echo "rsync error : Error in file I/O "
633      return;;
634    12) echo "rsync error : Error in rsync protocol data stream "
635      return;;
636    13) echo "rsync error : Errors with program diagnostics "
637      return;;
638    14) echo "rsync error : Error in IPC code "
639      return;;
640    20) echo "rsync error : Received SIGUSR1 or SIGINT "
641      return;;
642    21) echo "rsync error : Some error returned by waitpid() "
643      return;;
644    22) echo "rsync error : Error allocating core memory buffers "
645      return;;
646    23) echo "rsync error : Partial transfer due to error"
647      return;;
648    24) echo "rsync error : Partial transfer due to vanished source files"
649      return;;
650    30) echo "rsync error : Timeout in data send/receive "
651      return;;
652    *)  echo "rsync error : return code of rsync unknown :" $RET
653      return;;
654    esac
655  else
656    echo "unknown language $MYLANG."
657    return
658  fi
659}
660
661#D-#==================================================
662#D-function IGCM_sys_Cp
663#D-* Purpose: generic cp
664#D-* Examples:
665#D-
666function IGCM_sys_Cp {
667  IGCM_debug_PushStack "IGCM_sys_Cp" $@
668  if ( $DEBUG_sys ) ; then
669    echo "IGCM_sys_Cp :" $@
670  fi
671
672  typeset RET
673
674  echo cp $@ > out_rsync 2>&1
675  \cp $@ >> out_rsync 2>&1
676  RET=$?
677
678  if [ ${RET} -gt 0 ] ; then
679    echo "IGCM_sys_Cp : error."
680    cat out_rsync
681    IGCM_debug_Exit "IGCM_sys_Cp"
682  else
683    \rm out_rsync
684  fi
685  IGCM_debug_PopStack "IGCM_sys_Cp"
686}
687
688#D-#==================================================
689#D-function IGCM_sys_Rm
690#D-* Purpose: generic rm
691#D-* Examples:
692#D-
693function IGCM_sys_Rm {
694  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
695  if ( $DEBUG_sys ) ; then
696    echo "IGCM_sys_Rm :" $@
697  fi
698
699  typeset RET
700
701  echo rm $@ > out_rsync 2>&1
702  \rm $@ >> out_rsync 2>&1
703  RET=$?
704
705  if [ ${RET} -gt 0 ] ; then
706    echo "IGCM_sys_Rm : error."
707    cat out_rsync
708    IGCM_debug_Exit "IGCM_sys_Rm"
709  else
710    \rm out_rsync
711  fi
712  IGCM_debug_PopStack "IGCM_sys_Rm"
713}
714
715#D-#==================================================
716#D-function IGCM_sys_RmRunDir
717#D-* Purpose: rm tmpdir (dummy function most of the time batch
718#D-                      scheduler will do the job)
719#D-           Dummy function on mercure front-end
720#D-* Examples:
721#D-
722function IGCM_sys_RmRunDir {
723    IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
724    if ( $DEBUG_sys ) ; then
725        echo "IGCM_sys_RmRunDir :" $@
726        echo "Dummy call, let the scheduler do that."
727    fi
728    IGCM_debug_PopStack "IGCM_sys_RmRunDir"
729}
730
731#D-#==================================================
732#D-function IGCM_sys_Mv
733#D-* Purpose: generic move
734#D-* Examples:
735#D-
736function IGCM_sys_Mv {
737  IGCM_debug_PushStack "IGCM_sys_Mv" $@
738  if ( $DEBUG_sys ) ; then
739    echo "IGCM_sys_Mv :" $@
740  fi
741
742  if [ $DRYRUN = 0 ]; then
743
744    typeset RET
745   
746    echo mv $@ > out_rsync 2>&1
747    \mv $@ >> out_rsync 2>&1
748    RET=$?
749   
750    if [ ${RET} -gt 0 ] ; then
751      echo "IGCM_sys_Mv : error in mv."
752      cat out_rsync
753      IGCM_debug_Exit "IGCM_sys_Mv"
754    else
755      \rm out_rsync
756    fi
757  else
758    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
759  fi
760
761  IGCM_debug_PopStack "IGCM_sys_Mv"
762}
763
764#D-#==================================================
765#D-function IGCM_sys_Put_Dir
766#D-* Purpose: Copy a complete directory on $(ARCHIVE)
767#D-* Examples:
768#D-
769function IGCM_sys_Put_Dir {
770  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
771  if ( $DEBUG_sys ) ; then
772    echo "IGCM_sys_Put_Dir :" $@
773  fi
774  if [ $DRYRUN = 0 ]; then
775    if [ ! -d ${1} ] ; then
776      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
777      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
778      return
779    fi
780
781    typeset RET
782
783    # Only if we use rsync
784    #IGCM_sys_TestDirArchive $( dirname $2 )
785    #
786    #USUAL WAY
787    \cp -r $1 $2 > out_rsync 2>&1
788    RET=$?
789
790    if [ ${RET} -gt 0 ] ; then
791      echo "IGCM_sys_Put_Dir : error."
792      cat out_rsync
793      IGCM_debug_Exit "IGCM_sys_Put_Dir"
794    else
795      \rm out_rsync
796    fi
797  else
798    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
799  fi
800  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
801}
802
803#D-#==================================================
804#D-function IGCM_sys_Get_Dir
805#D-* Purpose: Copy a complete directory from $(ARCHIVE)
806#D-* Examples:
807#D-
808function IGCM_sys_Get_Dir {
809  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
810  if ( $DEBUG_sys ) ; then
811    echo "IGCM_sys_Get_Dir :" $@
812  fi
813  if [ $DRYRUN = 0 ]; then
814#       if [ ! -d ${1} ] ; then
815#           echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
816#           IGCM_debug_PopStack "IGCM_sys_Get_Dir"
817#           return
818#       fi
819
820    typeset RET
821
822    # Only if we use rsync
823    #IGCM_sys_TestDirArchive $( dirname $2 )
824    #
825    #USUAL WAY
826    # add dmget (to demigrate all offline files) to reduce time of this command :
827    #dmget $1/*
828    ccc_hsm get $1/*
829    \cp -r $1 $2 > out_rsync 2>&1
830    RET=$?
831
832    if [ ${RET} -gt 0 ] ; then
833      echo "IGCM_sys_Get_Dir : error."
834      cat out_rsync
835      IGCM_debug_Exit "IGCM_sys_Get_Dir"
836    else
837      \rm out_rsync
838    fi
839  else
840    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
841  fi
842  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
843}
844
845#D-#==================================================
846#D-function IGCM_sys_Get_Master
847#D-* Purpose: Copy a complete directory from MASTER filesystem
848#D-* Examples:
849#D-
850function IGCM_sys_Get_Master {
851  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
852  if ( $DEBUG_sys ) ; then
853    echo "IGCM_sys_Get_Master :" $@
854  fi
855  if [ $DRYRUN = 0 ]; then
856    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
857      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
858      IGCM_debug_PopStack "IGCM_sys_Get_Master"
859      return
860    fi
861
862    typeset RET
863
864    #USUAL WAY
865    \cp -r $1 $2 > out_rsync 2>&1
866    RET=$?
867
868    if [ ${RET} -gt 0 ] ; then
869      echo "IGCM_sys_Get_Master : error."
870      cat out_rsync
871      IGCM_debug_Exit "IGCM_sys_Get_Master"
872    else
873      \rm out_rsync
874    fi
875  else
876    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
877  fi
878  IGCM_debug_PopStack "IGCM_sys_Get_Master"
879}
880
881#D-#==================================================
882#D-function IGCM_sys_Put_Rest
883#D-* Purpose: Put computied restarts on ${ARCHIVE}.
884#D-           File and target directory must exist.
885#D-* Examples:
886#D-
887function IGCM_sys_Put_Rest {
888  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
889  if ( $DEBUG_sys ) ; then
890    echo "IGCM_sys_Put_Rest :" $@
891  fi
892  if [ $DRYRUN = 0 ]; then
893    if [ ! -f ${1} ] ; then
894      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
895      IGCM_debug_Exit "IGCM_sys_Put_Rest"
896    fi
897
898    typeset RET
899    #
900    if [ X${JobType} = XRUN ] ; then
901      IGCM_sys_Chmod 444 ${1}
902    fi
903
904    #
905    # USUAL WAY
906    \cp $1 $2 > out_rsync 2>&1
907    RET=$?
908
909#       #RSYNC WITH NETWORK SSH CALL
910#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
911#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
912
913#       #RSYNC WITH NFS USE
914#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
915#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
916
917#       RET=$?
918#       IGCM_sys_Rsync_out $RET
919
920#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
921#       (( RET=RET+$? ))
922
923    if [ ${RET} -gt 0 ] ; then
924      echo "IGCM_sys_Put_Rest : error."
925      cat out_rsync
926      IGCM_debug_Exit "IGCM_sys_Put_Rest"
927    else
928      \rm out_rsync
929    fi
930  else
931    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
932  fi
933  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
934}
935
936#D-#==================================================
937#D-function IGCM_sys_PutBuffer_Rest
938#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
939#D-           File and target directory must exist.
940#D-* Examples:
941#D-
942function IGCM_sys_PutBuffer_Rest {
943  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
944  if ( $DEBUG_sys ) ; then
945    echo "IGCM_sys_PutBuffer_Rest :" $@
946  fi
947  if [ $DRYRUN = 0 ]; then
948    if [ ! -f ${1} ] ; then
949      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
950      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
951    fi
952
953    typeset RET
954    #
955    if [ X${JobType} = XRUN ] ; then
956      IGCM_sys_Chmod 444 ${1}
957    fi
958
959    #
960    # USUAL WAY
961    \cp $1 $2 > out_rsync 2>&1
962    RET=$?
963
964    if [ ${RET} -gt 0 ] ; then
965      echo "IGCM_sys_PutBuffer_Rest : error."
966      cat out_rsync
967      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
968    else
969      \rm out_rsync
970    fi
971  else
972    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
973  fi
974  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
975}
976
977#D-#==================================================
978#D-function IGCM_sys_Put_Out
979#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
980#D-* Examples:
981#D-
982function IGCM_sys_Put_Out {
983  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
984  if ( $DEBUG_sys ) ; then
985    echo "IGCM_sys_Put_Out :" $@
986  fi
987  if [ $DRYRUN = 0 ]; then
988    if [ ! -f ${1} ] ; then
989      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
990      IGCM_debug_PopStack "IGCM_sys_Put_Out"
991      return 1
992    fi
993    #
994    IGCM_sys_MkdirArchive $( dirname $2 )
995    #
996    typeset RET exist skip
997
998    #=====================================================
999    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1000    #=====================================================
1001
1002    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1003    #if [ $? -eq 0 ] ; then
1004    #    typeset WORKPATH FILEPATH
1005    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1006    #    IGCM_sys_MkdirWork ${WORKPATH}
1007    #    FILEPATH=${WORKPATH}/$( basename $2 )
1008    #    #
1009    #    IGCM_sys_Cp ${1} ${FILEPATH}
1010    #fi
1011
1012    if [ X${JobType} = XRUN ] ; then
1013      if [ X${3} = X ] ; then
1014        IGCM_sys_Chmod 444 ${1}
1015      fi
1016    fi
1017
1018    exist=false
1019    skip=false
1020    if [ -f $2 ] ; then
1021      IGCM_debug_Print 1 "$2 already exist"
1022      #dmget $2
1023      ccc_hsm get $2
1024      exist=true
1025      if [ "X$( diff $1 $2 )" = X ] ; then
1026        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1027        skip=true
1028      else
1029        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1030        skip=false
1031      fi
1032    fi
1033    #
1034    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1035      IGCM_sys_Chmod u+w $2
1036    fi
1037    # USUAL WAY
1038    if [ X${skip} = Xfalse ] ; then
1039      \cp $1 $2 > out_rsync 2>&1
1040      RET=$?
1041      if [ ${RET} -gt 0 ] ; then
1042        echo "IGCM_sys_Put_Out : error."
1043        cat out_rsync
1044        IGCM_debug_Exit "IGCM_sys_Put_Out"
1045      else
1046        \rm out_rsync
1047      fi
1048    fi
1049
1050#       #RSYNC WITH NETWORK SSH CALL
1051#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1052#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1053
1054#       #RSYNC WITH NFS USE
1055#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1056#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1057
1058#       RET=$?
1059#       IGCM_sys_Rsync_out $RET
1060
1061#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1062#       (( RET=RET+$? ))
1063
1064  else
1065    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1066  fi
1067  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1068  return 0
1069}
1070
1071#D-#==================================================
1072#D-function IGCM_sys_PutBuffer_Out
1073#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1074#D-* Examples:
1075#D-
1076function IGCM_sys_PutBuffer_Out {
1077  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1078  if ( $DEBUG_sys ) ; then
1079    echo "IGCM_sys_PutBuffer_Out :" $@
1080  fi
1081  if [ $DRYRUN = 0 ]; then
1082    if [ ! -f ${1} ] ; then
1083      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1084      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1085      return 1
1086    fi
1087    #
1088    IGCM_sys_Mkdir $( dirname $2 )
1089    #
1090    typeset RET
1091
1092    if [ X${JobType} = XRUN ] ; then
1093      if [ X${3} = X ] ; then
1094        IGCM_sys_Chmod 444 ${1}
1095      fi
1096    fi
1097    #
1098    # USUAL WAY
1099    \cp $1 $2 > out_rsync 2>&1
1100    RET=$?
1101
1102    if [ ${RET} -gt 0 ] ; then
1103      echo "IGCM_sys_PutBuffer_Out : error."
1104      cat out_rsync
1105      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1106    else
1107      \rm out_rsync
1108    fi
1109  else
1110    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1111  fi
1112  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1113  return 0
1114}
1115
1116#D-#==================================================
1117#D-function IGCM_sys_Get
1118#D-* Purpose: Get a file from ${ARCHIVE}
1119#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1120#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1121function IGCM_sys_Get {
1122  IGCM_debug_PushStack "IGCM_sys_Get" $@
1123
1124  typeset DEST RET dm_liste ifile target file_work
1125
1126  if ( $DEBUG_sys ) ; then
1127    echo "IGCM_sys_Get :" $@
1128  fi
1129  if [ $DRYRUN -le 2 ]; then
1130    if [ X${1} = X'/l' ] ; then
1131      # test if the first file is present in the old computation :
1132      eval set +A dm_liste \${${2}}
1133    else
1134      eval set +A dm_liste ${1}
1135    fi
1136    eval DEST=\${${#}}
1137
1138    #=====================================================
1139    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1140    #=====================================================
1141
1142    # Is it an R_OUT file (not R_IN) ?
1143    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1144    #if [ $? -eq 0 ] ; then
1145    #    # Yes  ? then we try to get it in SCRATCHDIR
1146    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1147    #    if [ -f ${file_work[0]} ] ; then
1148    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1149    #   IGCM_debug_PopStack "IGCM_sys_Get"
1150    #   return
1151    #    fi
1152    #fi
1153
1154    # test if the (first) file is present in the old computation :
1155    IGCM_sys_TestFileArchive ${dm_liste[0]}
1156    RET=$?
1157    if [ ${RET} -gt 0 ] ; then
1158      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1159      IGCM_debug_Exit "IGCM_sys_Get"
1160    fi
1161
1162    #dmget ${dm_liste[*]} > out_rsync 2>&1
1163    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1164    RET=$?
1165
1166    if [ ${RET} -gt 0 ] ; then
1167      echo "WARNING IGCM_sys_Get : demigration error."
1168      cat out_rsync
1169      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1170    fi
1171
1172    #if [ ${RET} -gt 0 ] ; then
1173    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1174    #   cat out_rsync
1175    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1176    #   sleep 30
1177    #   echo "We try another time"
1178    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1179    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1180    #   RET=$?
1181    #   if [ ${RET} -gt 0 ] ; then
1182    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1183    #       cat out_rsync
1184    #       IGCM_debug_Exit "IGCM_sys_Get"
1185    #   fi
1186    #    else
1187    #   echo "ERROR IGCM_sys_Get : demigration error :"
1188    #   cat out_rsync
1189    #   IGCM_debug_Exit "IGCM_sys_Get"
1190    #    fi
1191    #fi
1192
1193    #USUAL WAY
1194    if [ X${1} = X'/l' ] ; then
1195      (( RET=0 ))
1196      for target in ${dm_liste[*]} ; do
1197        local_file=$( basename ${target} )
1198        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1199        (( RET = RET + $? ))
1200      done
1201    else
1202      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1203      RET=$?
1204    fi
1205
1206#       #RSYNC WITH NETWORK SSH CALL
1207#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1208#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1209
1210#       #RSYNC WITH NFS USE
1211#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1212#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1213
1214#       RET=$?
1215#       IGCM_sys_Rsync_out $RET
1216
1217#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1218#       (( RET=RET+$? ))
1219
1220    if [ ${RET} -gt 0 ] ; then
1221      echo "IGCM_sys_Get : copy error."
1222      cat out_rsync
1223#      IGCM_debug_Exit "IGCM_sys_Get"
1224    else
1225      \rm out_rsync
1226    fi
1227  else
1228    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1229  fi
1230  IGCM_debug_PopStack "IGCM_sys_Get"
1231}
1232
1233#D-#==================================================
1234#D-function IGCM_sys_GetBuffer
1235#D-* Purpose: Get a file from ${SCRATCHDIR}
1236#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1237#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1238function IGCM_sys_GetBuffer {
1239  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1240
1241  typeset DEST RET buf_liste ifile target file_work
1242
1243  if ( $DEBUG_sys ) ; then
1244    echo "IGCM_sys_GetBuffer :" $@
1245  fi
1246  if [ $DRYRUN -le 2 ]; then
1247    if [ X${1} = X'/l' ] ; then
1248      # test if the first file is present in the old computation :
1249      eval set +A buf_liste \${${2}}
1250    else
1251      eval set +A buf_liste ${1}
1252    fi
1253    eval DEST=\${${#}}
1254
1255    #USUAL WAY
1256    if [ X${1} = X'/l' ] ; then
1257      (( RET=0 ))
1258      for target in ${buf_liste[*]} ; do
1259        local_file=$( basename ${target} )
1260        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1261        (( RET = RET + $? ))
1262      done
1263    else
1264      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1265      RET=$?
1266    fi
1267
1268    if [ ${RET} -gt 0 ] ; then
1269      echo "IGCM_sys_GetBuffer : copy error."
1270      cat out_rsync
1271      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1272    else
1273      \rm out_rsync
1274    fi
1275  else
1276    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1277  fi
1278  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1279}
1280
1281#D-#==================================================
1282#D-function IGCM_sys_GetDate_FichWork
1283#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1284#D-* Examples:
1285#D-
1286function IGCM_sys_GetDate_FichWork {
1287  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1288  if ( $DEBUG_sys ) ; then
1289    echo "IGCM_sys_GetDate_FichWork :" $@
1290  fi
1291  # donne la date filesys d'un fichier sur la machine work
1292  IGCM_debug_PopStack "IGCM_sys_FichWork"
1293}
1294
1295#D-#==================================================
1296#D-function IGCM_sys_GetDate_FichArchive
1297#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1298#D-* Examples:
1299#D-
1300function IGCM_sys_GetDate_FichArchive {
1301  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1302  if ( $DEBUG_sys ) ; then
1303    echo "IGCM_sys_GetDate_FichArchive :" $@
1304  fi
1305  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1306}
1307
1308#D-#==================================================
1309#D-function IGCM_sys_Dods_Rm
1310#D-* Purpose: DO NOTHING ! Put $(ARCHIVE) files on DODS internet protocole.
1311#D-* Examples:
1312#D-
1313function IGCM_sys_Dods_Rm {
1314  if ( $DEBUG_sys ) ; then
1315    echo "IGCM_sys_Dods_Rm :" $@
1316  fi
1317  typeset RET
1318  RET=0
1319  if [ $DRYRUN = 0 ]; then
1320
1321#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1322#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1323#      echo "Nothing has been done."
1324#      return
1325#    fi
1326
1327    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1328    RET=$?
1329   
1330#       if [ ${RET} -gt 0 ] ; then
1331#           echo "IGCM_sys_Dods_Rm : error."
1332#           cat out_dods_rm
1333#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1334#       else
1335#           rm out_dods_rm
1336#       fi
1337
1338  else
1339    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1340  fi
1341  return $RET
1342}
1343
1344#D-#==================================================
1345#D-function IGCM_sys_Dods_Cp
1346#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1347#D-* Examples:
1348#D-
1349function IGCM_sys_Dods_Cp {
1350  if ( $DEBUG_sys ) ; then
1351    echo "IGCM_sys_Dods_Cp :" $@
1352  fi
1353  typeset RET
1354  RET=0
1355  if [ $DRYRUN = 0 ]; then
1356
1357#    if [ ! -d ${R_SAVE}/${1} ] ; then
1358#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1359#      echo "Nothing has been done."
1360#      return
1361#    fi
1362
1363    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1364    RET=$?
1365
1366#       if [ ${RET} -gt 0 ] ; then
1367#           echo "IGCM_sys_Dods_Cp : error."
1368#           cat out_dods_cp
1369#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1370#       else
1371#           rm out_dods_cp
1372#       fi
1373
1374  else
1375    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1376  fi
1377  return $RET
1378}
1379
1380#D-#==================================================
1381#D-function IGCM_sys_Put_Dods
1382#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1383#D-* Examples:
1384#D-
1385function IGCM_sys_Put_Dods {
1386  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1387  if ( $DEBUG_sys ) ; then
1388    echo "IGCM_sys_Put_Dods :" $@
1389  fi
1390  typeset RET
1391  if [ $DRYRUN = 0 ]; then
1392    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1393      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1394      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1395      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1396      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1397      return
1398    fi
1399
1400    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1401      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1402      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1403      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1404      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1405      return
1406    fi
1407    #
1408    if [ -d ${R_SAVE}/${1} ] ; then
1409      cd ${R_SAVE}
1410    elif [ -d ${R_FIGR}/${1} ] ; then
1411      cd ${R_FIGR}
1412    fi
1413
1414    IGCM_sys_Dods_Rm ${1}
1415    IGCM_sys_Dods_Cp ${1}
1416    RET=0
1417   
1418    if [ ${RET} -gt 0 ] ; then
1419      echo "IGCM_sys_Put_Dods : error."
1420      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1421    fi
1422  else
1423    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1424  fi
1425  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1426}
1427
1428##############################################################
1429# REBUILD OPERATOR
1430
1431function IGCM_sys_rebuild {
1432  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1433  if ( $DEBUG_sys ) ; then
1434    echo "IGCM_sys_rebuild :" $@
1435  fi
1436  /home/cont003/p86ipsl/X86_64/bin/rebuild -f -o $@
1437  if [ $? -gt 0 ] ; then
1438    echo "IGCM_sys_rebuild : erreur ${@}."
1439    IGCM_debug_Exit "rebuild"
1440  fi
1441
1442  IGCM_debug_PopStack "IGCM_sys_rebuild"
1443}
1444
1445##############################################################
1446# NCO OPERATOR
1447
1448function IGCM_sys_ncap2 {
1449  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1450  if ( $DEBUG_sys ) ; then
1451    echo "IGCM_sys_ncap2 :" $@
1452  fi
1453  ncap2 "$@"
1454  if [ $? -gt 0 ] ; then
1455    echo "IGCM_sys_ncap2 : erreur ${@}."
1456    IGCM_debug_Exit "ncap2"
1457  fi
1458
1459  IGCM_debug_PopStack "IGCM_sys_ncap2"
1460}
1461
1462function IGCM_sys_ncatted {
1463  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1464  if ( $DEBUG_sys ) ; then
1465    echo "IGCM_sys_ncatted :" $@
1466  fi
1467  ncatted "$@"
1468  if [ $? -gt 0 ] ; then
1469    echo "IGCM_sys_ncatted : erreur ${@}."
1470    IGCM_debug_Exit "ncatted"
1471  fi
1472
1473  IGCM_debug_PopStack "IGCM_sys_ncatted"
1474}
1475
1476function IGCM_sys_ncbo {
1477  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1478  if ( $DEBUG_sys ) ; then
1479    echo "IGCM_sys_ncbo :" $@
1480  fi
1481  ncbo $@
1482  if [ $? -gt 0 ] ; then
1483    echo "IGCM_sys_ncbo : erreur ${@}."
1484    IGCM_debug_Exit "ncbo"
1485  fi
1486
1487  IGCM_debug_PopStack "IGCM_sys_ncbo"
1488}
1489
1490function IGCM_sys_ncdiff {
1491  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1492  if ( $DEBUG_sys ) ; then
1493    echo "IGCM_sys_ncdiff :" $@
1494  fi
1495  ncdiff $@
1496  if [ $? -gt 0 ] ; then
1497    echo "IGCM_sys_ncdiff : erreur ${@}."
1498    IGCM_debug_Exit "ncdiff"
1499  fi
1500
1501  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1502}
1503
1504function IGCM_sys_ncea {
1505  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1506  if ( $DEBUG_sys ) ; then
1507    echo "IGCM_sys_ncea :" $@
1508  fi
1509  ncea $@
1510  if [ $? -gt 0 ] ; then
1511    echo "IGCM_sys_ncea : erreur ${@}."
1512    IGCM_debug_Exit "ncea"
1513  fi
1514
1515  IGCM_debug_PopStack "IGCM_sys_ncea"
1516}
1517
1518function IGCM_sys_ncecat {
1519  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1520  if ( $DEBUG_sys ) ; then
1521    echo "IGCM_sys_ncecat :" $@
1522  fi
1523  ncecat $@
1524  if [ $? -gt 0 ] ; then
1525    echo "IGCM_sys_ncecat : erreur ${@}."
1526    IGCM_debug_Exit "ncecat"
1527  fi
1528
1529  IGCM_debug_PopStack "IGCM_sys_ncecat"
1530}
1531
1532function IGCM_sys_ncflint {
1533  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1534  if ( $DEBUG_sys ) ; then
1535    echo "IGCM_sys_ncflint :" $@
1536  fi
1537  ncflint $@
1538  if [ $? -gt 0 ] ; then
1539    echo "IGCM_sys_ncflint : erreur ${@}."
1540    IGCM_debug_Exit "ncflint"
1541  fi
1542
1543  IGCM_debug_PopStack "IGCM_sys_ncflint"
1544}
1545
1546function IGCM_sys_ncks {
1547  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1548  if ( $DEBUG_sys ) ; then
1549    echo "IGCM_sys_ncks :" $@
1550  fi
1551  ncks $@
1552  if [ $? -gt 0 ] ; then
1553    echo "IGCM_sys_ncks : erreur ${@}."
1554    IGCM_debug_Exit "ncks"
1555  fi
1556
1557  IGCM_debug_PopStack "IGCM_sys_ncks"
1558}
1559
1560function IGCM_sys_ncpdq {
1561  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1562  if ( $DEBUG_sys ) ; then
1563    echo "IGCM_sys_ncpdq :" $@
1564  fi
1565  ncpdq $@
1566  if [ $? -gt 0 ] ; then
1567    echo "IGCM_sys_ncpdq : erreur ${@}."
1568    IGCM_debug_Exit "ncpdq"
1569  fi
1570
1571  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1572}
1573
1574function IGCM_sys_ncra {
1575  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1576  if ( $DEBUG_sys ) ; then
1577    echo "IGCM_sys_ncra :" $@
1578  fi
1579  ncra $@
1580  if [ $? -gt 0 ] ; then
1581    echo "IGCM_sys_ncra : erreur ${@}."
1582    IGCM_debug_Exit "ncra"
1583  fi
1584
1585  IGCM_debug_PopStack "IGCM_sys_ncra"
1586}
1587
1588function IGCM_sys_ncrcat {
1589  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1590  if ( $DEBUG_sys ) ; then
1591    echo "IGCM_sys_ncrcat :" $@
1592  fi
1593  ncrcat $@
1594  if [ $? -gt 0 ] ; then
1595    echo "IGCM_sys_ncrcat : erreur ${@}."
1596#       IGCM_debug_Exit "ncrcat"
1597  fi
1598
1599  IGCM_debug_PopStack "IGCM_sys_ncrcat"
1600}
1601
1602function IGCM_sys_ncrename {
1603  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1604  if ( $DEBUG_sys ) ; then
1605    echo "IGCM_sys_ncrename :" $@
1606  fi
1607  ncrename $@
1608  if [ $? -gt 0 ] ; then
1609    echo "IGCM_sys_ncrename : erreur ${@}."
1610    IGCM_debug_Exit "ncrename"
1611  fi
1612
1613  IGCM_debug_PopStack "IGCM_sys_ncrename"
1614}
1615
1616function IGCM_sys_ncwa {
1617  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1618  if ( $DEBUG_sys ) ; then
1619    echo "IGCM_sys_ncwa :" $@
1620  fi
1621  ncwa $@
1622  if [ $? -gt 0 ] ; then
1623    echo "IGCM_sys_ncwa : erreur ${@}."
1624    IGCM_debug_Exit "ncwa"
1625  fi
1626
1627  IGCM_debug_PopStack "IGCM_sys_ncwa"
1628}
1629
1630##############################################################
1631# CDO OPERATOR
1632
1633function IGCM_sys_cdo {
1634  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
1635  if ( $DEBUG_sys ) ; then
1636    echo "IGCM_sys_cdo :" $@
1637  fi
1638  \cdo $@
1639  if [ $? -gt 0 ] ; then
1640    echo "IGCM_sys_cdo : erreur ${@}."
1641    IGCM_debug_PopStack "IGCM_sys_cdo"
1642    return 1
1643  else
1644    IGCM_debug_PopStack "IGCM_sys_cdo"
1645    return 0
1646  fi
1647
1648  IGCM_debug_PopStack "IGCM_sys_cdo"
1649}
1650
1651############################################################
1652# Activate Running Environnment Variables
1653
1654function IGCM_sys_activ_variables {
1655  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1656  if ( $DEBUG_sys ) ; then
1657    echo "IGCM_sys_activ_variables"
1658  fi
1659  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1660}
1661
1662############################################################
1663# Desactivate Running Environnment Variables
1664
1665function IGCM_sys_desactiv_variables {
1666  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1667  if ( $DEBUG_sys ) ; then
1668    echo "IGCM_sys_desactiv_variables"
1669  fi
1670  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1671}
1672
1673############################################################
1674# Build run file
1675
1676function IGCM_sys_build_run_file {
1677  IGCM_debug_PushStack "IGCM_sys_build_run_file"
1678  if ( $DEBUG_sys ) ; then
1679    echo "IGCM_sys_build_run_file"
1680  fi
1681  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1682}
Note: See TracBrowser for help on using the repository browser.