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
RevLine 
[141]1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
[373]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
[141]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
[217]65# $hostname ou hostname
[228]66typeset  HOST=${HOST:=$( hostname )}
[141]67# $username ou whoami
[228]68typeset  LOGIN=${LOGIN:=$( whoami )}
[141]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
[192]78typeset -r RSYNC_opt="-va"
[141]79# ie storage filesystem
[192]80typeset -r RHOST=cesium
[141]81
82#====================================================
[305]83# Source default environment
[141]84#====================================================
[184]85. /etc/profile
[141]86
87#====================================================
[305]88# Set environment tools (ferret, nco, cdo)
[141]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
[545]119typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
[438]120typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
[141]121
122#====================================================
[544]123#- R_OUT
[141]124typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
125
126#====================================================
[544]127#- R_BUF (ONLY FOR double copy an scratch)
128typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
[141]129
130#====================================================
131#- OUT_POST
132typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
133
134#====================================================
135#- RUN_DIR_PATH : Temporary working directory (=> TMP)
[331]136PBS_JOBID=${PBS_JOBID:=TEMPDIR$$}
[196]137typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/${PBS_JOBID}}
[141]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
[192]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.
[141]150#D-* Examples:
151#D-
152function IGCM_sys_RshMaster {
[544]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
[192]163    export libIGCM=${libIGCM_SX}
[141]164    export DEBUG_debug=${DEBUG_debug}
[192]165    . ${libIGCM_SX}/libIGCM_debug/libIGCM_debug.ksh
166    . ${libIGCM_SX}/libIGCM_card/libIGCM_card.ksh
[141]167    ${@}
168EOF
[544]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
[396]179
[544]180  IGCM_debug_PopStack "IGCM_sys_RshMaster"
[141]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 {
[544]189  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
190  /bin/ksh <<-EOF
[141]191    ${@}
192EOF
[544]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"
[141]198}
199
200#D-#==================================================
201#D-function IGCM_sys_RshPost
[343]202#D-* Purpose: Post-process rsh command
[141]203#D-* Examples:
204#D-
205function IGCM_sys_RshPost {
[544]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"
[141]226}
227
228#D-#==================================================
[228]229#D-function IGCM_sys_SendMail
230#D-* Purpose: Send mail when simulation is over
231#D-* Examples:
232#D-
233function IGCM_sys_SendMail {
[544]234  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
235  if ( $DEBUG_sys ) ; then
236    echo "IGCM_sys_SendMail :" $@
237  fi
[228]238
[544]239  if ( ${ExitFlag} ) ; then
240    status=failed
241  else
242    status=completed
243  fi
[452]244
[544]245  ssh mercure <<-EOF
[228]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}
[288]252    export SUBMIT_DIR=${SUBMIT_DIR}
[452]253    export status=${status}
[228]254
255    cat  << END_MAIL > job_end.mail
256Dear ${LOGIN},
257
[452]258  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
[228]259  Job started : ${DateBegin}
260  Job ended   : ${DateEnd}
[434]261  Output files are available in ${R_SAVE}
[453]262  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
[228]263END_MAIL
264
265    if [ ! -z ${config_UserChoices_MailName} ] ; then
[440]266       mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
[228]267    elif [ -f ~/.forward ] ; then
[440]268       mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
[228]269    fi
270    sleep 10
271    rm -f job_end.mail
272EOF
273
[544]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"
[228]279}
280
281#D-#==================================================
[141]282#D-function IGCM_sys_Mkdir
283#D-* Purpose: Master locale mkdir command
284#D-* Examples:
285#D-
286function IGCM_sys_Mkdir {
[544]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"
[141]296    fi
[544]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"
[141]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 {
[544]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"
[141]322    fi
[544]323  fi
324  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
[141]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 {
[544]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"
[141]343    fi
[544]344  fi
345  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
[141]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 {
[544]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"
[141]364}
365
366#D-#==================================================
367#D-function IGCM_sys_Chmod
368#D-* Purpose: Chmod
369#D-* Examples:
370#D-
371function IGCM_sys_Chmod {
[544]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"
[141]381    fi
[544]382  else
383    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
384  fi
385  IGCM_debug_PopStack "IGCM_sys_Chmod"
[141]386}
387
388#D-#==================================================
389#D-function IGCM_sys_FileSize
390#D-* Purpose: Filesize
391#D-* Examples:
392#D-
393function IGCM_sys_FileSize {
[544]394  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
[141]395
[544]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]}
[141]402
[544]403  IGCM_debug_PopStack "IGCM_sys_FileSize"
[141]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 {
[544]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"
[141]419
[544]420  return ${ExistFlag}
[141]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 {
[544]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"
[141]436
[544]437  return ${ExistFlag}
[141]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 {
[544]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"
[141]453
[544]454  return ${ExistFlag}
[141]455}
456
457#D-#==================================================
[544]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-#==================================================
[141]472#D-function IGCM_sys_CountFileArchive
473#D-* Purpose: Count files on Archive filesystem
474#D-* Examples:
475#D-
476function IGCM_sys_CountFileArchive {
[544]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"
[141]483}
484
485#D-#==================================================
[544]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-#==================================================
[141]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 {
[544]505  IGCM_debug_PushStack "IGCM_sys_Tree" $@
506  if ( $DEBUG_sys ) ; then
507    echo "IGCM_sys_Tree :" $@
508  fi
[141]509
[544]510  \tree -f $@
[141]511
[544]512  IGCM_debug_PopStack "IGCM_sys_Tree"
[141]513}
514
515#D-#==================================================
516#D-function IGCM_sys_Tar
[544]517#D-* Purpose: master tar command
[141]518#D-* Examples:
519#D-
520function IGCM_sys_Tar {
[544]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"
[141]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 {
[544]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"
[141]549}
550
551#D-#==================================================
[228]552#D-function IGCM_sys_Qsub
553#D-* Purpose: Qsub new job
554#D-* Examples:
555#D-
556function IGCM_sys_Qsub {
[544]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"
[228]567}
568
569#D-#==================================================
[141]570#D-function IGCM_sys_QsubPost
571#D-* Purpose: Qsub new job on scalaire
572#D-* Examples:
573#D-
574function IGCM_sys_QsubPost {
[544]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"
[141]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 {
[544]598  RET=$1
599  if [ ! $RET ] ; then
600    echo "rsync error !"
601  fi
[141]602
[544]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
[141]700}
[544]701
[141]702#D-#==================================================
703#D-function IGCM_sys_Cp
704#D-* Purpose: generic cp
705#D-* Examples:
706#D-
707function IGCM_sys_Cp {
[544]708  IGCM_debug_PushStack "IGCM_sys_Cp" $@
709  if ( $DEBUG_sys ) ; then
710    echo "IGCM_sys_Cp :" $@
711  fi
[141]712
[544]713  typeset RET
[141]714
[544]715  echo cp $@ > out_rsync 2>&1
716  \cp $@ >> out_rsync 2>&1
717  RET=$?
[141]718
[544]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"
[141]727}
728
729#D-#==================================================
730#D-function IGCM_sys_Rm
731#D-* Purpose: generic rm
732#D-* Examples:
733#D-
734function IGCM_sys_Rm {
[544]735  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
736  if ( $DEBUG_sys ) ; then
737    echo "IGCM_sys_Rm :" $@
738  fi
[141]739
[544]740  typeset RET
[141]741
[544]742  echo rm $@ > out_rsync 2>&1
743  \rm $@ >> out_rsync 2>&1
744  RET=$?
[192]745
[544]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"
[141]754}
755
756#D-#==================================================
[203]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 {
[544]763  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
764  if ( $DEBUG_sys ) ; then
765    echo "IGCM_sys_RmRunDir :" $@
766  fi
[203]767
[544]768  typeset RET
[203]769
[544]770  echo rm $@ > out_rsync 2>&1
771  \rm $@ >> out_rsync 2>&1
772  RET=$?
[203]773
[544]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"
[203]782}
783
784#D-#==================================================
[141]785#D-function IGCM_sys_Mv
786#D-* Purpose: generic move
787#D-* Examples:
788#D-
789function IGCM_sys_Mv {
[544]790  IGCM_debug_PushStack "IGCM_sys_Mv" $@
791  if ( $DEBUG_sys ) ; then
792    echo "IGCM_sys_Mv :" $@
793  fi
[141]794
[544]795  if [ $DRYRUN = 0 ]; then
[141]796
[544]797    typeset RET
[173]798   
[544]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"
[173]807    else
[544]808      \rm out_rsync
[141]809    fi
[544]810  else
811    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
812  fi
[141]813
[544]814  IGCM_debug_PopStack "IGCM_sys_Mv"
[141]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 {
[544]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
[141]832    fi
833
[544]834    typeset RET
[141]835
[544]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=$?
[141]842
[544]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"
[141]847    else
[544]848      \rm out_rsync
[141]849    fi
[544]850  else
851    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
852  fi
853  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
[141]854}
855
856#D-#==================================================
857#D-function IGCM_sys_Get_Dir
[544]858#D-* Purpose: Copy a complete directory from ${ARCHIVE}
[141]859#D-* Examples:
860#D-
861function IGCM_sys_Get_Dir {
[544]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
[141]872
[544]873    typeset RET
[141]874
[544]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=$?
[141]883
[544]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"
[141]888    else
[544]889      \rm out_rsync
[141]890    fi
[544]891  else
892    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
893  fi
894  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
[141]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 {
[544]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
[141]916    fi
[387]917
[544]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
[387]925            #USUAL WAY
[544]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
[141]937
[544]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"
[141]942    else
[544]943      \rm out_rsync
[141]944    fi
[544]945  else
946    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
947  fi
948  IGCM_debug_PopStack "IGCM_sys_Get_Master"
[141]949}
950
951#D-#==================================================
[228]952#D-function IGCM_sys_Put_Rest
[544]953#D-* Purpose: Put computied restarts on ${ARCHIVE}.
[228]954#D-           File and target directory must exist.
955#D-* Examples:
956#D-
957function IGCM_sys_Put_Rest {
[544]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"
[228]966    fi
967
[544]968    typeset RET
969    #
970    if [ X${JobType} = XRUN ] ; then
971      IGCM_sys_Chmod 444 ${1}
972    fi
[228]973
[544]974    #
975    # USUAL WAY
976    \cp $1 $2 > out_rsync 2>&1
977    RET=$?
978
[228]979#       #RSYNC WITH NETWORK SSH CALL
[544]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
[228]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
[544]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"
[228]997    else
[544]998      \rm out_rsync
[228]999    fi
[544]1000  else
1001    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1002  fi
1003  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
[228]1004}
1005
1006#D-#==================================================
[141]1007#D-function IGCM_sys_Put_Out
[544]1008#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
[141]1009#D-* Examples:
1010#D-
1011function IGCM_sys_Put_Out {
[544]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
[141]1021    fi
[544]1022    #
1023    IGCM_sys_MkdirArchive $( dirname $2 )
1024    #
1025    typeset RET exist skip
[228]1026
[544]1027    #=====================================================
1028    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1029    #=====================================================
[228]1030
[544]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
[228]1040
[544]1041    if [ X${JobType} = XRUN ] ; then
1042      if [ X${3} = X ] ; then
1043        IGCM_sys_Chmod 444 ${1}
1044      fi
1045    fi
[141]1046
[544]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"
[360]1058        skip=false
[544]1059      fi
1060    fi
[358]1061        #
[544]1062    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1063      IGCM_sys_Chmod u+w $2
1064    fi
[358]1065        # USUAL WAY
[544]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
[358]1077
[141]1078#       #RSYNC WITH NETWORK RSH CALL
[192]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
[141]1081
1082#       #RSYNC WITH NFS USE
[192]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
[141]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
[358]1092
[544]1093  else
1094    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1095  fi
1096  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1097  return 0
[141]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 {
[544]1106  IGCM_debug_PushStack "IGCM_sys_Get" $@
[141]1107
[544]1108  typeset DEST RET dm_liste ifile target file_work
[141]1109
[544]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}
[141]1119    fi
[544]1120    eval DEST=\${${#}}
[141]1121
[544]1122    #=====================================================
1123    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1124    #=====================================================
[141]1125
[544]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
[141]1137
[544]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
[141]1145
[544]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
[520]1153
[544]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
[141]1173
[544]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
[520]1186
[228]1187#       #RSYNC WITH NETWORK SSH CALL
[192]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
[141]1190
1191#       #RSYNC WITH NFS USE
[192]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
[141]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
[544]1201    if [ ${RET} -gt 0 ] ; then
1202      echo "IGCM_sys_Get : copy error."
1203      cat out_rsync
1204      IGCM_debug_Exit "IGCM_sys_Get"
[141]1205    else
[544]1206      \rm out_rsync
[141]1207    fi
[544]1208  else
1209    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1210  fi
1211  IGCM_debug_PopStack "IGCM_sys_Get"
[141]1212}
1213
1214#D-#==================================================
[544]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-#==================================================
[343]1290#D-function IGCM_sys_Dods_Rm
[544]1291#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
[343]1292#D-* Examples:
1293#D-
1294function IGCM_sys_Dods_Rm {
[544]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
[343]1305    fi
[544]1306    dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1307    RET=$?
1308   
[418]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
[544]1317  else
1318    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1319  fi
1320  return $RET
[343]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 {
[544]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
[343]1339    fi
[544]1340    #
1341    dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1342    RET=$?
1343
[348]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
[418]1351
[544]1352  else
1353    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1354  fi
1355  return $RET
[343]1356}
1357
1358#D-#==================================================
[141]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 {
[544]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
[141]1373    fi
1374
[544]1375    typeset RET
[141]1376        #
[544]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"
[141]1385    fi
[544]1386  else
1387    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1388  fi
1389  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
[141]1390}
1391
[544]1392##############################################################
1393# REBUILD OPERATOR
[141]1394
[544]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"
[141]1407}
1408
[544]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"
[141]1419}
1420
[544]1421############################################################
1422# Desactivate Running Environnment Variables
[141]1423
[544]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}
[141]1431
[544]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"
[141]1441}
1442
1443##############################################################
1444# NCO OPERATOR
1445
[377]1446function IGCM_sys_ncap2 {
[544]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
[141]1456
[544]1457  IGCM_debug_PopStack "IGCM_sys_ncap2"
[141]1458}
1459
[375]1460function IGCM_sys_ncatted {
[544]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
[141]1470
[544]1471  IGCM_debug_PopStack "IGCM_sys_ncatted"
[375]1472}
[141]1473
1474function IGCM_sys_ncbo {
[544]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
[141]1484
[544]1485  IGCM_debug_PopStack "IGCM_sys_ncbo"
[141]1486}
1487
1488function IGCM_sys_ncdiff {
[544]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
[141]1498
[544]1499  IGCM_debug_PopStack "IGCM_sys_ncdiff"
[141]1500}
1501
1502function IGCM_sys_ncea {
[544]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
[141]1512
[544]1513  IGCM_debug_PopStack "IGCM_sys_ncea"
[141]1514}
1515
1516function IGCM_sys_ncecat {
[544]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
[141]1526
[544]1527  IGCM_debug_PopStack "IGCM_sys_ncecat"
[141]1528}
1529
1530function IGCM_sys_ncflint {
[544]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
[141]1540
[544]1541  IGCM_debug_PopStack "IGCM_sys_ncflint"
[141]1542}
1543
1544function IGCM_sys_ncks {
[544]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
[141]1554
[544]1555  IGCM_debug_PopStack "IGCM_sys_ncks"
[141]1556}
1557
1558function IGCM_sys_ncpdq {
[544]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
[141]1568
[544]1569  IGCM_debug_PopStack "IGCM_sys_ncpdq"
[141]1570}
1571
1572function IGCM_sys_ncra {
[544]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
[141]1582
[544]1583  IGCM_debug_PopStack "IGCM_sys_ncra"
[141]1584}
1585
1586function IGCM_sys_ncrcat {
[544]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 ${@}."
[141]1594#       IGCM_debug_Exit "ncrcat"
[544]1595  fi
[141]1596
[544]1597  IGCM_debug_PopStack "IGCM_sys_ncrcat"
[141]1598}
1599
1600function IGCM_sys_ncrename {
[544]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
[141]1610
[544]1611  IGCM_debug_PopStack "IGCM_sys_ncrename"
[141]1612}
1613
1614function IGCM_sys_ncwa {
[544]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
[141]1624
[544]1625  IGCM_debug_PopStack "IGCM_sys_ncwa"
[141]1626}
1627
[305]1628##############################################################
1629# CDO OPERATOR
1630
1631function IGCM_sys_cdo {
[544]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 ${@}."
[305]1639    IGCM_debug_PopStack "IGCM_sys_cdo"
[544]1640    return 1
1641  else
1642    IGCM_debug_PopStack "IGCM_sys_cdo"
1643    return 0
1644  fi
[305]1645
[544]1646  IGCM_debug_PopStack "IGCM_sys_cdo"
[141]1647}
Note: See TracBrowser for help on using the repository browser.