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

Last change on this file since 128 was 128, checked in by mmaipsl, 15 years ago

Add experience type management : JobType? = DEB(ug), DEV(elopment), RUN (default)
(No propoagation in Post-treatment for instance).
Put "Where do we run ?" question in libIGCM_sys.

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