source: tags/libIGCM_v1_5/libIGCM_sys/libIGCM_sys_titane.ksh @ 487

Last change on this file since 487 was 244, checked in by aclsce, 14 years ago

Added correction done for all the machines except for titane :
Add an optionnal argument to all IGCM_sys_Put_Out functions :
if any 3thrd argument is there, file won't be protected. If
there is no argument (default in libIGCM), file will be set read-only.

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