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

Last change on this file since 428 was 428, checked in by sdipsl, 13 years ago

Add iitm AIX6 machine

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