source: tags/libIGCM_v2.0_rc1/libIGCM_sys/libIGCM_sys_iitm.ksh @ 1137

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