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

Last change on this file since 450 was 450, checked in by sdipsl, 13 years ago

Homogenize sleeping period in libIGCM_sys

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