source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_default.ksh @ 39

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

SD : Add sleep 60 in function IGCM_sys_Get_Master to prevent NFS problem

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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