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

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

First draft for ulam

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