source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh @ 79

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