source: tags/libIGCM_v1_9/libIGCM_sys/libIGCM_sys_mercurex9.ksh @ 1170

Last change on this file since 1170 was 366, checked in by mmaipsl, 14 years ago

In system libraries, make some i variables local to there subroutines.

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