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

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

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

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