source: tags/libIGCM_v1_9/libIGCM_sys/libIGCM_sys_titane.ksh @ 552

Last change on this file since 552 was 364, checked in by sdipsl, 14 years ago

Avoid infinite loop when submitting to cesium due to interaction between local and global variable i.

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