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

Last change on this file since 548 was 548, checked in by sdipsl, 12 years ago

Bugfix : when retrieving input ifiles from another filesystem than /dmnfs you must not use dmget ... it hangs forever ...

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