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