source: tags/libIGCM_v1_5/libIGCM_sys/libIGCM_sys_mercurex9.ksh @ 293

Last change on this file since 293 was 228, checked in by mmaipsl, 14 years ago

Supress buggy space after HOST and LOGIN variables.
Add an optionnal argument to all IGCM_sys_Put_Out functions :
if any 3thrd argument is there, file won't be protected. If
there is no argument (default in libIGCM), file will be set read-only.

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