source: tags/libIGCM_v1/libIGCM_sys/libIGCM_sys_mercureTX.ksh @ 1456

Last change on this file since 1456 was 2, checked in by mmaipsl, 16 years ago

MM: import first trunk version of libIGCM.

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