source: tags/libIGCM_v1_12/libIGCM_sys/libIGCM_sys_vargas.ksh @ 566

Last change on this file since 566 was 566, checked in by mafoipsl, 12 years ago

On vargas : add temporary file suppression and add $LOGIN to have different names for different login. NB : No problem on other systems.

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