source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_ulam.ksh @ 58

Last change on this file since 58 was 58, checked in by sdipsl, 15 years ago

Headers for LoadLeveler? 3.5

File size: 33.3 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil
5# Contact: sebastien.denvil.@ipsl.jussieu.fr
6# $Date: 2008-12-15 16:00:58 +0100 (Mon, 15 Dec 2008) $
7# $Author: sdipsl $
8# $Revision: 44 $
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 Ulam
24#D-#==================================================
25#D-
26#D- This ksh library if a layer under some usefull
27#D-environment variables and shell commands.
28#D-All those definitions depend on host particularities.
29#D-It manages a stack mechanism and test validity of operations.
30#D-All function described bellow must be prefixed by IGCM_sys.
31
32#====================================================
33# libIGCM_sys PARAMETERS
34#====================================================
35
36#====================================================
37# set DEBUG_sys to true to output calls of function
38typeset -r DEBUG_sys=${DEBUG_sys:=true}
39
40#====================================================
41# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
42typeset -r DRYRUN=${DRYRUN:=0}
43
44# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
45# -------------------------------------------------------------------------------------
46# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
47# |          |  Cp/Exe param files |            |  Chmod  |                           |
48# |          |      Qsub           |            |         |                           |
49# -------------------------------------------------------------------------------------
50# |    0     |       yes           |    yes     |  yes    |      yes                  |
51# -------------------------------------------------------------------------------------
52# |    1     |       yes           |    yes     |  yes    |      no                   |
53# -------------------------------------------------------------------------------------
54# |    2     |       yes           |    yes     |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56# |    3     |       yes           |    no      |  no     |      no                   |
57# -------------------------------------------------------------------------------------
58
59#=====================================================
60# Global Variables :
61#=====================================================
62# Language : "fr" or "en"
63typeset -r MYLANG="fr"
64
65#=====================================================
66# Host and user names
67# $hostname ou hostname
68typeset -r HOST=$( hostname )
69# $username ou whoami
70typeset -r LOGIN=$( whoami )
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# rsync with path
78typeset -r RSYNC=/usr/bin/rsync
79# RSYNC_opt args to rsync
80typeset -r RSYNC_opt="-Lt -v"
81# RSYNC_opt args to "remote rsync"
82# ie storage filesystem
83typeset -r RHOST=gaya.idris.fr
84typeset -r REMOTE_RSYNC=/u/rech/ces/rces452/RSYNC/bin/rsync
85
86#====================================================
87# Source Ferret
88source /home/rech/psl/rpsl655/.atlas_env_ulam_bash
89
90#====================================================
91# Source tools
92module load netcdf
93module load nco
94module load cdo
95
96#====================================================
97# Specific for ocean additionnal diagnostic
98export FER_GO="$FER_GO /home/rech/ces/rces599/Cpl/TKE /home/rech/ces/rces599/Cpl/TKE/GO /home/rech/ces/rces452/IGCM_POST_UTIL/JNL"
99export FER_PALETTE="$FER_PALETTE /home/rech/ces/rces599/Cpl/TKE/PALET"
100export DISPLAY=:1
101
102#=========================================================
103# Host specific DIRECTORIES
104#====================================================
105
106#====================================================
107#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
108typeset -r R_EXE="${MODIPSL}/bin"
109
110#====================================================
111#- SUBMIT_DIR : submission dir
112typeset SUBMIT_DIR=${SUBMIT_DIR:=${LOADL_STEP_INITDIR}}
113
114#====================================================
115#- ARCHIVE
116typeset -r ARCHIVE=$HOMEGAYA
117
118#====================================================
119#- IN
120typeset -r R_IN=${R_IN:=/u/rech/psl/rpsl035/IGCM}
121
122#====================================================
123#- OUT
124typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
125
126#====================================================
127#- OUT_POST
128typeset -r R_OUT_POST=${WORKDIR}/IGCM_OUT
129
130#====================================================
131#- RUN_DIR_PATH : Temporary working directory (=> TMP)
132typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${TMPDIR}}
133
134#D-#==================================================
135#D-function IGCM_sys_RshMaster
136#D-* Purpose: Master rsh command
137#D-* Examples:
138#D-
139function IGCM_sys_RshMaster {
140    #set -vx
141    IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
142    rsh brodie exec /bin/ksh <<-EOF
143    export libIGCM=${libIGCM_SX}
144    . ${libIGCM_SX}/libIGCM_debug/libIGCM_debug.ksh
145    . ${libIGCM_SX}/libIGCM_card/libIGCM_card.ksh
146    ${@}
147EOF
148    if [ $? -gt 0 ] ; then
149        echo "IGCM_sys_RshMaster : erreur."
150        IGCM_debug_Exit "IGCM_sys_RshMaster"
151    fi
152    IGCM_debug_PopStack "IGCM_sys_RshMaster"
153}
154
155#D-#==================================================
156#D-function IGCM_sys_RshArchive
157#D-* Purpose: Archive rsh command
158#D-* Examples:
159#D-
160function IGCM_sys_RshArchive {
161    IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
162    /bin/ksh <<-EOF
163    ${@}
164EOF
165    if [ $? -gt 0 ] ; then
166        echo "IGCM_sys_RshArchive : erreur."
167        IGCM_debug_Exit "IGCM_sys_RshArchive"
168    fi
169    IGCM_debug_PopStack "IGCM_sys_RshArchive"
170}
171
172#D-#==================================================
173#D-function IGCM_sys_Nb_files_archive
174#D-* Purpose: Count files on Archive filesystem
175#D-* Examples:
176#D-
177function IGCM_sys_Nb_files_archive {
178   ls ${@} 2>/dev/null | wc -l
179   if [ $? -gt 0 ] ; then
180       echo "IGCM_sys_RshArchive : erreur."
181   fi
182}
183
184#D-#==================================================
185#D-function IGCM_sys_RshPost
186#D-* Purpose: Master rsh command
187#D-* Examples:
188#D-
189function IGCM_sys_RshPost {
190    IGCM_debug_PushStack "IGCM_sys_RshPost" $@
191    if ( $DEBUG_sys ) ; then
192        echo "IGCM_sys_RshPost :" $@
193    fi
194    /bin/ksh ${@}
195    if [ $? -gt 0 ] ; then
196        echo "IGCM_sys_RshPost : erreur."
197        IGCM_debug_Exit "IGCM_sys_RshPost"
198    fi
199    IGCM_debug_PopStack "IGCM_sys_RshPost"
200}
201
202#D-#==================================================
203#D-function IGCM_sys_Mkdir
204#D-* Purpose: Master locale mkdir command
205#D-* Examples:
206#D-
207function IGCM_sys_Mkdir {
208    IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
209    if ( $DEBUG_sys ) ; then
210        echo "IGCM_sys_Mkdir :" $@
211    fi
212    if [ ! -d ${1} ]; then
213        \mkdir -p $1
214        if [ $? -gt 0 ] ; then
215            echo "IGCM_sys_Mkdir : erreur."
216            IGCM_debug_Exit "IGCM_sys_Mkdir"
217        fi
218    fi
219    # vérification :
220    if [ ! -d ${1} ] ; then
221        echo "IGCM_sys_Mkdir : erreur."
222        IGCM_debug_Exit "IGCM_sys_Mkdir"
223    fi
224    IGCM_debug_PopStack "IGCM_sys_Mkdir"
225}
226
227#D-#==================================================
228#D-function IGCM_sys_MkdirArchive
229#D-* Purpose: Mkdir on Archive
230#D-* Examples:
231#D-
232function IGCM_sys_MkdirArchive {
233    IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
234    if ( $DEBUG_sys ) ; then
235        echo "IGCM_sys_MkdirArchive :" $@
236    fi
237    #- creation de repertoire sur le serveur fichier
238    if [ ! -d ${1} ]; then 
239        \mkdir -p $1
240        if [ $? -gt 0 ] ; then
241            echo "IGCM_sys_MkdirArchive : erreur."
242            IGCM_debug_Exit "IGCM_sys_MkdirArchive"
243        fi
244    fi
245    # vérification ?? :
246    if [ ! -d ${1} ] ; then
247        echo "IGCM_sys_MkdirArchive : erreur."
248        IGCM_debug_Exit "IGCM_sys_MkdirArchive"
249    fi
250    IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
251}
252
253#D-#==================================================
254#D-function IGCM_sys_MkdirWork
255#D-* Purpose: Mkdir on Work
256#D-* Examples:
257#D-
258function IGCM_sys_MkdirWork {
259    IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
260    if ( $DEBUG_sys ) ; then
261        echo "IGCM_sys_MkdirWork :" $@
262    fi
263    #- creation de repertoire sur le serveur fichier
264    if [ ! -d ${1} ]; then 
265        \mkdir -p $1
266        if [ $? -gt 0 ] ; then
267            echo "IGCM_sys_MkdirWork : erreur."
268            IGCM_debug_Exit "IGCM_sys_MkdirWork"
269        fi
270    fi
271    # vérification ?? :
272    if [ ! -d ${1} ] ; then
273        echo "IGCM_sys_MkdirWork : erreur."
274        IGCM_debug_Exit "IGCM_sys_MkdirWork"
275    fi
276    IGCM_debug_PopStack "IGCM_sys_MkdirWork"
277}
278#IGCM_sys_MkdirWork ${RUN_DIR_PATH}
279#echo "RUN_DIR_PATH ${RUN_DIR_PATH} ok."
280
281#D-#==================================================
282#D-function IGCM_sys_Cd
283#D-* Purpose: master cd command
284#D-* Examples:
285#D-
286function IGCM_sys_Cd {
287    IGCM_debug_PushStack "IGCM_sys_Cd" $@
288    if ( $DEBUG_sys ) ; then
289        echo "IGCM_sys_Cd :" $@
290    fi
291    \cd $1
292    if [ $? -gt 0 ] ; then
293        echo "IGCM_sys_Cd : erreur."
294        IGCM_debug_Exit "IGCM_sys_Cd"
295    fi
296    IGCM_debug_PopStack "IGCM_sys_Cd"
297}
298
299#D-#==================================================
300#D-function IGCM_sys_Chmod
301#D-* Purpose: Chmod
302#D-* Examples:
303#D-
304function IGCM_sys_Chmod {
305    IGCM_debug_PushStack "IGCM_sys_Chmod" $@
306    if ( $DEBUG_sys ) ; then
307        echo "IGCM_sys_Chmod :" $@
308    fi
309    if [ $DRYRUN -le 1 ]; then
310        \chmod $@
311        if [ $? -gt 0 ] ; then
312            echo "IGCM_sys_Chmod : erreur."
313            IGCM_debug_Exit "IGCM_sys_Chmod"
314        fi
315    else
316        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
317    fi
318    IGCM_debug_PopStack "IGCM_sys_Chmod"
319}
320
321#D-#==================================================
322#D-function IGCM_sys_FileSize
323#D-* Purpose: Filesize
324#D-* Examples:
325#D-
326function IGCM_sys_FileSize {
327    IGCM_debug_PushStack "IGCM_sys_FileSize" $@
328
329    typeset sizeF
330    set +A sizeF -- $( ls -la ${1} )
331    if [ $? -gt 0 ] ; then
332        IGCM_debug_Exit "IGCM_sys_FileSize"
333    fi
334    eval ${2}=${sizeF[4]}
335
336    IGCM_debug_PopStack "IGCM_sys_FileSize"
337}
338
339#D-#==================================================
340#D-function IGCM_sys_TestDir
341#D-* Purpose: Test Directory that must exists
342#D-* Examples:
343#D-
344function IGCM_sys_TestDir {
345    IGCM_debug_PushStack "IGCM_sys_TestDir" $@
346    if ( $DEBUG_sys ) ; then
347        echo "IGCM_sys_TestDir :" $@
348    fi
349    if [ ! -d ${1} ]; then
350        echo "IGCM_sys_TestDir : Directory $1 does not exist."
351        IGCM_debug_Exit "IGCM_sys_TestDir"
352    fi
353    IGCM_debug_PopStack "IGCM_sys_TestDir"
354}
355
356#D-#==================================================
357#D-function IGCM_sys_TestDirArchive
358#D-* Purpose: Test Directory that must exists on Archive
359#D-* Examples:
360#D-
361function IGCM_sys_TestDirArchive {
362    IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
363    if ( $DEBUG_sys ) ; then
364        echo "IGCM_sys_TestDirArchive :" $@
365    fi
366    if [ ! -d ${1} ]; then
367        echo "IGCM_sys_TestDirArchive : Directory $1 does not exist on ${ARCHIVE}."
368        IGCM_debug_Exit "IGCM_sys_TestDirArchive"
369    fi
370    IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
371}
372
373#D-#==================================================
374#D-function IGCM_sys_TestFileArchive
375#D-* Purpose: Test file that must NOT EXISTS on Archive
376#D-* Examples:
377#D-
378function IGCM_sys_TestFileArchive {
379    IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
380    if ( $DEBUG_sys ) ; then
381        echo "IGCM_sys_TestFileArchive :" $@
382    fi
383    typeset RET
384
385    mfls ${1} | grep ${1} > /dev/null 2>&1
386    RET=$?
387    if [ ${RET} -gt 0 ]; then
388        IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
389        return 1
390    else
391        IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
392        return 0
393    fi
394}
395
396#D-#==================================================
397#D-function IGCM_sys_Tree
398#D-* Purpose: Tree directories with files on ${ARCHIVE}
399#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
400#D-
401function IGCM_sys_Tree {
402    IGCM_debug_PushStack "IGCM_sys_Tree" $@
403    if ( $DEBUG_sys ) ; then
404        echo "IGCM_sys_Tree :" $@
405    fi
406
407    \mfls -r $@
408
409    IGCM_debug_PopStack "IGCM_sys_Tree"
410}
411
412#D-#==================================================
413#D-function IGCM_sys_Tar
414#D-* Purpose: master un-tar command
415#D-* Examples:
416#D-
417function IGCM_sys_Tar {
418    IGCM_debug_PushStack "IGCM_sys_Tar" $@
419    if ( $DEBUG_sys ) ; then
420        echo "IGCM_sys_Tar :" $@
421    fi
422    \tar cvf $@
423    if [ $? -gt 0 ] ; then
424        echo "IGCM_sys_Tar : erreur."
425        IGCM_debug_Exit "IGCM_sys_Tar"
426    fi
427    \tar tvf $1
428
429    IGCM_debug_PopStack "IGCM_sys_Tar"
430}
431
432#D-#==================================================
433#D-function IGCM_sys_UnTar
434#D-* Purpose: master un-tar command
435#D-* Examples:
436#D-
437function IGCM_sys_UnTar {
438    IGCM_debug_PushStack "IGCM_sys_UnTar" $@
439    if ( $DEBUG_sys ) ; then
440        echo "IGCM_sys_UnTar :" $@
441    fi
442    \tar xvf $1
443    if [ $? -gt 0 ] ; then
444        echo "IGCM_sys_UnTar : erreur."
445        IGCM_debug_Exit "IGCM_sys_UnTar"
446    fi
447    IGCM_debug_PopStack "IGCM_sys_UnTar"
448}
449
450#D-#==================================================
451#D-function IGCM_sys_QsubPost
452#D-* Purpose: Qsub new job on scalaire
453#D-* Examples:
454#D-
455function IGCM_sys_QsubPost {
456    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
457    if ( $DEBUG_sys ) ; then
458        echo "IGCM_sys_QsubPost :" $@
459    fi
460    llsubmit -o ${POST_DIR}/$1.${PeriodDateEnd}.out ${libIGCM}/$1.job
461    if [ $? -gt 0 ] ; then
462        echo "IGCM_sys_QsubPost : erreur."
463        IGCM_debug_Exit "IGCM_sys_QsubPost"
464    fi
465    IGCM_debug_PopStack "IGCM_sys_QsubPost"
466}
467
468#D-*************************
469#D- File transfer functions
470#D-*************************
471#D-
472
473#D-#==================================================
474#D-function IGCM_sys_Rsync_out
475#D-* Purpose: treat return val of rsync
476#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
477#D-  Error values and explanations can depend on your system version.
478function IGCM_sys_Rsync_out {
479    RET=$1
480    if [ ! $RET ] ; then
481        echo "rsync error !"
482    fi
483
484    if [ $MYLANG = "fr" ]; then
485        case $RET in
486            0)  return ;;
487            1)  echo "Erreur de rsync ; RERR_SYNTAX : "
488                echo "Erreur de syntaxe ou d'utilisation."
489                return;;
490            2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
491                echo "Incompatibilité de protocole."
492                return;;
493            3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
494                echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
495                echo "répertoires"
496                return;;
497            4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
498                echo "Action demandée non supportée : une tentative de manipulation de"
499                echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
500                echo "été faite ; ou une option qui est supportée par le  client  mais"
501                echo "pas par le serveur a été spécifiée."
502                return;;
503            10) echo "Erreur de rsync ; RERR_SOCKETIO"
504                echo "Erreur dans le socket d'entrée sortie"
505                return;;
506            11) echo "Erreur de rsync ; RERR_FILEIO"
507                echo "Erreur d'entrée sortie fichier"
508                return;;
509            12) echo "Erreur de rsync ; RERR_STREAMIO"
510                echo "Erreur dans flux de donnée du protocole rsync"
511                return;;
512            13) echo "Erreur de rsync ; RERR_MESSAGEIO"
513                echo "Erreur avec les diagnostics du programme"
514                return;;
515            14) echo "Erreur de rsync ; RERR_IPC"
516                echo "Erreur dans le code IPC"
517                return;;
518            20) echo "Erreur de rsync ; RERR_SIGNAL"
519                echo "SIGUSR1 ou SIGINT reçu"
520                return;;
521            21) echo "Erreur de rsync ; RERR_WAITCHILD"
522                echo "Une erreur retournée par waitpid()"
523                return;;
524            22) echo "Erreur de rsync ; RERR_MALLOC"
525                echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
526                return;;
527            23) echo ""
528                echo "Erreur fichier inexistant"
529                return;;
530            30) echo "Erreur de rsync ; RERR_TIMEOUT"
531                echo "Temps d'attente écoulé dans l'envoi/réception de données"
532                return;;
533            *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
534                return;;
535        esac
536    elif [ $MYLANG = "en" ] ; then
537        case $RET in
538            0)  return;;               
539            1)  echo "rsync error : Syntax or usage error "
540                return;;
541            2)  echo "rsync error : Protocol incompatibility "
542                return;;
543            3)  echo "rsync error : Errors selecting input/output files, dirs"
544                return;;
545            4)  echo "rsync error : Requested action not supported: an attempt"
546                echo "was made to manipulate 64-bit files on a platform that cannot support"
547                echo "them; or an option was specified that is supported by the client and"
548                echo "not by the server."
549                return;;
550            5)  echo "rsync error : Error starting client-server protocol"
551                return;;
552            10) echo "rsync error : Error in socket I/O "
553                return;;
554            11) echo "rsync error : Error in file I/O "
555                return;;
556            12) echo "rsync error : Error in rsync protocol data stream "
557                return;;
558            13) echo "rsync error : Errors with program diagnostics "
559                return;;
560            14) echo "rsync error : Error in IPC code "
561                return;;
562            20) echo "rsync error : Received SIGUSR1 or SIGINT "
563                return;;
564            21) echo "rsync error : Some error returned by waitpid() "
565                return;;
566            22) echo "rsync error : Error allocating core memory buffers "
567                return;;
568            23) echo "rsync error : Partial transfer due to error"
569                return;;
570            24) echo "rsync error : Partial transfer due to vanished source files"
571                return;;
572            30) echo "rsync error : Timeout in data send/receive "
573                return;;
574            *)  echo "rsync error : return code of rsync unknown :" $RET
575                return;;
576        esac
577    else
578        echo "unknown language $MYLANG."
579        return
580    fi
581}
582   
583#D-#==================================================
584#D-function IGCM_sys_Cp
585#D-* Purpose: generic cp
586#D-* Examples:
587#D-
588function IGCM_sys_Cp {
589    IGCM_debug_PushStack "IGCM_sys_Cp" $@
590    if ( $DEBUG_sys ) ; then
591        echo "IGCM_sys_Cp :" $@
592    fi
593
594    typeset RET
595
596    echo cp $@ > out_rsync 2>&1
597    \cp $@ >> out_rsync 2>&1
598    RET=$?
599
600    if [ ${RET} -gt 0 ] ; then
601        echo "IGCM_sys_Cp : error."
602        cat out_rsync
603        IGCM_debug_Exit "IGCM_sys_Cp"
604    fi
605    IGCM_debug_PopStack "IGCM_sys_Cp"
606}
607
608#D-#==================================================
609#D-function IGCM_sys_Rm
610#D-* Purpose: generic rm
611#D-* Examples:
612#D-
613function IGCM_sys_Rm {
614    IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
615    if ( $DEBUG_sys ) ; then
616        echo "IGCM_sys_Rm :" $@
617    fi
618
619    typeset RET
620
621    echo rm $@ > out_rsync 2>&1
622    \rm $@ >> out_rsync 2>&1
623    RET=$?
624
625    if [ ${RET} -gt 0 ] ; then
626        echo "IGCM_sys_Rm : error."
627        cat out_rsync
628        IGCM_debug_Exit "IGCM_sys_Rm"
629    fi
630    IGCM_debug_PopStack "IGCM_sys_Rm"
631}
632
633#D-#==================================================
634#D-function IGCM_sys_Mv
635#D-* Purpose: generic move
636#D-* Examples:
637#D-
638function IGCM_sys_Mv {
639    IGCM_debug_PushStack "IGCM_sys_Mv" $@
640    if ( $DEBUG_sys ) ; then
641        echo "IGCM_sys_Mv :" $@
642    fi
643
644    typeset RET
645
646    echo mv $@ > out_rsync 2>&1
647    \mv $@ >> out_rsync 2>&1
648    RET=$?
649
650    if [ ${RET} -gt 0 ] ; then
651        echo "IGCM_sys_Mv : error in mv."
652        cat out_rsync
653        IGCM_debug_Exit "IGCM_sys_Mv"
654    fi
655
656    IGCM_debug_PopStack "IGCM_sys_Mv"
657}
658
659#D-#==================================================
660#D-function IGCM_sys_Put_Dir
661#D-* Purpose: Copy a complete directory on $(ARCHIVE)
662#D-* Examples:
663#D-
664function IGCM_sys_Put_Dir {
665    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
666    if ( $DEBUG_sys ) ; then
667        echo "IGCM_sys_Put_Dir :" $@
668    fi
669    if [ $DRYRUN = 0 ]; then
670        if [ ! -d ${1} ] ; then
671            echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
672            IGCM_debug_PopStack "IGCM_sys_Put_Dir"
673            return
674        fi
675
676        typeset RET
677
678        # Only if we use rsync
679        #IGCM_sys_TestDirArchive $( dirname $2 )
680        #
681        #USUAL WAY
682        rcp -r $1 gaya:$2 > out_rsync 2>&1
683        RET=$?
684
685        if [ ${RET} -gt 0 ] ; then
686            echo "IGCM_sys_Put_Dir : error."
687            cat out_rsync
688            IGCM_debug_Exit "IGCM_sys_Put_Dir"
689        fi
690    else
691        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
692    fi
693    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
694}
695
696#D-#==================================================
697#D-function IGCM_sys_Get_Dir
698#D-* Purpose: Copy a complete directory from $(ARCHIVE)
699#D-* Examples:
700#D-
701function IGCM_sys_Get_Dir {
702    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
703    if ( $DEBUG_sys ) ; then
704        echo "IGCM_sys_Get_Dir :" $@
705    fi
706    if [ $DRYRUN = 0 ]; then
707        if [ ! -d ${1} ] ; then
708            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
709            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
710            return
711        fi
712
713        typeset RET
714
715        #USUAL WAY
716        rcp -rp gaya:$1 $2 > out_rsync 2>&1
717        RET=$?
718
719        if [ ${RET} -gt 0 ] ; then
720            echo "IGCM_sys_Get_Dir : error."
721            cat out_rsync
722            IGCM_debug_Exit "IGCM_sys_Get_Dir"
723        fi
724    else
725        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
726    fi
727    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
728}
729
730#D-#==================================================
731#D-function IGCM_sys_Get_Master
732#D-* Purpose: Copy a complete directory from MASTER filesystem
733#D-* Examples:
734#D-
735function IGCM_sys_Get_Master {
736    IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
737    if ( $DEBUG_sys ) ; then
738        echo "IGCM_sys_Get_Master :" $@
739    fi
740    if [ $DRYRUN = 0 ]; then
741        TEST=$( rsh brodie -n "[ -d $1 ] && echo 1 || echo 0" )
742        if [ ${TEST} -ne 1 ] ; then
743            echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ON BRODIE."
744            IGCM_debug_PopStack "IGCM_sys_Get_Master"
745            return
746        fi
747
748        typeset RET
749        sleep 60
750
751        #USUAL WAY
752        rcp -r brodie:$1 $2 > out_rsync 2>&1
753        RET=$?
754
755        if [ ${RET} -gt 0 ] ; then
756            echo "IGCM_sys_Get_Master : error."
757            cat out_rsync
758            IGCM_debug_Exit "IGCM_sys_Get_Master"
759        fi
760    else
761        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
762    fi
763    IGCM_debug_PopStack "IGCM_sys_Get_Master"
764}
765
766#D-#==================================================
767#D-function IGCM_sys_Put_Out
768#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
769#D-* Examples:
770#D-
771function IGCM_sys_Put_Out {
772    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
773    if ( $DEBUG_sys ) ; then
774        echo "IGCM_sys_Put_Out :" $@
775    fi
776    if [ $DRYRUN = 0 ]; then
777        if [ ! -f ${1} ] ; then
778            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
779            IGCM_debug_PopStack "IGCM_sys_Put_Out"
780            return 1
781        fi
782
783        typeset RET
784        #
785        IGCM_sys_Chmod 444 ${1}
786        #
787        # Only if we use rsync
788        #IGCM_sys_TestDirArchive $( dirname $2 )
789        #
790        #USUAL WAY
791        mfput $1 $2 > out_rsync 2>&1
792        RET=$?
793
794#       #RSYNC WITH NETWORK RSH CALL
795#       echo ${RSYNC_FRONT} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
796#       ${RSYNC_FRONT} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
797
798#       #RSYNC WITH NFS USE
799#       echo ${RSYNC_FRONT} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
800#       ${RSYNC_FRONT} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
801
802#       RET=$?
803#       IGCM_sys_Rsync_out $RET
804
805#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
806#       (( RET=RET+$? ))
807
808        if [ ${RET} -gt 0 ] ; then
809            echo "IGCM_sys_Put_Out : error."
810            cat out_rsync
811            IGCM_debug_Exit "IGCM_sys_Put_Out"
812        fi
813    else
814        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
815    fi
816    IGCM_debug_PopStack "IGCM_sys_Put_Out"
817    return 0
818}
819
820#D-#==================================================
821#D-function IGCM_sys_Get
822#D-* Purpose: Get a file from ${ARCHIVE}
823#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
824#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
825function IGCM_sys_Get {
826    IGCM_debug_PushStack "IGCM_sys_Get" $@
827
828    typeset DEST RET dm_liste ifile target
829
830    if ( $DEBUG_sys ) ; then
831        echo "IGCM_sys_Get :" $@
832    fi
833    if [ $DRYRUN -le 2 ]; then
834        if [ X${1} = X'/l' ] ; then
835            # test if the first file is present in the old computation :
836            eval set +A dm_liste \${${2}}
837        else
838            dm_liste=${1}
839        fi
840        eval DEST=\${${#}}
841
842        # test if the (first) file is present in the old computation :
843        IGCM_sys_TestFileArchive ${dm_liste[0]}
844        RET=$?
845        if [ ${RET} -gt 0 ] ; then
846            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
847            IGCM_debug_Exit "IGCM_sys_Get"
848            IGCM_debug_PopStack "IGCM_sys_Get"
849            return
850        fi
851
852        # SD : dm_liste is not suited for computing job
853        #      because we change filename during transfert
854        #      dm_liste is better suited for post-treatment
855        # SD : dm_liste necessary only with RSYNC
856
857        #dm_liste=" "
858        #(( ifile=1 ))
859        #while [ $ifile -lt $# ] ; do
860        #    dm_liste=$( eval echo ${dm_liste[*]} " "\${${ifile}} )
861        #    (( ifile = ifile + 1 ))
862        #done
863        #DEST=$( eval echo \${${#}} )
864
865        #USUAL WAY
866        mfget ${dm_liste[*]} ${DEST} > out_rsync 2>&1
867        RET=$?
868
869#       #RSYNC WITH NETWORK RSH CALL
870#       echo ${RSYNC_FRONT} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
871#       ${RSYNC_FRONT} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
872
873#       #RSYNC WITH NFS USE
874#       echo ${RSYNC_FRONT} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
875#       ${RSYNC_FRONT} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
876
877#       RET=$?
878#       IGCM_sys_Rsync_out $RET
879
880#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
881#       (( RET=RET+$? ))
882
883        if [ ${RET} -gt 0 ] ; then
884            echo "IGCM_sys_Get : copy error."
885            cat out_rsync
886            IGCM_debug_Exit "IGCM_sys_Get"
887        fi
888    else
889        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
890    fi
891    IGCM_debug_PopStack "IGCM_sys_Get"
892}
893
894#D-#==================================================
895#D-function IGCM_sys_Put_Dods
896#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
897#D-* Examples:
898#D-
899function IGCM_sys_Put_Dods {
900    IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
901    if ( $DEBUG_sys ) ; then
902        echo "IGCM_sys_Put_Dods :" $@
903    fi
904    if [ $DRYRUN = 0 ]; then
905        if [ ! -d ${R_SAVE}/${1} ] ; then
906            echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
907            IGCM_debug_PopStack "IGCM_sys_Put_Dods"
908            return
909        fi
910
911        typeset RET
912        #
913        rsh gaya exec /bin/ksh <<EOF
914        cd ${R_SAVE}
915        /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${config_UserChoices_TagName}/${config_UserChoices_JobName}/${1} > /dev/null 2>&1
916        /sbin/chmod -R u+w ${R_SAVE}/${1}
917        /usr/local/bin/dods_cp ${1} DODS/pub/${LOGIN}/${config_UserChoices_TagName}/${config_UserChoices_JobName} > /dev/null 2>&1
918        /sbin/chmod -R +rX ${R_SAVE}/${1}
919        /sbin/chmod -R u+w ${R_SAVE}/${1}
920EOF
921        RET=$?
922
923        if [ ${RET} -gt 0 ] ; then
924            echo "IGCM_sys_Put_Dods : error."
925            cat out_dods
926            IGCM_debug_Exit "IGCM_sys_Put_Dods"
927        fi
928    else
929        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
930    fi
931    IGCM_debug_PopStack "IGCM_sys_Put_Dods"
932}
933
934############################################################## A REVOIR !!
935
936#D-#==================================================
937#D-function IGCM_sys_Rapatrie
938#D-* Purpose: Rapatrie
939#D-* Examples:
940#D-
941function IGCM_sys_Rapatrie {
942    IGCM_debug_PushStack "IGCM_sys_Rapatrie" $@
943    if ( $DEBUG_sys ) ; then
944        echo "IGCM_sys_Rapatrie :" $@
945    fi
946
947    typeset RET=0
948
949    IGCM_sys_Get ${R_STOCKAGE}/$2 $1 ;
950    let $(( RET=RET+$? ))
951    IGCM_sys_Cd $1 ;
952    let $(( RET=RET+$? ))
953    IGCM_sys_UnTar $2 ;
954    let $(( RET=RET+$? ))
955
956    if [ ${RET} -gt 0 ] ; then
957        echo "IGCM_sys_Rapatrie : erreur."
958        IGCM_debug_Exit "IGCM_sys_Rapatrie"
959    fi
960    IGCM_debug_PopStack "IGCM_sys_Rapatrie"
961}
962
963############################################################## A FINIR !!
964
965#D-#==================================================
966#D-function IGCM_sys_GetDate_FichWork
967#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
968#D-* Examples:
969#D-
970function IGCM_sys_GetDate_FichWork {
971    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
972    if ( $DEBUG_sys ) ; then
973        echo "IGCM_sys_GetDate_FichWork :" $@
974    fi
975    # donne la date filesys d'un fichier sur la machine work
976    IGCM_debug_PopStack "IGCM_sys_FichWork"
977}
978
979#D-#==================================================
980#D-function IGCM_sys_GetDate_FichArchive
981#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
982#D-* Examples:
983#D-
984function IGCM_sys_GetDate_FichArchive {
985    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
986    if ( $DEBUG_sys ) ; then
987        echo "IGCM_sys_GetDate_FichArchive :" $@
988    fi
989    IGCM_debug_PopStack "IGCM_sys_FichArchive"
990}
991
992##############################################################
993# REBUILD OPERATOR
994
995function IGCM_sys_rebuild {
996    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
997    if ( $DEBUG_sys ) ; then
998        echo "IGCM_sys_rebuild :" $@
999    fi
1000    /home/rech/ces/rces452/REBUILD/bin/rebuild -f -o $@
1001    if [ $? -gt 0 ] ; then
1002       echo "IGCM_sys_rebuild : erreur ${@}."
1003       IGCM_debug_Exit "rebuild"
1004    fi
1005
1006    IGCM_debug_PopStack "IGCM_sys_rebuild"
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    /usr/local/pub/nco/3.9.6/bin/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=/usr/local/pub/nco/3.9.6/bin/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#     /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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    /usr/local/pub/nco/3.9.6/bin/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.