source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh @ 61

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