source: tags/libIGCM_v1_12/libIGCM_sys/libIGCM_sys_iitm.ksh @ 1456

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