source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_cesium.ksh @ 545

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