source: tags/libIGCM_v1_2/libIGCM_sys/libIGCM_sys_obelix.ksh @ 293

Last change on this file since 293 was 44, checked in by sdipsl, 15 years ago

SD : - correct bug with post-processing in case of asynchronous rebuild.

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