source: tags/libIGCM_v1/libIGCM_sys/libIGCM_sys_zahir.ksh @ 1456

Last change on this file since 1456 was 2, checked in by mmaipsl, 16 years ago

MM: import first trunk version of libIGCM.

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