source: tags/libIGCM_v1_8-old/libIGCM_sys/libIGCM_sys_titane.ksh

Last change on this file was 324, checked in by mafoipsl, 14 years ago

Consolidate RshPost? for CESIUM.

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