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

Last change on this file since 217 was 217, checked in by sdipsl, 14 years ago

Avoid side effect with user environment. Do not define read-only varible potentially defined by system environment.

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