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

Last change on this file since 128 was 128, checked in by mmaipsl, 15 years ago

Add experience type management : JobType? = DEB(ug), DEV(elopment), RUN (default)
(No propoagation in Post-treatment for instance).
Put "Where do we run ?" question in libIGCM_sys.

File size: 33.5 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        if [ X${JobType} = XRUN ] ; then
809            IGCM_sys_Chmod 444 ${1}
810        fi
811
812        typeset RET
813
814        echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
815        ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
816        RET=$?
817        IGCM_sys_Rsync_out $RET
818
819        ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
820        (( RET=RET+$? ))
821
822        if [ ${RET} -gt 0 ] ; then
823            echo "IGCM_sys_Put_Rest : error."
824            cat out_rsync
825            IGCM_debug_Exit "IGCM_sys_Put_Rest"
826        fi
827    else
828        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
829    fi
830    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
831}
832
833#D-#==================================================
834#D-function IGCM_sys_Put_Out
835#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
836#D-* Examples:
837#D-
838function IGCM_sys_Put_Out {
839    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
840    if ( $DEBUG_sys ) ; then
841        echo "IGCM_sys_Put_Out :" $@
842    fi
843    if [ $DRYRUN = 0 ]; then
844        if [ -f ${1} ] ; then
845            if [ ! -d $( dirname $2 ) ] ; then
846                IGCM_sys_MkdirArchive $( dirname $2 )
847            fi
848        else
849            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
850            IGCM_debug_PopStack "IGCM_sys_Put_Out"
851            return 1
852        fi
853
854        typeset RET
855        #
856        if [ X${JobType} = XRUN ] ; then
857            IGCM_sys_Chmod 444 ${1}
858        fi
859        #
860
861        echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
862        ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
863        RET=$?
864        IGCM_sys_Rsync_out $RET
865
866        ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
867        (( RET=RET+$? ))
868
869        if [ ${RET} -gt 0 ] ; then
870            echo "IGCM_sys_Put_Out : error."
871            cat out_rsync
872            IGCM_debug_Exit "IGCM_sys_Put_Out"
873        fi
874    else
875        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
876    fi
877    IGCM_debug_PopStack "IGCM_sys_Put_Out"
878    return 0
879}
880
881#D-#==================================================
882#D-function IGCM_sys_Get
883#D-* Purpose: Get a file from ${ARCHIVE}
884#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
885#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
886function IGCM_sys_Get {
887    IGCM_debug_PushStack "IGCM_sys_Get" $@
888
889    typeset DEST RET dm_liste ifile target
890
891    if ( $DEBUG_sys ) ; then
892        echo "IGCM_sys_Get :" $@
893    fi
894    if [ $DRYRUN -le 2 ]; then
895        if [ X${1} = X'/l' ] ; then
896            # test if the first file is present in the old computation :
897            eval set +A dm_liste \${${2}}
898        else
899            dm_liste=${1}
900        fi
901        eval DEST=\${${#}}
902
903        # test if the (first) file is present in the old computation :
904        IGCM_sys_TestFileArchive ${dm_liste[0]}
905        RET=$?
906        if [ ${RET} -gt 0 ] ; then
907            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
908            IGCM_debug_Exit "IGCM_sys_Get"
909            return
910        fi
911
912        (( RET=0 ))
913        for target in ${dm_liste[*]} ; do
914          \cp ${target} ${DEST} >> out_rsync 2>&1
915          (( RET=RET+$? ))
916        done
917
918#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
919#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
920#       RET=$?
921#       IGCM_sys_Rsync_out $RET
922
923#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
924#       (( RET=RET+$? ))
925
926        if [ ${RET} -gt 0 ] ; then
927            echo "IGCM_sys_Get : copy error."
928            cat out_rsync
929            IGCM_debug_Exit "IGCM_sys_Get"
930        fi
931    else
932        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
933    fi
934    IGCM_debug_PopStack "IGCM_sys_Get"
935}
936
937#D-#==================================================
938#D-function IGCM_sys_Put_Dods
939#D-* Purpose: DO NOTHING ! Put $(ARCHIVE) files on DODS internet protocole.
940#D-* Examples:
941#D-
942function IGCM_sys_Put_Dods {
943    IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
944    if ( $DEBUG_sys ) ; then
945        echo "IGCM_sys_Put_Dods :" $@
946    fi
947    if [ $DRYRUN = 0 ]; then
948        if [ ! -f ${1} ] ; then
949            echo "WARNING : IGCM_sys_Put_Dods ${1} DOES NOT EXIST ."
950            IGCM_debug_PopStack "IGCM_sys_Put_Dods"
951            return
952        fi
953        #DO NOTHING
954    else
955        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
956    fi
957    IGCM_debug_PopStack "IGCM_sys_Put_Dods"
958}
959
960############################################################## A REVOIR !!
961
962#D-#==================================================
963#D-function IGCM_sys_Rapatrie
964#D-* Purpose: Rapatrie
965#D-* Examples:
966#D-
967function IGCM_sys_Rapatrie {
968    IGCM_debug_PushStack "IGCM_sys_Rapatrie" $@
969    if ( $DEBUG_sys ) ; then
970        echo "IGCM_sys_Rapatrie :" $@
971    fi
972
973    typeset RET=0
974
975    IGCM_sys_Get ${R_STOCKAGE}/$2 $1 ;
976    let $(( RET=RET+$? ))
977    IGCM_sys_Cd $1 ;
978    let $(( RET=RET+$? ))
979    IGCM_sys_UnTar $2 ;
980    let $(( RET=RET+$? ))
981
982    if [ ${RET} -gt 0 ] ; then
983        echo "IGCM_sys_Rapatrie : erreur."
984        IGCM_debug_Exit "IGCM_sys_Rapatrie"
985    fi
986    IGCM_debug_PopStack "IGCM_sys_Rapatrie"
987}
988
989############################################################## A FINIR !!
990
991#D-#==================================================
992#D-function IGCM_sys_GetDate_FichWork
993#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
994#D-* Examples:
995#D-
996function IGCM_sys_GetDate_FichWork {
997    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
998    if ( $DEBUG_sys ) ; then
999        echo "IGCM_sys_GetDate_FichWork :" $@
1000    fi
1001    # donne la date filesys d'un fichier sur la machine work
1002    IGCM_debug_PopStack "IGCM_sys_FichWork"
1003}
1004
1005#D-#==================================================
1006#D-function IGCM_sys_GetDate_FichArchive
1007#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1008#D-* Examples:
1009#D-
1010function IGCM_sys_GetDate_FichArchive {
1011    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1012    if ( $DEBUG_sys ) ; then
1013        echo "IGCM_sys_GetDate_FichArchive :" $@
1014    fi
1015    IGCM_debug_PopStack "IGCM_sys_FichArchive"
1016}
1017
1018
1019##############################################################
1020# REBUILD OPERATOR
1021
1022function IGCM_sys_rebuild {
1023    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1024    if ( $DEBUG_sys ) ; then
1025        echo "IGCM_sys_rebuild :" $@
1026    fi
1027    rebuild -f -o $@
1028    if [ $? -gt 0 ] ; then
1029       echo "IGCM_sys_rebuild : erreur ${@}."
1030       IGCM_debug_Exit "rebuild"
1031    fi
1032
1033    IGCM_debug_PopStack "IGCM_sys_rebuild"
1034}
1035
1036##############################################################
1037# NCO OPERATOR
1038
1039function IGCM_sys_ncap {
1040    IGCM_debug_PushStack "IGCM_sys_ncap" -- $@
1041    if ( $DEBUG_sys ) ; then
1042        echo "IGCM_sys_ncap :" $@
1043    fi
1044    /usr/local/bin/ncap $@
1045    if [ $? -gt 0 ] ; then
1046       echo "IGCM_sys_ncap : erreur ${@}."
1047#       IGCM_debug_Exit "ncap"
1048    fi
1049
1050    IGCM_debug_PopStack "IGCM_sys_ncap"
1051}
1052
1053ncatted=/usr/local/bin/ncatted
1054# Problem with ksh and string passed in this function to ncatted !
1055# function IGCM_sys_ncatted {
1056#     IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1057#     if ( $DEBUG_sys ) ; then
1058#       echo "IGCM_sys_ncatted :" $@
1059#     fi
1060#     /usr/local/bin/ncatted $@
1061#     if [ $? -gt 0 ] ; then
1062#        echo "IGCM_sys_ncatted : erreur ${@}."
1063#        IGCM_debug_Exit "ncatted"
1064#     fi
1065
1066#     IGCM_debug_PopStack "IGCM_sys_ncatted"
1067# }
1068
1069function IGCM_sys_ncbo {
1070    IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1071    if ( $DEBUG_sys ) ; then
1072        echo "IGCM_sys_ncbo :" $@
1073    fi
1074    /usr/local/bin/ncbo $@
1075    if [ $? -gt 0 ] ; then
1076       echo "IGCM_sys_ncbo : erreur ${@}."
1077#       IGCM_debug_Exit "ncbo"
1078    fi
1079
1080    IGCM_debug_PopStack "IGCM_sys_ncbo"
1081}
1082
1083function IGCM_sys_ncdiff {
1084    IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1085    if ( $DEBUG_sys ) ; then
1086        echo "IGCM_sys_ncdiff :" $@
1087    fi
1088    /usr/local/bin/ncdiff $@
1089    if [ $? -gt 0 ] ; then
1090       echo "IGCM_sys_ncdiff : erreur ${@}."
1091#       IGCM_debug_Exit "ncdiff"
1092    fi
1093
1094    IGCM_debug_PopStack "IGCM_sys_ncdiff"
1095}
1096
1097function IGCM_sys_ncea {
1098    IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1099    if ( $DEBUG_sys ) ; then
1100        echo "IGCM_sys_ncea :" $@
1101    fi
1102    /usr/local/bin/ncea $@
1103    if [ $? -gt 0 ] ; then
1104       echo "IGCM_sys_ncea : erreur ${@}."
1105#       IGCM_debug_Exit "ncea"
1106    fi
1107
1108    IGCM_debug_PopStack "IGCM_sys_ncea"
1109}
1110
1111function IGCM_sys_ncecat {
1112    IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1113    if ( $DEBUG_sys ) ; then
1114        echo "IGCM_sys_ncecat :" $@
1115    fi
1116    /usr/local/bin/ncecat $@
1117    if [ $? -gt 0 ] ; then
1118       echo "IGCM_sys_ncecat : erreur ${@}."
1119#       IGCM_debug_Exit "ncecat"
1120    fi
1121
1122    IGCM_debug_PopStack "IGCM_sys_ncecat"
1123}
1124
1125function IGCM_sys_ncflint {
1126    IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1127    if ( $DEBUG_sys ) ; then
1128        echo "IGCM_sys_ncflint :" $@
1129    fi
1130    /usr/local/bin/ncflint $@
1131    if [ $? -gt 0 ] ; then
1132       echo "IGCM_sys_ncflint : erreur ${@}."
1133#       IGCM_debug_Exit "ncflint"
1134    fi
1135
1136    IGCM_debug_PopStack "IGCM_sys_ncflint"
1137}
1138
1139function IGCM_sys_ncks {
1140    IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1141    if ( $DEBUG_sys ) ; then
1142        echo "IGCM_sys_ncks :" $@
1143    fi
1144    /usr/local/bin/ncks $@
1145    if [ $? -gt 0 ] ; then
1146       echo "IGCM_sys_ncks : erreur ${@}."
1147#       IGCM_debug_Exit "ncks"
1148    fi
1149
1150    IGCM_debug_PopStack "IGCM_sys_ncks"
1151}
1152
1153function IGCM_sys_ncpdq {
1154    IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1155    if ( $DEBUG_sys ) ; then
1156        echo "IGCM_sys_ncpdq :" $@
1157    fi
1158    /usr/local/bin/ncpdq $@
1159    if [ $? -gt 0 ] ; then
1160       echo "IGCM_sys_ncpdq : erreur ${@}."
1161#       IGCM_debug_Exit "ncpdq"
1162    fi
1163
1164    IGCM_debug_PopStack "IGCM_sys_ncpdq"
1165}
1166
1167function IGCM_sys_ncra {
1168    IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1169    if ( $DEBUG_sys ) ; then
1170        echo "IGCM_sys_ncra :" $@
1171    fi
1172    /usr/local/bin/ncra $@
1173    if [ $? -gt 0 ] ; then
1174       echo "IGCM_sys_ncra : erreur ${@}."
1175#       IGCM_debug_Exit "ncra"
1176    fi
1177
1178    IGCM_debug_PopStack "IGCM_sys_ncra"
1179}
1180
1181function IGCM_sys_ncrcat {
1182    IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1183    if ( $DEBUG_sys ) ; then
1184        echo "IGCM_sys_ncrcat :" $@
1185    fi
1186    /usr/local/bin/ncrcat $@
1187    if [ $? -gt 0 ] ; then
1188       echo "IGCM_sys_ncrcat : erreur ${@}."
1189#       IGCM_debug_Exit "ncrcat"
1190    fi
1191
1192    IGCM_debug_PopStack "IGCM_sys_ncrcat"
1193}
1194
1195function IGCM_sys_ncrename {
1196    IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1197    if ( $DEBUG_sys ) ; then
1198        echo "IGCM_sys_ncrename :" $@
1199    fi
1200    /usr/local/bin/ncrename $@
1201    if [ $? -gt 0 ] ; then
1202       echo "IGCM_sys_ncrename : erreur ${@}."
1203#       IGCM_debug_Exit "ncrename"
1204    fi
1205
1206    IGCM_debug_PopStack "IGCM_sys_ncrename"
1207}
1208
1209function IGCM_sys_ncwa {
1210    IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1211    if ( $DEBUG_sys ) ; then
1212        echo "IGCM_sys_ncwa :" $@
1213    fi
1214    /usr/local/bin/ncwa $@
1215    if [ $? -gt 0 ] ; then
1216       echo "IGCM_sys_ncwa : erreur ${@}."
1217#       IGCM_debug_Exit "ncwa"
1218    fi
1219
1220    IGCM_debug_PopStack "IGCM_sys_ncwa"
1221}
1222
1223############################################################
1224# Activate Running Environnment Variables
1225
1226function IGCM_sys_activ_variables {
1227    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1228    if ( $DEBUG_sys ) ; then
1229        echo "IGCM_sys_activ_variables"
1230    fi
1231    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1232}
1233
1234############################################################
1235# Desactivate Running Environnment Variables
1236
1237function IGCM_sys_desactiv_variables {
1238    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1239    if ( $DEBUG_sys ) ; then
1240        echo "IGCM_sys_desactiv_variables"
1241    fi
1242    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1243}
1244
1245############################################################
1246# Build run file
1247
1248function IGCM_sys_build_run_file {
1249    IGCM_debug_PushStack "IGCM_sys_build_run_file"
1250    if ( $DEBUG_sys ) ; then
1251        echo "IGCM_sys_build_run_file"
1252    fi
1253    IGCM_debug_PopStack "IGCM_sys_build_run_file"
1254}
Note: See TracBrowser for help on using the repository browser.