source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_mercure.ksh @ 274

Last change on this file since 274 was 274, checked in by mafoipsl, 14 years ago

Use CSCRATCHDIR on new front end for mercure to have better performances for rebuild and other postprocessing operations. Correct config_Finalize to avoid warning messages. Correct somme comment.

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