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

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

ACa/SD : Function IGCM_sys_RshArchive will be use to manage NEMO restart in the parallel case

  • 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
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        ( ${DEBUG_debug} ) && 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        ( ${DEBUG_debug} ) && 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        ( ${DEBUG_debug} ) && 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          \cp ${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        ( ${DEBUG_debug} ) && 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        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
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# REBUILD OPERATOR
999
1000function IGCM_sys_rebuild {
1001    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1002    if ( $DEBUG_sys ) ; then
1003        echo "IGCM_sys_rebuild :" $@
1004    fi
1005    rebuild -f -o $@
1006    if [ $? -gt 0 ] ; then
1007       echo "IGCM_sys_rebuild : erreur ${@}."
1008       IGCM_debug_Exit "rebuild"
1009    fi
1010
1011    IGCM_debug_PopStack "IGCM_sys_rebuild"
1012}
1013
1014##############################################################
1015# NCO OPERATOR
1016
1017function IGCM_sys_ncap {
1018    IGCM_debug_PushStack "IGCM_sys_ncap" -- $@
1019    if ( $DEBUG_sys ) ; then
1020        echo "IGCM_sys_ncap :" $@
1021    fi
1022    /usr/local/bin/ncap $@
1023    if [ $? -gt 0 ] ; then
1024       echo "IGCM_sys_ncap : erreur ${@}."
1025#       IGCM_debug_Exit "ncap"
1026    fi
1027
1028    IGCM_debug_PopStack "IGCM_sys_ncap"
1029}
1030
1031ncatted=/usr/local/bin/ncatted
1032# Problem with ksh and string passed in this function to ncatted !
1033# function IGCM_sys_ncatted {
1034#     IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1035#     if ( $DEBUG_sys ) ; then
1036#       echo "IGCM_sys_ncatted :" $@
1037#     fi
1038#     /usr/local/bin/ncatted $@
1039#     if [ $? -gt 0 ] ; then
1040#        echo "IGCM_sys_ncatted : erreur ${@}."
1041#        IGCM_debug_Exit "ncatted"
1042#     fi
1043
1044#     IGCM_debug_PopStack "IGCM_sys_ncatted"
1045# }
1046
1047function IGCM_sys_ncbo {
1048    IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1049    if ( $DEBUG_sys ) ; then
1050        echo "IGCM_sys_ncbo :" $@
1051    fi
1052    /usr/local/bin/ncbo $@
1053    if [ $? -gt 0 ] ; then
1054       echo "IGCM_sys_ncbo : erreur ${@}."
1055#       IGCM_debug_Exit "ncbo"
1056    fi
1057
1058    IGCM_debug_PopStack "IGCM_sys_ncbo"
1059}
1060
1061function IGCM_sys_ncdiff {
1062    IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1063    if ( $DEBUG_sys ) ; then
1064        echo "IGCM_sys_ncdiff :" $@
1065    fi
1066    /usr/local/bin/ncdiff $@
1067    if [ $? -gt 0 ] ; then
1068       echo "IGCM_sys_ncdiff : erreur ${@}."
1069#       IGCM_debug_Exit "ncdiff"
1070    fi
1071
1072    IGCM_debug_PopStack "IGCM_sys_ncdiff"
1073}
1074
1075function IGCM_sys_ncea {
1076    IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1077    if ( $DEBUG_sys ) ; then
1078        echo "IGCM_sys_ncea :" $@
1079    fi
1080    /usr/local/bin/ncea $@
1081    if [ $? -gt 0 ] ; then
1082       echo "IGCM_sys_ncea : erreur ${@}."
1083#       IGCM_debug_Exit "ncea"
1084    fi
1085
1086    IGCM_debug_PopStack "IGCM_sys_ncea"
1087}
1088
1089function IGCM_sys_ncecat {
1090    IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1091    if ( $DEBUG_sys ) ; then
1092        echo "IGCM_sys_ncecat :" $@
1093    fi
1094    /usr/local/bin/ncecat $@
1095    if [ $? -gt 0 ] ; then
1096       echo "IGCM_sys_ncecat : erreur ${@}."
1097#       IGCM_debug_Exit "ncecat"
1098    fi
1099
1100    IGCM_debug_PopStack "IGCM_sys_ncecat"
1101}
1102
1103function IGCM_sys_ncflint {
1104    IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1105    if ( $DEBUG_sys ) ; then
1106        echo "IGCM_sys_ncflint :" $@
1107    fi
1108    /usr/local/bin/ncflint $@
1109    if [ $? -gt 0 ] ; then
1110       echo "IGCM_sys_ncflint : erreur ${@}."
1111#       IGCM_debug_Exit "ncflint"
1112    fi
1113
1114    IGCM_debug_PopStack "IGCM_sys_ncflint"
1115}
1116
1117function IGCM_sys_ncks {
1118    IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1119    if ( $DEBUG_sys ) ; then
1120        echo "IGCM_sys_ncks :" $@
1121    fi
1122    /usr/local/bin/ncks $@
1123    if [ $? -gt 0 ] ; then
1124       echo "IGCM_sys_ncks : erreur ${@}."
1125#       IGCM_debug_Exit "ncks"
1126    fi
1127
1128    IGCM_debug_PopStack "IGCM_sys_ncks"
1129}
1130
1131function IGCM_sys_ncpdq {
1132    IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1133    if ( $DEBUG_sys ) ; then
1134        echo "IGCM_sys_ncpdq :" $@
1135    fi
1136    /usr/local/bin/ncpdq $@
1137    if [ $? -gt 0 ] ; then
1138       echo "IGCM_sys_ncpdq : erreur ${@}."
1139#       IGCM_debug_Exit "ncpdq"
1140    fi
1141
1142    IGCM_debug_PopStack "IGCM_sys_ncpdq"
1143}
1144
1145function IGCM_sys_ncra {
1146    IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1147    if ( $DEBUG_sys ) ; then
1148        echo "IGCM_sys_ncra :" $@
1149    fi
1150    /usr/local/bin/ncra $@
1151    if [ $? -gt 0 ] ; then
1152       echo "IGCM_sys_ncra : erreur ${@}."
1153#       IGCM_debug_Exit "ncra"
1154    fi
1155
1156    IGCM_debug_PopStack "IGCM_sys_ncra"
1157}
1158
1159function IGCM_sys_ncrcat {
1160    IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1161    if ( $DEBUG_sys ) ; then
1162        echo "IGCM_sys_ncrcat :" $@
1163    fi
1164    /usr/local/bin/ncrcat $@
1165    if [ $? -gt 0 ] ; then
1166       echo "IGCM_sys_ncrcat : erreur ${@}."
1167#       IGCM_debug_Exit "ncrcat"
1168    fi
1169
1170    IGCM_debug_PopStack "IGCM_sys_ncrcat"
1171}
1172
1173function IGCM_sys_ncrename {
1174    IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1175    if ( $DEBUG_sys ) ; then
1176        echo "IGCM_sys_ncrename :" $@
1177    fi
1178    /usr/local/bin/ncrename $@
1179    if [ $? -gt 0 ] ; then
1180       echo "IGCM_sys_ncrename : erreur ${@}."
1181#       IGCM_debug_Exit "ncrename"
1182    fi
1183
1184    IGCM_debug_PopStack "IGCM_sys_ncrename"
1185}
1186
1187function IGCM_sys_ncwa {
1188    IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1189    if ( $DEBUG_sys ) ; then
1190        echo "IGCM_sys_ncwa :" $@
1191    fi
1192    /usr/local/bin/ncwa $@
1193    if [ $? -gt 0 ] ; then
1194       echo "IGCM_sys_ncwa : erreur ${@}."
1195#       IGCM_debug_Exit "ncwa"
1196    fi
1197
1198    IGCM_debug_PopStack "IGCM_sys_ncwa"
1199}
1200
1201############################################################
1202# Activate Running Environnment Variables
1203
1204function IGCM_sys_activ_variables {
1205    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1206    if ( $DEBUG_sys ) ; then
1207        echo "IGCM_sys_activ_variables"
1208    fi
1209    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1210}
1211
1212############################################################
1213# Desactivate Running Environnment Variables
1214
1215function IGCM_sys_desactiv_variables {
1216    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1217    if ( $DEBUG_sys ) ; then
1218        echo "IGCM_sys_desactiv_variables"
1219    fi
1220    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1221}
1222
1223############################################################
1224# Build run file
1225
1226function IGCM_sys_build_run_file {
1227    IGCM_debug_PushStack "IGCM_sys_build_run_file"
1228    if ( $DEBUG_sys ) ; then
1229        echo "IGCM_sys_build_run_file"
1230    fi
1231    IGCM_debug_PopStack "IGCM_sys_build_run_file"
1232}
Note: See TracBrowser for help on using the repository browser.