source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_vargas.ksh @ 476

Last change on this file since 476 was 476, checked in by mafoipsl, 13 years ago

On vargas, use standard Script_Output file name to follow libIGCM rules for Script_Output (saving, cleaning).

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