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

Last change on this file since 434 was 434, checked in by mmaipsl, 13 years ago

correct a typo in Message send by mail.

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