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

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