source: tags/libIGCM_v1/libIGCM_sys/libIGCM_sys_default.ksh @ 1456

Last change on this file since 1456 was 2, checked in by mmaipsl, 16 years ago

MM: import first trunk version of libIGCM.

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