source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_titane.ksh @ 437

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

Send mail notification when computing job stops
It could be that we send a notification if a post-processing job stops in PROD mode ---> need some refactoring and caution...

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