source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh @ 115

Last change on this file since 115 was 98, checked in by sdipsl, 15 years ago
  • Try to avoid having stack files every where during post-processing job.
File size: 33.4 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Christian Laguerre
5# Contact: Martial.Mancip_ipsl.jussieu.fr
6# $Date: 2008-05-29 21:29:09 +0200 (Thu, 29 May 2008) $
7# $Author: laguerre $
8# $Revision: 7 $
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11# History:
12# Modification:
13#
14#**************************************************************
15
16#=========================================================
17# The documentation of this file can be automatically generated
18# if you use the prefix #D- for comments to be extracted.
19# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
20#=========================================================
21
22#D-#==================================================
23#D-LibIGCM_sys for obelix
24#D-#==================================================
25#D-
26#D- This ksh library if a layer under some usefull
27#D-environment variables and shell commands.
28#D-All those definitions depend on host particularities.
29#D-It manages a stack mechanism and test validity of operations.
30#D-All function described bellow must be prefixed by IGCM_sys.
31
32#====================================================
33# libIGCM_sys PARAMETERS
34#====================================================
35
36#=====================================================
37# set DEBUG_sys to true to output calls of function
38typeset -r DEBUG_sys=${DEBUG_sys:=true}
39
40#=====================================================
41# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
42typeset -r DRYRUN=${DRYRUN:=0}
43
44# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
45# -------------------------------------------------------------------------------------
46# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
47# |          |  Cp/Exe param files |            |  Chmod  |                           |
48# |          |      Qsub           |            |         |                           |
49# -------------------------------------------------------------------------------------
50# |    0     |       yes           |    yes     |  yes    |      yes                  |
51# -------------------------------------------------------------------------------------
52# |    1     |       yes           |    yes     |  yes    |      no                   |
53# -------------------------------------------------------------------------------------
54# |    2     |       yes           |    yes     |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56# |    3     |       yes           |    no      |  no     |      no                   |
57# -------------------------------------------------------------------------------------
58
59#=====================================================
60# Global Variables :
61#=====================================================
62# Language : "fr" or "en"
63typeset -r MYLANG="fr"
64
65#=====================================================
66# Host and user names
67# $hostname ou hostname
68typeset -r HOST=$( hostname )
69# $username ou whoami
70typeset -r LOGIN=$( whoami )
71# $hostname of the MASTER job
72typeset -r MASTER=obelix
73
74#D-
75#D-#==================================================
76#D-Program used in libIGCM
77#D-#==================================================
78
79# rsync with path
80typeset -r RSYNC=/usr/bin/rsync
81# RSYNC_opt args to rsync
82typeset -r RSYNC_opt="-Lt -v"
83
84#====================================================
85# Source Ferret
86. /home/users/brock/.atlas_env_asterix_ksh
87
88#=========================================================
89# Host specific DIRECTORIES
90#====================================================
91
92#====================================================
93#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
94typeset -r R_EXE="${MODIPSL}/bin"
95
96#====================================================
97#- SCRATCHDIR (=> ${R_DONNEES})
98typeset -r SCRATCHDIR=/tmp
99
100#====================================================
101#- SUBMIT_DIR : submission dir
102typeset SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
103#====================================================
104#- ARCHIVE
105typeset -r ARCHIVE=/home/scratch01/${LOGIN}
106
107#====================================================
108#- libIGCM_POST
109typeset -r libIGCM_POST=${libIGCM}
110
111#====================================================
112#- IN
113typeset -r R_IN=${R_IN:=${ARCHIVE}/${LOGIN}/IGCM}
114
115#====================================================
116#- OUT
117typeset -r R_OUT=${ARCHIVE}/${LOGIN}/IGCM_OUT
118
119#====================================================
120#- OUT_POST
121typeset -r R_OUT_POST=${R_OUT}
122
123#====================================================
124#- RUN_DIR_PATH : Temporary working directory (=> TMP)
125typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/tmp$$}
126#typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/home/orchidee_ns/${LOGIN}/tmp$$}
127
128#====================================================
129#- HOST_MPIRUN_COMMAND
130typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
131
132#=========================================================
133#- Add "time" before mpirun command
134MPIRUN_COMMAND="time "${MPIRUN_COMMAND}
135echo ${MPIRUN_COMMAND}
136
137#====================================================
138#- Max number of arguments passed to nco operator or demigration command
139UNIX_MAX_LIMIT=360
140
141#D-#==================================================
142#D-function IGCM_sys_RshMaster
143#D-* Purpose: Master rsh command
144#D-* Examples:
145#D-
146function IGCM_sys_RshMaster {
147    IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
148    ssh ${HOST} /bin/ksh  <<-EOF
149    export libIGCM=${libIGCM}
150    export DEBUG_debug=${DEBUG_debug}
151    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
152    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
153    ${@}
154EOF
155    if [ $? -gt 0 ] ; then
156        echo "IGCM_sys_RshMaster : erreur."
157        IGCM_debug_Exit "IGCM_sys_RshMaster"
158    fi
159    IGCM_debug_PopStack "IGCM_sys_RshMaster"
160}
161
162#D-#==================================================
163#D-function IGCM_sys_RshArchive
164#D-* Purpose: Archive rsh command
165#D-* Examples:
166#D-
167function IGCM_sys_RshArchive {
168    IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
169    /bin/ksh <<-EOF
170    ${@}
171EOF
172    if [ $? -gt 0 ] ; then
173        echo "IGCM_sys_RshArchive : erreur."
174        IGCM_debug_Exit "IGCM_sys_RshArchive"
175    fi
176    IGCM_debug_PopStack "IGCM_sys_RshArchive"
177}
178
179#D-#==================================================
180#D-function IGCM_sys_RshPost
181#D-* Purpose: Master rsh command
182#D-* Examples:
183#D-
184(( RshPNum = 0 ))
185function IGCM_sys_RshPost {
186    IGCM_debug_PushStack "IGCM_sys_RshPost" $@
187    if ( $DEBUG_sys ) ; then
188        echo "IGCM_sys_RshPost :" $@
189    fi
190    #ssh ${HOST} exec /bin/ksh -vx $@ > out_RshPost.${RshPNum}
191    ssh ${HOST} exec /bin/ksh $@ > out_RshPost.${RshPNum}
192    if [ $? -gt 0 ] ; then
193        echo "IGCM_sys_RshPost : erreur."
194        IGCM_debug_Exit "IGCM_sys_RshPost"
195    fi
196    (( RshPNum = RshPNum + 1 ))
197    IGCM_debug_PopStack "IGCM_sys_RshPost"
198}
199
200#D-#==================================================
201#D-function IGCM_sys_Mkdir
202#D-* Purpose: Master locale mkdir command
203#D-* Examples:
204#D-
205function IGCM_sys_Mkdir {
206    IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
207    if ( $DEBUG_sys ) ; then
208        echo "IGCM_sys_Mkdir :" $@
209    fi
210    if [ ! -d ${1} ]; then
211        \mkdir -p $1
212        if [ $? -gt 0 ] ; then
213            echo "IGCM_sys_Mkdir : erreur."
214            IGCM_debug_Exit "IGCM_sys_Mkdir"
215        fi
216    fi
217    # vérification :
218    if [ ! -d ${1} ] ; then
219        echo "IGCM_sys_Mkdir : erreur."
220        IGCM_debug_Exit "IGCM_sys_Mkdir"
221    fi
222    IGCM_debug_PopStack "IGCM_sys_Mkdir"
223}
224
225#D-#==================================================
226#D-function IGCM_sys_MkdirArchive
227#D-* Purpose: Mkdir on Archive
228#D-* Examples:
229#D-
230function IGCM_sys_MkdirArchive {
231    IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
232    if ( $DEBUG_sys ) ; then
233        echo "IGCM_sys_MkdirArchive :" $@
234    fi
235    #- creation de repertoire sur le serveur fichier
236    if [ ! -d ${1} ]; then 
237        \mkdir -p $1
238        if [ $? -gt 0 ] ; then
239            echo "IGCM_sys_MkdirArchive : erreur."
240            IGCM_debug_Exit "IGCM_sys_MkdirArchive"
241        fi
242    fi
243#    vérification ?? :
244    if [ ! -d ${1} ] ; then
245        echo "IGCM_sys_MkdirArchive : erreur."
246        IGCM_debug_Exit "IGCM_sys_MkdirArchive"
247    fi
248    IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
249}
250
251#D-#==================================================
252#D-function IGCM_sys_MkdirWork
253#D-* Purpose: Mkdir on Work
254#D-* Examples:
255#D-
256function IGCM_sys_MkdirWork {
257    IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
258    if ( $DEBUG_sys ) ; then
259        echo "IGCM_sys_MkdirWork :" $@
260    fi
261    #- creation de repertoire sur le serveur fichier
262    if [ ! -d ${1} ]; then 
263        \mkdir -p $1
264        if [ $? -gt 0 ] ; then
265            echo "IGCM_sys_MkdirWork : erreur."
266            IGCM_debug_Exit "IGCM_sys_MkdirWork"
267        fi
268    fi
269    # vérification ?? :
270    if [ ! -d ${1} ] ; then
271        echo "IGCM_sys_MkdirWork : erreur."
272        IGCM_debug_Exit "IGCM_sys_MkdirWork"
273    fi
274    IGCM_debug_PopStack "IGCM_sys_MkdirWork"
275}
276IGCM_sys_MkdirWork ${RUN_DIR_PATH}
277echo "RUN_DIR_PATH ${RUN_DIR_PATH} ok."
278
279#D-#==================================================
280#D-function IGCM_sys_Cd
281#D-* Purpose: master cd command
282#D-* Examples:
283#D-
284function IGCM_sys_Cd {
285    IGCM_debug_PushStack "IGCM_sys_Cd" $@
286    if ( $DEBUG_sys ) ; then
287        echo "IGCM_sys_Cd :" $@
288    fi
289    \cd $1
290    if [ $? -gt 0 ] ; then
291        echo "IGCM_sys_Cd : erreur."
292        IGCM_debug_Exit "IGCM_sys_Cd"
293    fi
294    IGCM_debug_PopStack "IGCM_sys_Cd"
295}
296
297#D-#==================================================
298#D-function IGCM_sys_Chmod
299#D-* Purpose: Chmod
300#D-* Examples:
301#D-
302function IGCM_sys_Chmod {
303    IGCM_debug_PushStack "IGCM_sys_Chmod" $@
304    if ( $DEBUG_sys ) ; then
305        echo "IGCM_sys_Chmod :" $@
306    fi
307    if [ $DRYRUN -le 1 ]; then
308        \chmod $@
309        if [ $? -gt 0 ] ; then
310            echo "IGCM_sys_Chmod : erreur."
311            IGCM_debug_Exit "IGCM_sys_Chmod"
312        fi
313    else
314        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
315    fi
316    IGCM_debug_PopStack "IGCM_sys_Chmod"
317}
318
319#D-#==================================================
320#D-function IGCM_sys_FileSize
321#D-* Purpose: Filesize
322#D-* Examples:
323#D-
324function IGCM_sys_FileSize {
325    IGCM_debug_PushStack "IGCM_sys_FileSize" $@
326
327    typeset sizeF
328    set +A sizeF -- $( ls -la ${1} )
329    if [ $? -gt 0 ] ; then
330        IGCM_debug_Exit "IGCM_sys_FileSize"
331    fi
332    eval ${2}=${sizeF[4]}
333
334    IGCM_debug_PopStack "IGCM_sys_FileSize"
335}
336
337#D-#==================================================
338#D-function IGCM_sys_TestDir
339#D-* Purpose: Test Directory that must exists
340#D-* Examples:
341#D-
342function IGCM_sys_TestDir {
343    IGCM_debug_PushStack "IGCM_sys_TestDir" $@
344    if ( $DEBUG_sys ) ; then
345        echo "IGCM_sys_TestDir :" $@
346    fi
347    typeset ExistFlag
348    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
349    IGCM_debug_PopStack "IGCM_sys_TestDir"
350
351    return ${ExistFlag}
352}
353
354#D-#==================================================
355#D-function IGCM_sys_TestDirArchive
356#D-* Purpose: Test Directory that must exists on Archive
357#D-* Examples:
358#D-
359function IGCM_sys_TestDirArchive {
360    IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
361    if ( $DEBUG_sys ) ; then
362        echo "IGCM_sys_TestDirArchive :" $@
363    fi
364    typeset ExistFlag
365    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
366    IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
367
368    return ${ExistFlag}
369}
370
371#D-#==================================================
372#D-function IGCM_sys_TestFileArchive
373#D-* Purpose: Test file that must NOT EXISTS on Archive
374#D-* Examples:
375#D-
376function IGCM_sys_TestFileArchive {
377    IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
378    if ( $DEBUG_sys ) ; then
379        echo "IGCM_sys_TestFileArchive :" $@
380    fi
381    typeset ExistFlag
382    ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
383    IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
384
385    return ${ExistFlag}
386}
387
388#D-#==================================================
389#D-function IGCM_sys_CountFileArchive
390#D-* Purpose: Count files on Archive filesystem
391#D-* Examples:
392#D-
393function IGCM_sys_CountFileArchive {
394    IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
395    ls ${@} 2>/dev/null | wc -l
396    if [ $? -gt 0 ] ; then
397        echo "IGCM_sys_CountFileArchive : erreur."
398    fi
399    IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
400}
401
402#D-#==================================================
403#D-function IGCM_sys_Tree
404#D-* Purpose: Tree directories with files on ${ARCHIVE}
405#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
406#D-
407function IGCM_sys_Tree {
408    IGCM_debug_PushStack "IGCM_sys_Tree" $@
409    if ( $DEBUG_sys ) ; then
410        echo "IGCM_sys_Tree :" $@
411    fi
412
413    \tree -f $@
414
415    IGCM_debug_PopStack "IGCM_sys_Tree"
416}
417
418#D-#==================================================
419#D-function IGCM_sys_Tar
420#D-* Purpose: master un-tar command
421#D-* Examples:
422#D-
423function IGCM_sys_Tar {
424    IGCM_debug_PushStack "IGCM_sys_Tar" $@
425    if ( $DEBUG_sys ) ; then
426        echo "IGCM_sys_Tar :" $@
427    fi
428    \tar cvf $@
429    if [ $? -gt 0 ] ; then
430        echo "IGCM_sys_Tar : erreur."
431        IGCM_debug_Exit "IGCM_sys_Tar"
432    fi
433    \tar tvf $1
434
435    IGCM_debug_PopStack "IGCM_sys_Tar"
436}
437
438#D-#==================================================
439#D-function IGCM_sys_UnTar
440#D-* Purpose: master un-tar command
441#D-* Examples:
442#D-
443function IGCM_sys_UnTar {
444    IGCM_debug_PushStack "IGCM_sys_UnTar" $@
445    if ( $DEBUG_sys ) ; then
446        echo "IGCM_sys_UnTar :" $@
447    fi
448    \tar xvf $1
449    if [ $? -gt 0 ] ; then
450        echo "IGCM_sys_UnTar : erreur."
451        IGCM_debug_Exit "IGCM_sys_UnTar"
452    fi
453    IGCM_debug_PopStack "IGCM_sys_UnTar"
454}
455
456#D-#==================================================
457#D-function IGCM_sys_Qsub
458#D-* Purpose: Qsub new job
459#D-* Examples:
460#D-
461function IGCM_sys_Qsub {
462    IGCM_debug_PushStack "IGCM_sys_Qsub" $@
463    if ( $DEBUG_sys ) ; then
464        echo "IGCM_sys_Qsub :" $@
465    fi
466    /usr/local/bin/qsub -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} < $1
467    if [ $? -gt 0 ] ; then
468        echo "IGCM_sys_Qsub : erreur -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} $@."
469        IGCM_debug_Exit "IGCM_sys_Qsub"
470    fi
471    IGCM_debug_PopStack "IGCM_sys_Qsub"
472}
473
474#D-#==================================================
475#D-function IGCM_sys_QsubPost
476#D-* Purpose: Qsub new job on scalaire
477#D-* Examples:
478#D-
479function IGCM_sys_QsubPost {
480    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
481    if ( $DEBUG_sys ) ; then
482        echo "IGCM_sys_QsubPost :" $@
483    fi
484    /usr/local/bin/qsub -q medium -o ${POST_DIR}/$1.${PeriodDateEnd}.out ${libIGCM_POST}/$1.job -v ${listVarEnv}
485    if [ $? -gt 0 ] ; then
486        echo "IGCM_sys_QsubPost : erreur " $@
487        IGCM_debug_Exit "IGCM_sys_QsubPost"
488    fi
489    IGCM_debug_PopStack "IGCM_sys_QsubPost"
490}
491
492#D-*************************
493#D- File transfer functions
494#D-*************************
495#D-
496
497#D-#==================================================
498#D-function IGCM_sys_Rsync_out
499#D-* Purpose: treat return val of rsync
500#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
501#D-  Error values and explanations can depend on your system version.
502function IGCM_sys_Rsync_out {
503    RET=$1
504    if [ ! $RET ] ; then
505        echo "rsync error !"
506    fi
507
508    if [ $MYLANG = "fr" ]; then
509        case $RET in
510            0)  return ;;
511            1)  echo "Erreur de rsync ; RERR_SYNTAX : "
512                echo "Erreur de syntaxe ou d'utilisation."
513                return;;
514            2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
515                echo "Incompatibilité de protocole."
516                return;;
517            3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
518                echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
519                echo "répertoires"
520                return;;
521            4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
522                echo "Action demandée non supportée : une tentative de manipulation de"
523                echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
524                echo "été faite ; ou une option qui est supportée par le  client  mais"
525                echo "pas par le serveur a été spécifiée."
526                return;;
527            10) echo "Erreur de rsync ; RERR_SOCKETIO"
528                echo "Erreur dans le socket d'entrée sortie"
529                return;;
530            11) echo "Erreur de rsync ; RERR_FILEIO"
531                echo "Erreur d'entrée sortie fichier"
532                return;;
533            12) echo "Erreur de rsync ; RERR_STREAMIO"
534                echo "Erreur dans flux de donnée du protocole rsync"
535                return;;
536            13) echo "Erreur de rsync ; RERR_MESSAGEIO"
537                echo "Erreur avec les diagnostics du programme"
538                return;;
539            14) echo "Erreur de rsync ; RERR_IPC"
540                echo "Erreur dans le code IPC"
541                return;;
542            20) echo "Erreur de rsync ; RERR_SIGNAL"
543                echo "SIGUSR1 ou SIGINT reçu"
544                return;;
545            21) echo "Erreur de rsync ; RERR_WAITCHILD"
546                echo "Une erreur retournée par waitpid()"
547                return;;
548            22) echo "Erreur de rsync ; RERR_MALLOC"
549                echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
550                return;;
551            23) echo ""
552                echo "Erreur fichier inexistant"
553                return;;
554            30) echo "Erreur de rsync ; RERR_TIMEOUT"
555                echo "Temps d'attente écoulé dans l'envoi/réception de données"
556                return;;
557            *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
558                return;;
559        esac
560    elif [ $MYLANG = "en" ] ; then
561        case $RET in
562            0)  return;;               
563            1)  echo "rsync error : Syntax or usage error "
564                return;;
565            2)  echo "rsync error : Protocol incompatibility "
566                return;;
567            3)  echo "rsync error : Errors selecting input/output files, dirs"
568                return;;
569            4)  echo "rsync error : Requested action not supported: an attempt"
570                echo "was made to manipulate 64-bit files on a platform that cannot support"
571                echo "them; or an option was specified that is supported by the client and"
572                echo "not by the server."
573                return;;
574            5)  echo "rsync error : Error starting client-server protocol"
575                return;;
576            10) echo "rsync error : Error in socket I/O "
577                return;;
578            11) echo "rsync error : Error in file I/O "
579                return;;
580            12) echo "rsync error : Error in rsync protocol data stream "
581                return;;
582            13) echo "rsync error : Errors with program diagnostics "
583                return;;
584            14) echo "rsync error : Error in IPC code "
585                return;;
586            20) echo "rsync error : Received SIGUSR1 or SIGINT "
587                return;;
588            21) echo "rsync error : Some error returned by waitpid() "
589                return;;
590            22) echo "rsync error : Error allocating core memory buffers "
591                return;;
592            23) echo "rsync error : Partial transfer due to error"
593                return;;
594            24) echo "rsync error : Partial transfer due to vanished source files"
595                return;;
596            30) echo "rsync error : Timeout in data send/receive "
597                return;;
598            *)  echo "rsync error : return code of rsync unknown :" $RET
599                return;;
600        esac
601    else
602        echo "unknown language $MYLANG."
603        return
604    fi
605}
606   
607#D-#==================================================
608#D-function IGCM_sys_Cp
609#D-* Purpose: generic cp
610#D-* Examples:
611#D-
612function IGCM_sys_Cp {
613    IGCM_debug_PushStack "IGCM_sys_Cp" $@
614    if ( $DEBUG_sys ) ; then
615        echo "IGCM_sys_Cp :" $@
616    fi
617
618    typeset RET
619
620    echo cp --preserve=timestamps $@ > out_rsync 2>&1
621    \cp --preserve=timestamps $@ >> out_rsync 2>&1
622    RET=$?
623   
624    if [ ${RET} -gt 0 ] ; then
625        echo "IGCM_sys_Cp : error."
626        cat out_rsync
627        IGCM_debug_Exit "IGCM_sys_Cp"
628    fi
629    IGCM_debug_PopStack "IGCM_sys_Cp"
630}
631
632#D-#==================================================
633#D-function IGCM_sys_Rm
634#D-* Purpose: generic rm
635#D-* Examples:
636#D-
637function IGCM_sys_Rm {
638    IGCM_debug_PushStack "IGCM_sys_Rm" $@
639    if ( $DEBUG_sys ) ; then
640        echo "IGCM_sys_Rm :" $@
641    fi
642
643    typeset RET
644
645    echo rm $@ > out_rsync 2>&1
646    \rm $@ >> out_rsync 2>&1
647    RET=$?
648   
649    if [ ${RET} -gt 0 ] ; then
650        echo "IGCM_sys_Rm : error."
651        cat out_rsync
652        IGCM_debug_Exit "IGCM_sys_Rm"
653    fi
654    IGCM_debug_PopStack "IGCM_sys_Rm"
655}
656
657#D-#==================================================
658#D-function IGCM_sys_Mv
659#D-* Purpose: generic move
660#D-* Examples:
661#D-
662function IGCM_sys_Mv {
663    IGCM_debug_PushStack "IGCM_sys_Mv" $@
664    if ( $DEBUG_sys ) ; then
665        echo "IGCM_sys_Mv :" $@
666    fi
667
668    typeset RET
669
670    echo mv $@ > out_rsync 2>&1
671    \mv $@ >> out_rsync 2>&1
672    RET=$?
673   
674    if [ ${RET} -gt 0 ] ; then
675        echo "IGCM_sys_Mv : error in mv."
676        cat out_rsync
677        IGCM_debug_Exit "IGCM_sys_Mv"
678    fi
679
680    IGCM_debug_PopStack "IGCM_sys_Mv"
681}
682
683#D-#==================================================
684#D-function IGCM_sys_Put_Dir
685#D-* Purpose: Copy a complete directory on $(ARCHIVE)
686#D-* Examples:
687#D-
688function IGCM_sys_Put_Dir {
689    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
690    if ( $DEBUG_sys ) ; then
691        echo "IGCM_sys_Put_Dir :" $@
692    fi
693    if [ $DRYRUN = 0 ]; then
694        if [ ! -d ${1} ] ; then
695            echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
696            IGCM_debug_PopStack "IGCM_sys_Put_Dir"
697            return
698        fi
699
700        typeset RET
701
702        # Only if we use rsync
703        #IGCM_sys_TestDirArchive $( dirname $2 )
704        #
705        #USUAL WAY
706        \cp -R $1 $2 > out_rsync 2>&1
707        RET=$?
708
709        if [ ${RET} -gt 0 ] ; then
710            echo "IGCM_sys_Put_Dir : error."
711            cat out_rsync
712            IGCM_debug_Exit "IGCM_sys_Put_Dir"
713        fi
714    else
715        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
716    fi
717    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
718}
719
720#D-#==================================================
721#D-function IGCM_sys_Get_Dir
722#D-* Purpose: Copy a complete directory from $(ARCHIVE)
723#D-* Examples:
724#D-
725function IGCM_sys_Get_Dir {
726    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
727    if ( $DEBUG_sys ) ; then
728        echo "IGCM_sys_Get_Dir :" $@
729    fi
730    if [ $DRYRUN = 0 ]; then
731        if [ ! -d ${1} ] ; then
732            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
733            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
734            return
735        fi
736
737        typeset RET
738
739        #USUAL WAY
740        \cp -R $1 $2 > out_rsync 2>&1
741        RET=$?
742
743        if [ ${RET} -gt 0 ] ; then
744            echo "IGCM_sys_Get_Dir : error."
745            cat out_rsync
746            IGCM_debug_Exit "IGCM_sys_Get_Dir"
747        fi
748    else
749        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
750    fi
751    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
752}
753
754#D-#==================================================
755#D-function IGCM_sys_Get_Master
756#D-* Purpose: Copy a complete directory from MASTER filesystem
757#D-* Examples:
758#D-
759function IGCM_sys_Get_Master {
760    IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
761    if ( $DEBUG_sys ) ; then
762        echo "IGCM_sys_Get_Master :" $@
763    fi
764    if [ $DRYRUN = 0 ]; then
765        if [ ! -d ${1} ] ; then
766            echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
767            IGCM_debug_PopStack "IGCM_sys_Get_Master"
768            return
769        fi
770
771        typeset RET
772        sleep 60
773
774        #USUAL WAY
775        cp -R $1 $2 > out_rsync 2>&1
776        RET=$?
777
778        if [ ${RET} -gt 0 ] ; then
779            echo "IGCM_sys_Get_Master : error."
780            cat out_rsync
781            IGCM_debug_Exit "IGCM_sys_Get_Master"
782        fi
783    else
784        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
785    fi
786    IGCM_debug_PopStack "IGCM_sys_Get_Master"
787}
788
789#D-#==================================================
790#D-function IGCM_sys_Put_Rest
791#D-* Purpose: commande de transfert des restarts $(ARCHIVE).
792#D-           Quitte si le fichier ou si le répertoire d'arriver n'existe pas.
793#D-* Examples:
794#D-
795function IGCM_sys_Put_Rest {
796    IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
797    if ( $DEBUG_sys ) ; then
798        echo "IGCM_sys_Put_Rest :" $@
799    fi
800    if [ $DRYRUN = 0 ]; then
801
802        IGCM_sys_TestDirArchive $( dirname $2 )
803
804        if [ ! -f ${1} ] ; then
805            echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
806            IGCM_debug_Exit "IGCM_sys_Put_Rest"
807        fi
808        IGCM_sys_Chmod 444 ${1}
809
810        typeset RET
811
812        echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
813        ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
814        RET=$?
815        IGCM_sys_Rsync_out $RET
816
817        ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
818        (( RET=RET+$? ))
819
820        if [ ${RET} -gt 0 ] ; then
821            echo "IGCM_sys_Put_Rest : error."
822            cat out_rsync
823            IGCM_debug_Exit "IGCM_sys_Put_Rest"
824        fi
825    else
826        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
827    fi
828    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
829}
830
831#D-#==================================================
832#D-function IGCM_sys_Put_Out
833#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
834#D-* Examples:
835#D-
836function IGCM_sys_Put_Out {
837    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
838    if ( $DEBUG_sys ) ; then
839        echo "IGCM_sys_Put_Out :" $@
840    fi
841    if [ $DRYRUN = 0 ]; then
842        if [ -f ${1} ] ; then
843            if [ ! -d $( dirname $2 ) ] ; then
844                IGCM_sys_MkdirArchive $( dirname $2 )
845            fi
846        else
847            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
848            IGCM_debug_PopStack "IGCM_sys_Put_Out"
849            return 1
850        fi
851
852        typeset RET
853        #
854        IGCM_sys_Chmod 444 ${1}
855        #
856
857        echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
858        ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
859        RET=$?
860        IGCM_sys_Rsync_out $RET
861
862        ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
863        (( RET=RET+$? ))
864
865        if [ ${RET} -gt 0 ] ; then
866            echo "IGCM_sys_Put_Out : error."
867            cat out_rsync
868            IGCM_debug_Exit "IGCM_sys_Put_Out"
869        fi
870    else
871        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
872    fi
873    IGCM_debug_PopStack "IGCM_sys_Put_Out"
874    return 0
875}
876
877#D-#==================================================
878#D-function IGCM_sys_Get
879#D-* Purpose: Get a file from ${ARCHIVE}
880#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
881#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
882function IGCM_sys_Get {
883    IGCM_debug_PushStack "IGCM_sys_Get" $@
884
885    typeset DEST RET dm_liste ifile target
886
887    if ( $DEBUG_sys ) ; then
888        echo "IGCM_sys_Get :" $@
889    fi
890    if [ $DRYRUN -le 2 ]; then
891        if [ X${1} = X'/l' ] ; then
892            # test if the first file is present in the old computation :
893            eval set +A dm_liste \${${2}}
894        else
895            dm_liste=${1}
896        fi
897        eval DEST=\${${#}}
898
899        # test if the (first) file is present in the old computation :
900        IGCM_sys_TestFileArchive ${dm_liste[0]}
901        RET=$?
902        if [ ${RET} -gt 0 ] ; then
903            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
904            IGCM_debug_Exit "IGCM_sys_Get"
905            return
906        fi
907
908        (( RET=0 ))
909        for target in ${dm_liste[*]} ; do
910          \cp ${target} ${DEST} >> out_rsync 2>&1
911          (( RET=RET+$? ))
912        done
913
914#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
915#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
916#       RET=$?
917#       IGCM_sys_Rsync_out $RET
918
919#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
920#       (( RET=RET+$? ))
921
922        if [ ${RET} -gt 0 ] ; then
923            echo "IGCM_sys_Get : copy error."
924            cat out_rsync
925            IGCM_debug_Exit "IGCM_sys_Get"
926        fi
927    else
928        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
929    fi
930    IGCM_debug_PopStack "IGCM_sys_Get"
931}
932
933#D-#==================================================
934#D-function IGCM_sys_Put_Dods
935#D-* Purpose: DO NOTHING ! Put $(ARCHIVE) files on DODS internet protocole.
936#D-* Examples:
937#D-
938function IGCM_sys_Put_Dods {
939    IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
940    if ( $DEBUG_sys ) ; then
941        echo "IGCM_sys_Put_Dods :" $@
942    fi
943    if [ $DRYRUN = 0 ]; then
944        if [ ! -f ${1} ] ; then
945            echo "WARNING : IGCM_sys_Put_Dods ${1} DOES NOT EXIST ."
946            IGCM_debug_PopStack "IGCM_sys_Put_Dods"
947            return
948        fi
949        #DO NOTHING
950    else
951        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
952    fi
953    IGCM_debug_PopStack "IGCM_sys_Put_Dods"
954}
955
956############################################################## A REVOIR !!
957
958#D-#==================================================
959#D-function IGCM_sys_Rapatrie
960#D-* Purpose: Rapatrie
961#D-* Examples:
962#D-
963function IGCM_sys_Rapatrie {
964    IGCM_debug_PushStack "IGCM_sys_Rapatrie" $@
965    if ( $DEBUG_sys ) ; then
966        echo "IGCM_sys_Rapatrie :" $@
967    fi
968
969    typeset RET=0
970
971    IGCM_sys_Get ${R_STOCKAGE}/$2 $1 ;
972    let $(( RET=RET+$? ))
973    IGCM_sys_Cd $1 ;
974    let $(( RET=RET+$? ))
975    IGCM_sys_UnTar $2 ;
976    let $(( RET=RET+$? ))
977
978    if [ ${RET} -gt 0 ] ; then
979        echo "IGCM_sys_Rapatrie : erreur."
980        IGCM_debug_Exit "IGCM_sys_Rapatrie"
981    fi
982    IGCM_debug_PopStack "IGCM_sys_Rapatrie"
983}
984
985############################################################## A FINIR !!
986
987#D-#==================================================
988#D-function IGCM_sys_GetDate_FichWork
989#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
990#D-* Examples:
991#D-
992function IGCM_sys_GetDate_FichWork {
993    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
994    if ( $DEBUG_sys ) ; then
995        echo "IGCM_sys_GetDate_FichWork :" $@
996    fi
997    # donne la date filesys d'un fichier sur la machine work
998    IGCM_debug_PopStack "IGCM_sys_FichWork"
999}
1000
1001#D-#==================================================
1002#D-function IGCM_sys_GetDate_FichArchive
1003#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1004#D-* Examples:
1005#D-
1006function IGCM_sys_GetDate_FichArchive {
1007    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1008    if ( $DEBUG_sys ) ; then
1009        echo "IGCM_sys_GetDate_FichArchive :" $@
1010    fi
1011    IGCM_debug_PopStack "IGCM_sys_FichArchive"
1012}
1013
1014
1015##############################################################
1016# REBUILD OPERATOR
1017
1018function IGCM_sys_rebuild {
1019    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1020    if ( $DEBUG_sys ) ; then
1021        echo "IGCM_sys_rebuild :" $@
1022    fi
1023    rebuild -f -o $@
1024    if [ $? -gt 0 ] ; then
1025       echo "IGCM_sys_rebuild : erreur ${@}."
1026       IGCM_debug_Exit "rebuild"
1027    fi
1028
1029    IGCM_debug_PopStack "IGCM_sys_rebuild"
1030}
1031
1032##############################################################
1033# NCO OPERATOR
1034
1035function IGCM_sys_ncap {
1036    IGCM_debug_PushStack "IGCM_sys_ncap" -- $@
1037    if ( $DEBUG_sys ) ; then
1038        echo "IGCM_sys_ncap :" $@
1039    fi
1040    /usr/local/bin/ncap $@
1041    if [ $? -gt 0 ] ; then
1042       echo "IGCM_sys_ncap : erreur ${@}."
1043#       IGCM_debug_Exit "ncap"
1044    fi
1045
1046    IGCM_debug_PopStack "IGCM_sys_ncap"
1047}
1048
1049ncatted=/usr/local/bin/ncatted
1050# Problem with ksh and string passed in this function to ncatted !
1051# function IGCM_sys_ncatted {
1052#     IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1053#     if ( $DEBUG_sys ) ; then
1054#       echo "IGCM_sys_ncatted :" $@
1055#     fi
1056#     /usr/local/bin/ncatted $@
1057#     if [ $? -gt 0 ] ; then
1058#        echo "IGCM_sys_ncatted : erreur ${@}."
1059#        IGCM_debug_Exit "ncatted"
1060#     fi
1061
1062#     IGCM_debug_PopStack "IGCM_sys_ncatted"
1063# }
1064
1065function IGCM_sys_ncbo {
1066    IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1067    if ( $DEBUG_sys ) ; then
1068        echo "IGCM_sys_ncbo :" $@
1069    fi
1070    /usr/local/bin/ncbo $@
1071    if [ $? -gt 0 ] ; then
1072       echo "IGCM_sys_ncbo : erreur ${@}."
1073#       IGCM_debug_Exit "ncbo"
1074    fi
1075
1076    IGCM_debug_PopStack "IGCM_sys_ncbo"
1077}
1078
1079function IGCM_sys_ncdiff {
1080    IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1081    if ( $DEBUG_sys ) ; then
1082        echo "IGCM_sys_ncdiff :" $@
1083    fi
1084    /usr/local/bin/ncdiff $@
1085    if [ $? -gt 0 ] ; then
1086       echo "IGCM_sys_ncdiff : erreur ${@}."
1087#       IGCM_debug_Exit "ncdiff"
1088    fi
1089
1090    IGCM_debug_PopStack "IGCM_sys_ncdiff"
1091}
1092
1093function IGCM_sys_ncea {
1094    IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1095    if ( $DEBUG_sys ) ; then
1096        echo "IGCM_sys_ncea :" $@
1097    fi
1098    /usr/local/bin/ncea $@
1099    if [ $? -gt 0 ] ; then
1100       echo "IGCM_sys_ncea : erreur ${@}."
1101#       IGCM_debug_Exit "ncea"
1102    fi
1103
1104    IGCM_debug_PopStack "IGCM_sys_ncea"
1105}
1106
1107function IGCM_sys_ncecat {
1108    IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1109    if ( $DEBUG_sys ) ; then
1110        echo "IGCM_sys_ncecat :" $@
1111    fi
1112    /usr/local/bin/ncecat $@
1113    if [ $? -gt 0 ] ; then
1114       echo "IGCM_sys_ncecat : erreur ${@}."
1115#       IGCM_debug_Exit "ncecat"
1116    fi
1117
1118    IGCM_debug_PopStack "IGCM_sys_ncecat"
1119}
1120
1121function IGCM_sys_ncflint {
1122    IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1123    if ( $DEBUG_sys ) ; then
1124        echo "IGCM_sys_ncflint :" $@
1125    fi
1126    /usr/local/bin/ncflint $@
1127    if [ $? -gt 0 ] ; then
1128       echo "IGCM_sys_ncflint : erreur ${@}."
1129#       IGCM_debug_Exit "ncflint"
1130    fi
1131
1132    IGCM_debug_PopStack "IGCM_sys_ncflint"
1133}
1134
1135function IGCM_sys_ncks {
1136    IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1137    if ( $DEBUG_sys ) ; then
1138        echo "IGCM_sys_ncks :" $@
1139    fi
1140    /usr/local/bin/ncks $@
1141    if [ $? -gt 0 ] ; then
1142       echo "IGCM_sys_ncks : erreur ${@}."
1143#       IGCM_debug_Exit "ncks"
1144    fi
1145
1146    IGCM_debug_PopStack "IGCM_sys_ncks"
1147}
1148
1149function IGCM_sys_ncpdq {
1150    IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1151    if ( $DEBUG_sys ) ; then
1152        echo "IGCM_sys_ncpdq :" $@
1153    fi
1154    /usr/local/bin/ncpdq $@
1155    if [ $? -gt 0 ] ; then
1156       echo "IGCM_sys_ncpdq : erreur ${@}."
1157#       IGCM_debug_Exit "ncpdq"
1158    fi
1159
1160    IGCM_debug_PopStack "IGCM_sys_ncpdq"
1161}
1162
1163function IGCM_sys_ncra {
1164    IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1165    if ( $DEBUG_sys ) ; then
1166        echo "IGCM_sys_ncra :" $@
1167    fi
1168    /usr/local/bin/ncra $@
1169    if [ $? -gt 0 ] ; then
1170       echo "IGCM_sys_ncra : erreur ${@}."
1171#       IGCM_debug_Exit "ncra"
1172    fi
1173
1174    IGCM_debug_PopStack "IGCM_sys_ncra"
1175}
1176
1177function IGCM_sys_ncrcat {
1178    IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1179    if ( $DEBUG_sys ) ; then
1180        echo "IGCM_sys_ncrcat :" $@
1181    fi
1182    /usr/local/bin/ncrcat $@
1183    if [ $? -gt 0 ] ; then
1184       echo "IGCM_sys_ncrcat : erreur ${@}."
1185#       IGCM_debug_Exit "ncrcat"
1186    fi
1187
1188    IGCM_debug_PopStack "IGCM_sys_ncrcat"
1189}
1190
1191function IGCM_sys_ncrename {
1192    IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1193    if ( $DEBUG_sys ) ; then
1194        echo "IGCM_sys_ncrename :" $@
1195    fi
1196    /usr/local/bin/ncrename $@
1197    if [ $? -gt 0 ] ; then
1198       echo "IGCM_sys_ncrename : erreur ${@}."
1199#       IGCM_debug_Exit "ncrename"
1200    fi
1201
1202    IGCM_debug_PopStack "IGCM_sys_ncrename"
1203}
1204
1205function IGCM_sys_ncwa {
1206    IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1207    if ( $DEBUG_sys ) ; then
1208        echo "IGCM_sys_ncwa :" $@
1209    fi
1210    /usr/local/bin/ncwa $@
1211    if [ $? -gt 0 ] ; then
1212       echo "IGCM_sys_ncwa : erreur ${@}."
1213#       IGCM_debug_Exit "ncwa"
1214    fi
1215
1216    IGCM_debug_PopStack "IGCM_sys_ncwa"
1217}
1218
1219############################################################
1220# Activate Running Environnment Variables
1221
1222function IGCM_sys_activ_variables {
1223    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1224    if ( $DEBUG_sys ) ; then
1225        echo "IGCM_sys_activ_variables"
1226    fi
1227    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1228}
1229
1230############################################################
1231# Desactivate Running Environnment Variables
1232
1233function IGCM_sys_desactiv_variables {
1234    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1235    if ( $DEBUG_sys ) ; then
1236        echo "IGCM_sys_desactiv_variables"
1237    fi
1238    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1239}
1240
1241############################################################
1242# Build run file
1243
1244function IGCM_sys_build_run_file {
1245    IGCM_debug_PushStack "IGCM_sys_build_run_file"
1246    if ( $DEBUG_sys ) ; then
1247        echo "IGCM_sys_build_run_file"
1248    fi
1249    IGCM_debug_PopStack "IGCM_sys_build_run_file"
1250}
Note: See TracBrowser for help on using the repository browser.