source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_mercurex9.ksh @ 182

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