source: tags/libIGCM_v1_4/libIGCM_sys/libIGCM_sys_vargas.ksh

Last change on this file was 173, checked in by mafoipsl, 15 years ago

Add DRYRUN capability in Sys_Mv for all systems supported.

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