source: tags/libIGCM_v1_8-old/libIGCM_sys/libIGCM_sys_mercure.ksh @ 803

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

Use TMPDIR for mercure again. Correct CompletedFlag? initialisation. Delete useless echo. Correct 1st line or rebuild.ksh.

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