source: tags/libIGCM_v1_7/libIGCM_sys/libIGCM_sys_titane.ksh @ 302

Last change on this file since 302 was 288, checked in by mafoipsl, 14 years ago

Add SUBLIT_DIR in messgae snt at the end of each simulation. Complete messages in clean_month.

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