source: branches/AllPostFred/libIGCM_sys/libIGCM_sys_obelix.ksh @ 33

Last change on this file since 33 was 33, checked in by mmaipsl, 15 years ago

Christian Laguerre, MM : correction on obelix calculator.

IGCM arborescence has been installed for ORCHIDEE on this cluster.

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