source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_iitm.ksh @ 782

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