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

Last change on this file since 404 was 404, checked in by acosce, 13 years ago

Aco : add "\" before "rm out_rsync" to force the remove (without asking
befor removing the file)

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