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

Last change on this file since 296 was 285, checked in by mmaipsl, 14 years ago

Add cdo function.

  • Property svn:keywords set to Date Author Revision
File size: 33.2 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}/tmp$$}
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    IGCM_sys_Cd ..
635
636    echo rm $@ > out_rsync 2>&1
637    \rm $@ >> out_rsync 2>&1
638    RET=$?
639
640    if [ ${RET} -gt 0 ] ; then
641        echo "IGCM_sys_RmRunDir : error."
642        cat out_rsync
643        IGCM_debug_Exit "IGCM_sys_RmRunDir"
644    fi
645
646    IGCM_debug_PopStack "IGCM_sys_RmRunDir"
647}
648
649#D-#==================================================
650#D-function IGCM_sys_Mv
651#D-* Purpose: generic move
652#D-* Examples:
653#D-
654function IGCM_sys_Mv {
655    IGCM_debug_PushStack "IGCM_sys_Mv" $@
656    if ( $DEBUG_sys ) ; then
657        echo "IGCM_sys_Mv :" $@
658    fi
659
660    if [ $DRYRUN = 0 ]; then
661
662        typeset RET
663           
664        echo mv $@ > out_rsync 2>&1
665        \mv $@ >> out_rsync 2>&1
666        RET=$?
667   
668        if [ ${RET} -gt 0 ] ; then
669            echo "IGCM_sys_Mv : error in mv."
670            cat out_rsync
671            IGCM_debug_Exit "IGCM_sys_Mv"
672        fi
673    else
674        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
675    fi
676
677    IGCM_debug_PopStack "IGCM_sys_Mv"
678}
679
680#D-#==================================================
681#D-function IGCM_sys_Put_Dir
682#D-* Purpose: Copy a complete directory on $(ARCHIVE)
683#D-* Examples:
684#D-
685function IGCM_sys_Put_Dir {
686    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
687    if ( $DEBUG_sys ) ; then
688        echo "IGCM_sys_Put_Dir :" $@
689    fi
690    if [ $DRYRUN = 0 ]; then
691        if [ ! -d ${1} ] ; then
692            echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
693            IGCM_debug_PopStack "IGCM_sys_Put_Dir"
694            return
695        fi
696
697        typeset RET
698
699        # Only if we use rsync
700        #IGCM_sys_TestDirArchive $( dirname $2 )
701        #
702        #USUAL WAY
703        \cp -r $1 $2 > out_rsync 2>&1
704        RET=$?
705
706        if [ ${RET} -gt 0 ] ; then
707            echo "IGCM_sys_Put_Dir : error."
708            cat out_rsync
709            IGCM_debug_Exit "IGCM_sys_Put_Dir"
710        fi
711    else
712        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
713    fi
714    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
715}
716
717#D-#==================================================
718#D-function IGCM_sys_Get_Dir
719#D-* Purpose: Copy a complete directory from $(ARCHIVE)
720#D-* Examples:
721#D-
722function IGCM_sys_Get_Dir {
723    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
724    if ( $DEBUG_sys ) ; then
725        echo "IGCM_sys_Get_Dir :" $@
726    fi
727    if [ $DRYRUN = 0 ]; then
728#       if [ ! -d ${1} ] ; then
729#           echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
730#           IGCM_debug_PopStack "IGCM_sys_Get_Dir"
731#           return
732#       fi
733
734        typeset RET
735
736        # Only if we use rsync
737        #IGCM_sys_TestDirArchive $( dirname $2 )
738        #
739        #USUAL WAY
740        \cp -r $1 $2 > out_rsync 2>&1
741        RET=$?
742
743        if [ ${RET} -gt 0 ] ; then
744            echo "IGCM_sys_Get_Dir : error."
745            cat out_rsync
746            IGCM_debug_Exit "IGCM_sys_Get_Dir"
747        fi
748    else
749        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
750    fi
751    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
752}
753
754#D-#==================================================
755#D-function IGCM_sys_Get_Master
756#D-* Purpose: Copy a complete directory from MASTER filesystem
757#D-* Examples:
758#D-
759function IGCM_sys_Get_Master {
760    IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
761    if ( $DEBUG_sys ) ; then
762        echo "IGCM_sys_Get_Master :" $@
763    fi
764    if [ $DRYRUN = 0 ]; then
765        if [ ! -d ${1} ] ; then
766            echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
767            IGCM_debug_PopStack "IGCM_sys_Get_Master"
768            return
769        fi
770
771        typeset RET
772        sleep 60
773
774        #USUAL WAY
775        \cp -r $1 $2 > out_rsync 2>&1
776        RET=$?
777
778        if [ ${RET} -gt 0 ] ; then
779            echo "IGCM_sys_Get_Master : error."
780            cat out_rsync
781            IGCM_debug_Exit "IGCM_sys_Get_Master"
782        fi
783    else
784        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
785    fi
786    IGCM_debug_PopStack "IGCM_sys_Get_Master"
787}
788
789#D-#==================================================
790#D-function IGCM_sys_Put_Out
791#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
792#D-* Examples:
793#D-
794function IGCM_sys_Put_Out {
795    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
796    if ( $DEBUG_sys ) ; then
797        echo "IGCM_sys_Put_Out :" $@
798    fi
799    if [ $DRYRUN = 0 ]; then
800        if [ ! -f ${1} ] ; then
801            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
802            IGCM_debug_PopStack "IGCM_sys_Put_Out"
803            return 1
804        fi
805        #
806        IGCM_sys_MkdirArchive $( dirname $2 )
807        #
808        typeset RET
809        #
810        if [ X${JobType} = XRUN ] ; then
811            if [ X${3} = X ] ; then
812                IGCM_sys_Chmod 444 ${1}
813            fi
814        fi
815        #
816        # USUAL WAY
817        \cp $1 $2 > out_rsync 2>&1
818        RET=$?
819
820#       #RSYNC WITH NETWORK RSH CALL
821#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
822#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
823
824#       #RSYNC WITH NFS USE
825#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
826#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
827
828#       RET=$?
829#       IGCM_sys_Rsync_out $RET
830
831#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
832#       (( RET=RET+$? ))
833
834        if [ ${RET} -gt 0 ] ; then
835            echo "IGCM_sys_Put_Out : error."
836            cat out_rsync
837            IGCM_debug_Exit "IGCM_sys_Put_Out"
838        fi
839    else
840        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
841    fi
842    IGCM_debug_PopStack "IGCM_sys_Put_Out"
843    return 0
844}
845
846#D-#==================================================
847#D-function IGCM_sys_Get
848#D-* Purpose: Get a file from ${ARCHIVE}
849#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
850#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
851function IGCM_sys_Get {
852    IGCM_debug_PushStack "IGCM_sys_Get" $@
853
854    typeset DEST RET dm_liste ifile target file_work
855
856    if ( $DEBUG_sys ) ; then
857        echo "IGCM_sys_Get :" $@
858    fi
859    if [ $DRYRUN -le 2 ]; then
860        if [ X${1} = X'/l' ] ; then
861            # test if the first file is present in the old computation :
862            eval set +A dm_liste \${${2}}
863        else
864            eval set +A dm_liste ${1}
865        fi
866        eval DEST=\${${#}}
867
868        #=====================================================
869        #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
870        #=====================================================
871
872        # Is it an R_OUT file (not R_IN) ?
873        #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
874        #if [ $? -eq 0 ] ; then
875        #    # Yes  ? then we try to get it in SCRATCHDIR
876        #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_OUT_SCR}|g" )
877        #    if [ -f ${file_work[0]} ] ; then
878        #       IGCM_sys_Cp ${file_work[*]} ${DEST}
879        #       IGCM_debug_PopStack "IGCM_sys_Get"
880        #       return
881        #    fi
882        #fi
883
884        # test if the (first) file is present in the old computation :
885        IGCM_sys_TestFileArchive ${dm_liste[0]}
886        RET=$?
887        if [ ${RET} -gt 0 ] ; then
888            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
889            IGCM_debug_Exit "IGCM_sys_Get"
890            #IGCM_debug_PopStack "IGCM_sys_Get"
891            #return
892        fi
893
894        dmget ${dm_liste[*]} > out_rsync 2>&1
895        RET=$?
896        if [ ${RET} -gt 0 ] ; then
897            echo "WARNING IGCM_sys_Get : demigration error."
898            cat out_rsync
899            #IGCM_debug_Exit "IGCM_sys_Get"
900            #IGCM_debug_PopStack "IGCM_sys_Get"
901            #return
902        fi
903
904        #USUAL WAY
905        (( RET=0 ))
906        if [ X${1} = X'/l' ] ; then
907            (( RET=0 ))
908            for target in ${dm_liste[*]} ; do
909                local_file=$( basename ${target} )
910                \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
911                (( RET = RET + $? ))
912            done
913        else
914            \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
915            RET=$?
916        fi
917
918#       #RSYNC WITH NETWORK RSH CALL
919#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
920#       ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
921
922#       #RSYNC WITH NFS USE
923#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
924#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
925
926#       RET=$?
927#       IGCM_sys_Rsync_out $RET
928
929#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
930#       (( RET=RET+$? ))
931
932    else
933        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
934    fi
935    IGCM_debug_PopStack "IGCM_sys_Get"
936}
937
938#D-#==================================================
939#D-function IGCM_sys_Put_Dods
940#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
941#D-* Examples:
942#D-
943function IGCM_sys_Put_Dods {
944    IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
945    if ( $DEBUG_sys ) ; then
946        echo "IGCM_sys_Put_Dods :" $@
947    fi
948    if [ $DRYRUN = 0 ]; then
949        if [ ! -d ${R_SAVE}/${1} ] ; then
950            echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
951            IGCM_debug_PopStack "IGCM_sys_Put_Dods"
952            return
953        fi
954
955        typeset RET
956        #
957        cd ${R_SAVE}
958        dods_rm public/${LOGIN}/${R_DODS}/${1} > /dev/null 2>&1
959        dods_cp ${1} public/${LOGIN}/${R_DODS} > /dev/null 2>&1
960        RET=0
961       
962        if [ ${RET} -gt 0 ] ; then
963            echo "IGCM_sys_Put_Dods : error."
964            IGCM_debug_Exit "IGCM_sys_Put_Dods"
965        fi
966    else
967        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
968    fi
969    IGCM_debug_PopStack "IGCM_sys_Put_Dods"
970}
971
972############################################################## A FINIR !!
973
974#D-#==================================================
975#D-function IGCM_sys_GetDate_FichWork
976#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
977#D-* Examples:
978#D-
979function IGCM_sys_GetDate_FichWork {
980    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
981    if ( $DEBUG_sys ) ; then
982        echo "IGCM_sys_GetDate_FichWork :" $@
983    fi
984    # donne la date filesys d'un fichier sur la machine work
985    IGCM_debug_PopStack "IGCM_sys_FichWork"
986}
987
988#D-#==================================================
989#D-function IGCM_sys_GetDate_FichArchive
990#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
991#D-* Examples:
992#D-
993function IGCM_sys_GetDate_FichArchive {
994    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
995    if ( $DEBUG_sys ) ; then
996        echo "IGCM_sys_GetDate_FichArchive :" $@
997    fi
998    IGCM_debug_PopStack "IGCM_sys_FichArchive"
999}
1000
1001##############################################################
1002# REBUILD OPERATOR
1003
1004function IGCM_sys_rebuild {
1005    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1006    if ( $DEBUG_sys ) ; then
1007        echo "IGCM_sys_rebuild :" $@
1008    fi
1009    /home/cont003/p86ipsl/X86_64/bin/rebuild -f -o $@
1010    if [ $? -gt 0 ] ; then
1011       echo "IGCM_sys_rebuild : erreur ${@}."
1012       IGCM_debug_Exit "rebuild"
1013    fi
1014
1015    IGCM_debug_PopStack "IGCM_sys_rebuild"
1016}
1017
1018##############################################################
1019# NCO OPERATOR
1020
1021function IGCM_sys_ncap {
1022    IGCM_debug_PushStack "IGCM_sys_ncap" -- $@
1023    if ( $DEBUG_sys ) ; then
1024        echo "IGCM_sys_ncap :" $@
1025    fi
1026    ncap $@
1027    if [ $? -gt 0 ] ; then
1028       echo "IGCM_sys_ncap : erreur ${@}."
1029#       IGCM_debug_Exit "ncap"
1030    fi
1031
1032    IGCM_debug_PopStack "IGCM_sys_ncap"
1033}
1034
1035ncatted=ncatted
1036# Problem with ksh and string passed in this function to ncatted !
1037# function IGCM_sys_ncatted {
1038#     IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1039#     if ( $DEBUG_sys ) ; then
1040#       echo "IGCM_sys_ncatted :" $@
1041#     fi
1042#     ncatted $@
1043#     if [ $? -gt 0 ] ; then
1044#        echo "IGCM_sys_ncatted : erreur ${@}."
1045#        IGCM_debug_Exit "ncatted"
1046#     fi
1047
1048#     IGCM_debug_PopStack "IGCM_sys_ncatted"
1049# }
1050
1051function IGCM_sys_ncbo {
1052    IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1053    if ( $DEBUG_sys ) ; then
1054        echo "IGCM_sys_ncbo :" $@
1055    fi
1056    ncbo $@
1057    if [ $? -gt 0 ] ; then
1058       echo "IGCM_sys_ncbo : erreur ${@}."
1059#       IGCM_debug_Exit "ncbo"
1060    fi
1061
1062    IGCM_debug_PopStack "IGCM_sys_ncbo"
1063}
1064
1065function IGCM_sys_ncdiff {
1066    IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1067    if ( $DEBUG_sys ) ; then
1068        echo "IGCM_sys_ncdiff :" $@
1069    fi
1070    ncdiff $@
1071    if [ $? -gt 0 ] ; then
1072       echo "IGCM_sys_ncdiff : erreur ${@}."
1073#       IGCM_debug_Exit "ncdiff"
1074    fi
1075
1076    IGCM_debug_PopStack "IGCM_sys_ncdiff"
1077}
1078
1079function IGCM_sys_ncea {
1080    IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1081    if ( $DEBUG_sys ) ; then
1082        echo "IGCM_sys_ncea :" $@
1083    fi
1084    ncea $@
1085    if [ $? -gt 0 ] ; then
1086       echo "IGCM_sys_ncea : erreur ${@}."
1087#       IGCM_debug_Exit "ncea"
1088    fi
1089
1090    IGCM_debug_PopStack "IGCM_sys_ncea"
1091}
1092
1093function IGCM_sys_ncecat {
1094    IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1095    if ( $DEBUG_sys ) ; then
1096        echo "IGCM_sys_ncecat :" $@
1097    fi
1098    ncecat $@
1099    if [ $? -gt 0 ] ; then
1100       echo "IGCM_sys_ncecat : erreur ${@}."
1101#       IGCM_debug_Exit "ncecat"
1102    fi
1103
1104    IGCM_debug_PopStack "IGCM_sys_ncecat"
1105}
1106
1107function IGCM_sys_ncflint {
1108    IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1109    if ( $DEBUG_sys ) ; then
1110        echo "IGCM_sys_ncflint :" $@
1111    fi
1112    ncflint $@
1113    if [ $? -gt 0 ] ; then
1114       echo "IGCM_sys_ncflint : erreur ${@}."
1115#       IGCM_debug_Exit "ncflint"
1116    fi
1117
1118    IGCM_debug_PopStack "IGCM_sys_ncflint"
1119}
1120
1121function IGCM_sys_ncks {
1122    IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1123    if ( $DEBUG_sys ) ; then
1124        echo "IGCM_sys_ncks :" $@
1125    fi
1126    ncks $@
1127    if [ $? -gt 0 ] ; then
1128       echo "IGCM_sys_ncks : erreur ${@}."
1129#       IGCM_debug_Exit "ncks"
1130    fi
1131
1132    IGCM_debug_PopStack "IGCM_sys_ncks"
1133}
1134
1135function IGCM_sys_ncpdq {
1136    IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1137    if ( $DEBUG_sys ) ; then
1138        echo "IGCM_sys_ncpdq :" $@
1139    fi
1140    ncpdq $@
1141    if [ $? -gt 0 ] ; then
1142       echo "IGCM_sys_ncpdq : erreur ${@}."
1143#       IGCM_debug_Exit "ncpdq"
1144    fi
1145
1146    IGCM_debug_PopStack "IGCM_sys_ncpdq"
1147}
1148
1149function IGCM_sys_ncra {
1150    IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1151    if ( $DEBUG_sys ) ; then
1152        echo "IGCM_sys_ncra :" $@
1153    fi
1154    ncra $@
1155    if [ $? -gt 0 ] ; then
1156       echo "IGCM_sys_ncra : erreur ${@}."
1157#       IGCM_debug_Exit "ncra"
1158    fi
1159
1160    IGCM_debug_PopStack "IGCM_sys_ncra"
1161}
1162
1163function IGCM_sys_ncrcat {
1164    IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1165    if ( $DEBUG_sys ) ; then
1166        echo "IGCM_sys_ncrcat :" $@
1167    fi
1168    ncrcat $@
1169    if [ $? -gt 0 ] ; then
1170       echo "IGCM_sys_ncrcat : erreur ${@}."
1171#       IGCM_debug_Exit "ncrcat"
1172    fi
1173
1174    IGCM_debug_PopStack "IGCM_sys_ncrcat"
1175}
1176
1177function IGCM_sys_ncrename {
1178    IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1179    if ( $DEBUG_sys ) ; then
1180        echo "IGCM_sys_ncrename :" $@
1181    fi
1182    ncrename $@
1183    if [ $? -gt 0 ] ; then
1184       echo "IGCM_sys_ncrename : erreur ${@}."
1185#       IGCM_debug_Exit "ncrename"
1186    fi
1187
1188    IGCM_debug_PopStack "IGCM_sys_ncrename"
1189}
1190
1191function IGCM_sys_ncwa {
1192    IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1193    if ( $DEBUG_sys ) ; then
1194        echo "IGCM_sys_ncwa :" $@
1195    fi
1196    ncwa $@
1197    if [ $? -gt 0 ] ; then
1198       echo "IGCM_sys_ncwa : erreur ${@}."
1199#       IGCM_debug_Exit "ncwa"
1200    fi
1201
1202    IGCM_debug_PopStack "IGCM_sys_ncwa"
1203}
1204
1205##############################################################
1206# CDO OPERATOR
1207
1208function IGCM_sys_cdo {
1209    IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
1210
1211    \cdo $@
1212    if [ $? -gt 0 ] ; then
1213       echo "IGCM_sys_cdo : erreur ${@}."
1214#       IGCM_debug_Exit "cdo"
1215    fi
1216
1217    IGCM_debug_PopStack "IGCM_sys_cdo"
1218}
1219
1220############################################################
1221# Activate Running Environnment Variables
1222
1223function IGCM_sys_activ_variables {
1224    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1225    if ( $DEBUG_sys ) ; then
1226        echo "IGCM_sys_activ_variables"
1227    fi
1228    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1229}
1230
1231############################################################
1232# Desactivate Running Environnment Variables
1233
1234function IGCM_sys_desactiv_variables {
1235    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1236    if ( $DEBUG_sys ) ; then
1237        echo "IGCM_sys_desactiv_variables"
1238    fi
1239    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1240}
1241
1242############################################################
1243# Build run file
1244
1245function IGCM_sys_build_run_file {
1246    IGCM_debug_PushStack "IGCM_sys_build_run_file"
1247    if ( $DEBUG_sys ) ; then
1248        echo "IGCM_sys_build_run_file"
1249    fi
1250    IGCM_debug_PopStack "IGCM_sys_build_run_file"
1251}
Note: See TracBrowser for help on using the repository browser.