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

Last change on this file since 1137 was 308, checked in by mafoipsl, 14 years ago

Include changeset [305] into libIGCM_v1_7.

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