source: branches/libIGCM_MPI_OpenMP/libIGCM_sys/libIGCM_sys_titane.ksh @ 496

Last change on this file since 496 was 491, checked in by mmaipsl, 13 years ago

Add local variable declarations in new IGCM_sys_build_execution_scripts function.

  • Property svn:keywords set to Revision Author Date
File size: 46.7 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for Titane
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=titane
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# rsync with path
78typeset -r RSYNC=/usr/bin/rsync
79# RSYNC_opt args to rsync
80typeset -r RSYNC_opt="-va"
81# ie storage filesystem
82typeset -r RHOST=titane
83
84#====================================================
85# Source default environment
86#====================================================
87. /etc/profile
88
89#====================================================
90# Set environment tools (ferret, nco, cdo)
91#====================================================
92. /home/cont003/p86ipsl/.atlas_env_titane_ksh
93
94#====================================================
95# Specific for ocean additionnal diagnostic
96export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
97export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
98
99#====================================================
100# Host specific DIRECTORIES
101#====================================================
102
103#====================================================
104#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
105typeset -r R_EXE="${MODIPSL}/bin"
106
107#====================================================
108#- SUBMIT_DIR : submission dir
109typeset SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
110
111#====================================================
112#- ARCHIVE
113typeset -r ARCHIVE=${DMFDIR}
114
115#====================================================
116#- Mirror libIGCM from titane to cesium if needed
117ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $2}' )
118if [ ! ${ROOTSYS} = "home" ] ; then
119    typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
120else
121    typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
122fi
123
124#====================================================
125#- libIGCM_POST
126if ( ${MirrorlibIGCM} ) ; then
127    PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
128    typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
129else
130    typeset -r libIGCM_POST=${libIGCM}
131fi
132
133#====================================================
134#- IN
135typeset -r R_IN=${R_IN:=/dmnfs/cont003/p86ipsl/IGCM}
136typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
137
138#====================================================
139#- OUT
140typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
141
142#====================================================
143#- OUT_SCR (ONLY FOR double copy an scratch)
144typeset -r R_OUT_SCR=${SCRATCHDIR}/IGCM_OUT
145
146#====================================================
147#- OUT_POST
148typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
149
150#====================================================
151#- RUN_DIR_PATH : Temporary working directory (=> TMP)
152if [ ! X${LSB_QUEUE} = Xmono ] ; then
153    typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${LSB_JOBID}}
154else
155    typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/TMPDIR_IGCM/${LSB_JOBID}}
156fi
157
158#====================================================
159#- BIG_DIR : BIG_DIR to store files waiting for rebuild
160typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
161
162#====================================================
163#- HOST_MPIRUN_COMMAND
164typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
165
166#====================================================
167#- Max number of arguments passed to nco operator or demigration command
168UNIX_MAX_LIMIT=360
169
170NUM_COREPERNODE=8
171       
172
173#D-#==================================================
174#D-function IGCM_sys_RshMaster
175#D-* Purpose: Just a fake command to wrapp
176#D-           IGCM_card call in post-treatment
177#D-           Ulam do not see brodie filesystem
178#D-           Cesium do not see all mercure filesystem
179#D-           That's why we need this hack.
180#D-* Examples:
181#D-
182function IGCM_sys_RshMaster {
183    IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
184    /bin/ksh <<-EOF
185    export libIGCM=${libIGCM}
186    export DEBUG_debug=${DEBUG_debug}
187    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
188    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
189    ${@}
190EOF
191    if [ $? -gt 0 ] ; then
192        echo "IGCM_sys_RshMaster : erreur."
193        IGCM_debug_Exit "IGCM_sys_RshMaster"
194    fi
195    IGCM_debug_PopStack "IGCM_sys_RshMaster"
196}
197
198#D-#==================================================
199#D-function IGCM_sys_RshArchive
200#D-* Purpose: Archive rsh command
201#D-* Examples:
202#D-
203function IGCM_sys_RshArchive {
204    IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
205    /bin/ksh <<-EOF
206    ${@}
207EOF
208    if [ $? -gt 0 ] ; then
209        echo "IGCM_sys_RshArchive : erreur."
210        IGCM_debug_Exit "IGCM_sys_RshArchive"
211    fi
212    IGCM_debug_PopStack "IGCM_sys_RshArchive"
213}
214
215#D-#==================================================
216#D-function IGCM_sys_RshPost
217#D-* Purpose: Post-process rsh command
218#D-* Examples:
219#D-
220function IGCM_sys_RshPost {
221    IGCM_debug_PushStack "IGCM_sys_RshPost" $@
222    if ( $DEBUG_sys ) ; then
223        echo "IGCM_sys_RshPost :" $@
224    fi
225
226    typeset NB_ESSAI DELAI status i
227    # keep standard input for the loop onto temporary file
228    cat >tmp_IGCM_sys_RshPost_$$
229
230    #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
231    #cat tmp_IGCM_sys_RshPost_$$
232
233    if [ "X$( grep rebuild_from tmp_IGCM_sys_RshPost_$$ )" != "X" ] ; then
234        # little hack so that rebuild submission is done on titane not an cesium
235        #
236        libIGCM_POST_sed=$( echo $libIGCM_POST | sed 's/\//\\\//g' )
237        POST_DIR_sed=$( echo ${POST_DIR} | sed 's/\//\\\//g' )
238        sed "s/IGCM_sys_QsubPost/IGCM_sys_Qsub/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
239        sed "s/ rebuild_fromWorkdir/ ${libIGCM_POST_sed}\/rebuild_fromWorkdir.job/g" tmp.txt > tmp_IGCM_sys_RshPost_$$
240        sed "s/ rebuild_fromArchive/ ${libIGCM_POST_sed}\/rebuild_fromArchive.job/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
241        sed "s/Script_Post_Output=/Script_Output=${POST_DIR_sed}\//g" tmp.txt > tmp_IGCM_sys_RshPost_$$
242        #\mv tmp.txt tmp_IGCM_sys_RshPost_$$
243        #
244        #echo cat tmp_IGCM_sys_RshPost_$$ AFTER
245        #cat tmp_IGCM_sys_RshPost_$$
246        /bin/ksh <tmp_IGCM_sys_RshPost_$$
247        if [ $? -gt 0 ] ; then
248            echo "IGCM_sys_RshPost : erreur."
249            IGCM_debug_Exit "IGCM_sys_RshPost"
250        fi
251        # delete temporary file
252        \rm tmp_IGCM_sys_RshPost_$$
253    else
254        # number of tentative
255        NB_ESSAI=10
256        # time delay between tentative
257        DELAI=10
258        i=0
259        while [ $i -ne $NB_ESSAI ] ; do
260            ssh -t titane996 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
261            status=$?
262            if [ ${status} -ne 0 ];
263            then
264                sleep $DELAI
265            else
266                break
267            fi
268            let i=$i+1
269        done
270        # delete temporary file
271        \rm tmp_IGCM_sys_RshPost_$$
272
273        if [ ${status} -gt 0 ] ; then
274            echo "IGCM_sys_RshPost : erreur."
275            IGCM_debug_Exit "IGCM_sys_RshPost"
276        fi
277    fi
278    IGCM_debug_PopStack "IGCM_sys_RshPost"
279}
280
281#D-#==================================================
282#D-function IGCM_sys_SendMail
283#D-* Purpose: Send mail when simulation is over
284#D-* Examples:
285#D-
286function IGCM_sys_SendMail {
287    IGCM_debug_PushStack "IGCM_sys_SendMail" $@
288    if ( $DEBUG_sys ) ; then
289       echo "IGCM_sys_SendMail :" $@
290    fi
291
292    if ( ${ExitFlag} ) ; then
293        status=failed
294    else
295        status=completed
296    fi
297
298    ssh -t titane996 ssh platine /bin/ksh <<-EOF
299    export LOGIN=${LOGIN}
300    export config_UserChoices_JobName=${config_UserChoices_JobName}
301    export config_UserChoices_MailName=${config_UserChoices_MailName}
302    export DateBegin=${DateBegin}
303    export DateEnd=${DateEnd}
304    export R_SAVE=${R_SAVE}
305    export SUBMIT_DIR=${SUBMIT_DIR}
306    export status=${status}
307
308    cat  << END_MAIL > job_end.mail
309Dear ${LOGIN},
310
311  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
312  Job started : ${DateBegin}
313  Job ended   : ${DateEnd}
314  Output files are available in ${R_SAVE}
315  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
316END_MAIL
317
318    if [ ! -z ${config_UserChoices_MailName} ] ; then
319        mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < job_end.mail
320    elif [ -f ~/.forward ] ; then
321        mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
322    fi
323
324    sleep 10
325    rm -f job_end.mail
326EOF
327
328    if [ $? -gt 0 ] ; then
329        echo "IGCM_sys_SendMail : erreur."
330        IGCM_debug_Exit "IGCM_sys_SendMail"
331    fi
332    IGCM_debug_PopStack "IGCM_sys_SendMail"
333}
334
335#D-#==================================================
336#D-function IGCM_sys_Mkdir
337#D-* Purpose: Master locale mkdir command
338#D-* Examples:
339#D-
340function IGCM_sys_Mkdir {
341    IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
342    if ( $DEBUG_sys ) ; then
343        echo "IGCM_sys_Mkdir :" $@
344    fi
345    if [ ! -d ${1} ]; then
346        \mkdir -p $1
347        if [ $? -gt 0 ] ; then
348            echo "IGCM_sys_Mkdir : erreur."
349            IGCM_debug_Exit "IGCM_sys_Mkdir"
350        fi
351    fi
352    # vérification :
353    if [ ! -d ${1} ] ; then
354        echo "IGCM_sys_Mkdir : erreur."
355        IGCM_debug_Exit "IGCM_sys_Mkdir"
356    fi
357    IGCM_debug_PopStack "IGCM_sys_Mkdir"
358}
359
360#D-#==================================================
361#D-function IGCM_sys_MkdirArchive
362#D-* Purpose: Mkdir on Archive
363#D-* Examples:
364#D-
365function IGCM_sys_MkdirArchive {
366    IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
367    if ( $DEBUG_sys ) ; then
368        echo "IGCM_sys_MkdirArchive :" $@
369    fi
370    #- creation de repertoire sur le serveur fichier
371    if [ ! -d ${1} ]; then 
372        \mkdir -p $1
373        if [ $? -gt 0 ] ; then
374            echo "IGCM_sys_MkdirArchive : erreur."
375            IGCM_debug_Exit "IGCM_sys_MkdirArchive"
376        fi
377    fi
378    IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
379}
380
381#D-#==================================================
382#D-function IGCM_sys_MkdirWork
383#D-* Purpose: Mkdir on Work
384#D-* Examples:
385#D-
386function IGCM_sys_MkdirWork {
387    IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
388    if ( $DEBUG_sys ) ; then
389        echo "IGCM_sys_MkdirWork :" $@
390    fi
391    #- creation de repertoire sur le serveur fichier
392    if [ ! -d ${1} ]; then 
393        \mkdir -p $1
394        if [ $? -gt 0 ] ; then
395            echo "IGCM_sys_MkdirWork : erreur."
396            IGCM_debug_Exit "IGCM_sys_MkdirWork"
397        fi
398    fi
399    IGCM_debug_PopStack "IGCM_sys_MkdirWork"
400}
401
402#D-#==================================================
403#D-function IGCM_sys_Cd
404#D-* Purpose: master cd command
405#D-* Examples:
406#D-
407function IGCM_sys_Cd {
408    IGCM_debug_PushStack "IGCM_sys_Cd" $@
409    if ( $DEBUG_sys ) ; then
410        echo "IGCM_sys_Cd :" $@
411    fi
412    \cd $1
413    if [ $? -gt 0 ] ; then
414        echo "IGCM_sys_Cd : erreur."
415        IGCM_debug_Exit "IGCM_sys_Cd"
416    fi
417    IGCM_debug_PopStack "IGCM_sys_Cd"
418}
419
420#D-#==================================================
421#D-function IGCM_sys_Chmod
422#D-* Purpose: Chmod
423#D-* Examples:
424#D-
425function IGCM_sys_Chmod {
426    IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
427    if ( $DEBUG_sys ) ; then
428        echo "IGCM_sys_Chmod :" $@
429    fi
430    if [ $DRYRUN -le 1 ]; then
431        \chmod $@
432        if [ $? -gt 0 ] ; then
433            echo "IGCM_sys_Chmod : erreur."
434            IGCM_debug_Exit "IGCM_sys_Chmod"
435        fi
436    else
437        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
438    fi
439    IGCM_debug_PopStack "IGCM_sys_Chmod"
440}
441
442#D-#==================================================
443#D-function IGCM_sys_FileSize
444#D-* Purpose: Filesize
445#D-* Examples:
446#D-
447function IGCM_sys_FileSize {
448    IGCM_debug_PushStack "IGCM_sys_FileSize" $@
449
450    typeset sizeF
451    set +A sizeF -- $( ls -la ${1} )
452    if [ $? -gt 0 ] ; then
453        IGCM_debug_Exit "IGCM_sys_FileSize"
454    fi
455    eval ${2}=${sizeF[4]}
456
457    IGCM_debug_PopStack "IGCM_sys_FileSize"
458}
459
460#D-#==================================================
461#D-function IGCM_sys_TestDir
462#D-* Purpose: Test Directory that must exists
463#D-* Examples:
464#D-
465function IGCM_sys_TestDir {
466    IGCM_debug_PushStack "IGCM_sys_TestDir" $@
467    if ( $DEBUG_sys ) ; then
468        echo "IGCM_sys_TestDir :" $@
469    fi
470    typeset ExistFlag
471    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
472    IGCM_debug_PopStack "IGCM_sys_TestDir"
473
474    return ${ExistFlag}
475}
476
477#D-#==================================================
478#D-function IGCM_sys_TestDirArchive
479#D-* Purpose: Test Directory that must exists on Archive
480#D-* Examples:
481#D-
482function IGCM_sys_TestDirArchive {
483    IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
484    if ( $DEBUG_sys ) ; then
485        echo "IGCM_sys_TestDirArchive :" $@
486    fi
487    typeset ExistFlag
488    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
489    IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
490
491    return ${ExistFlag}
492}
493
494#D-#==================================================
495#D-function IGCM_sys_TestFileArchive
496#D-* Purpose: Test file that must NOT EXISTS on Archive
497#D-* Examples:
498#D-
499function IGCM_sys_TestFileArchive {
500    IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
501    typeset ExistFlag
502    ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
503    IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
504
505    return ${ExistFlag}
506}
507
508#D-#==================================================
509#D-function IGCM_sys_CountFileArchive
510#D-* Purpose: Count files on Archive filesystem
511#D-* Examples:
512#D-
513function IGCM_sys_CountFileArchive {
514    IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
515    ls ${@} 2>/dev/null | wc -l
516    if [ $? -gt 0 ] ; then
517        echo "IGCM_sys_CountFileArchive : erreur."
518    fi
519    IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
520}
521
522#D-#==================================================
523#D-function IGCM_sys_Tree
524#D-* Purpose: Tree directories with files on ${ARCHIVE}
525#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
526#D-
527function IGCM_sys_Tree {
528    IGCM_debug_PushStack "IGCM_sys_Tree" $@
529    if ( $DEBUG_sys ) ; then
530        echo "IGCM_sys_Tree :" $@
531    fi
532
533    \ls -lR ${@}
534
535    IGCM_debug_PopStack "IGCM_sys_Tree"
536}
537
538#D-#==================================================
539#D-function IGCM_sys_Tar
540#D-* Purpose: master un-tar command
541#D-* Examples:
542#D-
543function IGCM_sys_Tar {
544    IGCM_debug_PushStack "IGCM_sys_Tar" $@
545    if ( $DEBUG_sys ) ; then
546        echo "IGCM_sys_Tar :" $@
547    fi
548    \tar xvf $1
549    if [ $? -gt 0 ] ; then
550        echo "IGCM_sys_Tar : erreur."
551        IGCM_debug_Exit "IGCM_sys_Tar"
552    fi
553    IGCM_debug_PopStack "IGCM_sys_Tar"
554}
555
556#D-#==================================================
557#D-function IGCM_sys_UnTar
558#D-* Purpose: master un-tar command
559#D-* Examples:
560#D-
561function IGCM_sys_UnTar {
562    IGCM_debug_PushStack "IGCM_sys_UnTar" $@
563    if ( $DEBUG_sys ) ; then
564        echo "IGCM_sys_UnTar :" $@
565    fi
566    \tar xvf $1
567    if [ $? -gt 0 ] ; then
568        echo "IGCM_sys_UnTar : erreur."
569        IGCM_debug_Exit "IGCM_sys_UnTar"
570    fi
571    IGCM_debug_PopStack "IGCM_sys_UnTar"
572}
573
574#D-#==================================================
575#D-function IGCM_sys_Qsub
576#D-* Purpose: Qsub new job
577#D-* Examples:
578#D-
579function IGCM_sys_Qsub {
580    IGCM_debug_PushStack "IGCM_sys_Qsub" $@
581    if ( $DEBUG_sys ) ; then
582        echo "IGCM_sys_Qsub :" $@
583    fi
584
585    if [ ${config_UserChoices_JobName}.${CumulPeriod} = "." ] ; then
586        /usr/local/bin/ccc_msub -o ${Script_Output} -e ${Script_Output} < $1
587    else
588        /usr/local/bin/ccc_msub -o ${Script_Output} -e ${Script_Output} -r ${config_UserChoices_JobName}.${CumulPeriod} < $1
589    fi
590
591    if [ $? -gt 0 ] ; then
592        echo "IGCM_sys_Qsub : erreur " $@
593        IGCM_debug_Exit "IGCM_sys_Qsub"
594    fi
595    IGCM_debug_PopStack "IGCM_sys_Qsub"
596}
597
598#D-#==================================================
599#D-function IGCM_sys_QsubPost
600#D-* Purpose: Qsub new job on scalaire
601#D-* Examples:
602#D-
603function IGCM_sys_QsubPost {
604    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
605    if ( $DEBUG_sys ) ; then
606        echo "IGCM_sys_QsubPost :" $@
607    fi
608    /usr/local/bin/ccc_msub -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.e.out -E "-v ${listVarEnv}" ${libIGCM_POST}/$1.job
609    if [ $? -gt 0 ] ; then
610        echo "IGCM_sys_QsubPost : erreur " $@
611        IGCM_debug_Exit "IGCM_sys_QsubPost"
612    fi
613    IGCM_debug_PopStack "IGCM_sys_QsubPost"
614}
615
616#D-*************************
617#D- File transfer functions
618#D-*************************
619#D-
620
621#D-#==================================================
622#D-function IGCM_sys_Rsync_out
623#D-* Purpose: treat return val of rsync
624#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
625#D-  Error values and explanations can depend on your system version.
626function IGCM_sys_Rsync_out {
627    RET=$1
628    if [ ! $RET ] ; then
629        echo "rsync error !"
630    fi
631
632    if [ $MYLANG = "fr" ]; then
633        case $RET in
634            0)  return ;;
635            1)  echo "Erreur de rsync ; RERR_SYNTAX : "
636                echo "Erreur de syntaxe ou d'utilisation."
637                return;;
638            2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
639                echo "Incompatibilité de protocole."
640                return;;
641            3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
642                echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
643                echo "répertoires"
644                return;;
645            4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
646                echo "Action demandée non supportée : une tentative de manipulation de"
647                echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
648                echo "été faite ; ou une option qui est supportée par le  client  mais"
649                echo "pas par le serveur a été spécifiée."
650                return;;
651            10) echo "Erreur de rsync ; RERR_SOCKETIO"
652                echo "Erreur dans le socket d'entrée sortie"
653                return;;
654            11) echo "Erreur de rsync ; RERR_FILEIO"
655                echo "Erreur d'entrée sortie fichier"
656                return;;
657            12) echo "Erreur de rsync ; RERR_STREAMIO"
658                echo "Erreur dans flux de donnée du protocole rsync"
659                return;;
660            13) echo "Erreur de rsync ; RERR_MESSAGEIO"
661                echo "Erreur avec les diagnostics du programme"
662                return;;
663            14) echo "Erreur de rsync ; RERR_IPC"
664                echo "Erreur dans le code IPC"
665                return;;
666            20) echo "Erreur de rsync ; RERR_SIGNAL"
667                echo "SIGUSR1 ou SIGINT reçu"
668                return;;
669            21) echo "Erreur de rsync ; RERR_WAITCHILD"
670                echo "Une erreur retournée par waitpid()"
671                return;;
672            22) echo "Erreur de rsync ; RERR_MALLOC"
673                echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
674                return;;
675            23) echo ""
676                echo "Erreur fichier inexistant"
677                return;;
678            30) echo "Erreur de rsync ; RERR_TIMEOUT"
679                echo "Temps d'attente écoulé dans l'envoi/réception de données"
680                return;;
681            *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
682                return;;
683        esac
684    elif [ $MYLANG = "en" ] ; then
685        case $RET in
686            0)  return;;               
687            1)  echo "rsync error : Syntax or usage error "
688                return;;
689            2)  echo "rsync error : Protocol incompatibility "
690                return;;
691            3)  echo "rsync error : Errors selecting input/output files, dirs"
692                return;;
693            4)  echo "rsync error : Requested action not supported: an attempt"
694                echo "was made to manipulate 64-bit files on a platform that cannot support"
695                echo "them; or an option was specified that is supported by the client and"
696                echo "not by the server."
697                return;;
698            5)  echo "rsync error : Error starting client-server protocol"
699                return;;
700            10) echo "rsync error : Error in socket I/O "
701                return;;
702            11) echo "rsync error : Error in file I/O "
703                return;;
704            12) echo "rsync error : Error in rsync protocol data stream "
705                return;;
706            13) echo "rsync error : Errors with program diagnostics "
707                return;;
708            14) echo "rsync error : Error in IPC code "
709                return;;
710            20) echo "rsync error : Received SIGUSR1 or SIGINT "
711                return;;
712            21) echo "rsync error : Some error returned by waitpid() "
713                return;;
714            22) echo "rsync error : Error allocating core memory buffers "
715                return;;
716            23) echo "rsync error : Partial transfer due to error"
717                return;;
718            24) echo "rsync error : Partial transfer due to vanished source files"
719                return;;
720            30) echo "rsync error : Timeout in data send/receive "
721                return;;
722            *)  echo "rsync error : return code of rsync unknown :" $RET
723                return;;
724        esac
725    else
726        echo "unknown language $MYLANG."
727        return
728    fi
729}
730   
731
732#D-#==================================================
733#D-function IGCM_sys_Miror_libIGCM
734#D-* Purpose: Mirror libIGCM PATH and lib to cesium
735#D-* Examples:
736#D-
737function IGCM_sys_Mirror_libIGCM {
738    IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
739    if ( $DEBUG_sys ) ; then
740        echo "IGCM_sys_Mirror_libIGCM"
741    fi
742
743    typeset RET DEST
744
745    mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
746
747    echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
748    ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
749    RET=$?
750
751    if [ ${RET} -gt 0 ] ; then
752        echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on cesium."
753        cat out_rsync
754    fi
755    IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
756}
757
758#====================================================
759#- Call IGCM_sys_Mirror_libIGCM now !
760if ( $MirrorlibIGCM ) ; then
761    IGCM_sys_Mirror_libIGCM
762fi
763
764#D-#==================================================
765#D-function IGCM_sys_Cp
766#D-* Purpose: generic cp
767#D-* Examples:
768#D-
769function IGCM_sys_Cp {
770    IGCM_debug_PushStack "IGCM_sys_Cp" $@
771    if ( $DEBUG_sys ) ; then
772        echo "IGCM_sys_Cp :" $@
773    fi
774
775    typeset RET
776
777    echo cp $@ > out_rsync 2>&1
778    \cp $@ >> out_rsync 2>&1
779    RET=$?
780
781    if [ ${RET} -gt 0 ] ; then
782        echo "IGCM_sys_Cp : error."
783        cat out_rsync
784        IGCM_debug_Exit "IGCM_sys_Cp"
785     else
786         \rm out_rsync
787    fi
788    IGCM_debug_PopStack "IGCM_sys_Cp"
789}
790
791#D-#==================================================
792#D-function IGCM_sys_Rm
793#D-* Purpose: generic rm
794#D-* Examples:
795#D-
796function IGCM_sys_Rm {
797    IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
798    if ( $DEBUG_sys ) ; then
799        echo "IGCM_sys_Rm :" $@
800    fi
801
802    typeset RET
803
804    echo rm $@ > out_rsync 2>&1
805    \rm $@ >> out_rsync 2>&1
806    RET=$?
807
808    if [ ${RET} -gt 0 ] ; then
809        echo "IGCM_sys_Rm : error."
810        cat out_rsync
811        IGCM_debug_Exit "IGCM_sys_Rm"
812    else
813        \rm out_rsync
814    fi
815    IGCM_debug_PopStack "IGCM_sys_Rm"
816}
817
818#D-#==================================================
819#D-function IGCM_sys_RmRunDir
820#D-* Purpose: rm tmpdir (dummy function most of the time batch
821#D-                      scheduler will do the job)
822#D-* Examples:
823#D-
824function IGCM_sys_RmRunDir {
825    IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
826    if ( $DEBUG_sys ) ; then
827        echo "IGCM_sys_RmRunDir :" $@
828    fi
829
830    typeset RET
831
832    echo rm $@ > out_rsync 2>&1
833    \rm $@ >> out_rsync 2>&1
834    RET=$?
835
836    if [ ${RET} -gt 0 ] ; then
837        echo "IGCM_sys_RmRunDir : error."
838        cat out_rsync
839        IGCM_debug_Exit "IGCM_sys_RmRunDir"
840    else
841        \rm out_rsync
842    fi
843
844    IGCM_debug_PopStack "IGCM_sys_RmRunDir"
845}
846
847#D-#==================================================
848#D-function IGCM_sys_Mv
849#D-* Purpose: generic move
850#D-* Examples:
851#D-
852function IGCM_sys_Mv {
853    IGCM_debug_PushStack "IGCM_sys_Mv" $@
854    if ( $DEBUG_sys ) ; then
855        echo "IGCM_sys_Mv :" $@
856    fi
857
858    if [ $DRYRUN = 0 ]; then
859
860        typeset RET
861           
862        echo mv $@ > out_rsync 2>&1
863        \mv $@ >> out_rsync 2>&1
864        RET=$?
865   
866        if [ ${RET} -gt 0 ] ; then
867            echo "IGCM_sys_Mv : error in mv."
868            cat out_rsync
869            IGCM_debug_Exit "IGCM_sys_Mv"
870        else
871            \rm out_rsync
872        fi
873    else
874        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
875    fi
876
877    IGCM_debug_PopStack "IGCM_sys_Mv"
878}
879
880#D-#==================================================
881#D-function IGCM_sys_Put_Dir
882#D-* Purpose: Copy a complete directory on $(ARCHIVE)
883#D-* Examples:
884#D-
885function IGCM_sys_Put_Dir {
886    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
887    if ( $DEBUG_sys ) ; then
888        echo "IGCM_sys_Put_Dir :" $@
889    fi
890    if [ $DRYRUN = 0 ]; then
891        if [ ! -d ${1} ] ; then
892            echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
893            IGCM_debug_PopStack "IGCM_sys_Put_Dir"
894            return
895        fi
896
897        typeset RET
898
899        # Only if we use rsync
900        #IGCM_sys_TestDirArchive $( dirname $2 )
901        #
902        #USUAL WAY
903        \cp -r $1 $2 > out_rsync 2>&1
904        RET=$?
905
906        if [ ${RET} -gt 0 ] ; then
907            echo "IGCM_sys_Put_Dir : error."
908            cat out_rsync
909            IGCM_debug_Exit "IGCM_sys_Put_Dir"
910        else
911            \rm out_rsync
912        fi
913    else
914        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
915    fi
916    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
917}
918
919#D-#==================================================
920#D-function IGCM_sys_Get_Dir
921#D-* Purpose: Copy a complete directory from $(ARCHIVE)
922#D-* Examples:
923#D-
924function IGCM_sys_Get_Dir {
925    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
926    if ( $DEBUG_sys ) ; then
927        echo "IGCM_sys_Get_Dir :" $@
928    fi
929    if [ $DRYRUN = 0 ]; then
930        if [ ! -d ${1} ] ; then
931            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
932            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
933            return
934        fi
935
936        typeset RET
937
938        # Only if we use rsync
939        #IGCM_sys_TestDirArchive $( dirname $2 )
940        #
941        #USUAL WAY
942        \cp -r $1 $2 > out_rsync 2>&1
943        RET=$?
944
945        if [ ${RET} -gt 0 ] ; then
946            echo "IGCM_sys_Get_Dir : error."
947            cat out_rsync
948            IGCM_debug_Exit "IGCM_sys_Get_Dir"
949        else
950            \rm out_rsync
951        fi
952    else
953        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
954    fi
955    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
956}
957
958#D-#==================================================
959#D-function IGCM_sys_Get_Master
960#D-* Purpose: Copy a complete directory from MASTER filesystem
961#D-* Examples:
962#D-
963function IGCM_sys_Get_Master {
964    IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
965    if ( $DEBUG_sys ) ; then
966        echo "IGCM_sys_Get_Master :" $@
967    fi
968    if [ $DRYRUN = 0 ]; then
969        if [ ! -d ${1} ] ; then
970            echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
971            IGCM_debug_PopStack "IGCM_sys_Get_Master"
972            return
973        fi
974
975        typeset RET
976
977        #USUAL WAY
978        \cp -r $1 $2 > out_rsync 2>&1
979        RET=$?
980
981        if [ ${RET} -gt 0 ] ; then
982            echo "IGCM_sys_Get_Master : error."
983            cat out_rsync
984            IGCM_debug_Exit "IGCM_sys_Get_Master"
985        fi
986    else
987        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
988    fi
989    IGCM_debug_PopStack "IGCM_sys_Get_Master"
990}
991
992#D-#==================================================
993#D-function IGCM_sys_Put_Rest
994#D-* Purpose: Put computied restarts on $(ARCHIVE).
995#D-           File and target directory must exist.
996#D-* Examples:
997#D-
998function IGCM_sys_Put_Rest {
999    IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1000    if ( $DEBUG_sys ) ; then
1001        echo "IGCM_sys_Put_Rest :" $@
1002    fi
1003    if [ $DRYRUN = 0 ]; then
1004        if [ ! -f ${1} ] ; then
1005            echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1006            IGCM_debug_Exit "IGCM_sys_Put_Rest"
1007        fi
1008
1009        typeset RET
1010        #
1011        if [ X${JobType} = XRUN ] ; then
1012            IGCM_sys_Chmod 444 ${1}
1013        fi
1014        #
1015        IGCM_sys_TestDirArchive $( dirname $2 )
1016        #
1017        # USUAL WAY
1018        \cp $1 $2 > out_rsync 2>&1
1019        RET=$?
1020
1021#       #RSYNC WITH NETWORK SSH CALL
1022#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
1023#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
1024
1025#       #RSYNC WITH NFS USE
1026#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1027#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> 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_Put_Rest : error."
1037            cat out_rsync
1038            IGCM_debug_Exit "IGCM_sys_Put_Rest"
1039        else
1040            \rm out_rsync
1041        fi
1042    else
1043        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1044    fi
1045    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1046}
1047
1048#D-#==================================================
1049#D-function IGCM_sys_Put_Out
1050#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
1051#D-* Examples:
1052#D-
1053function IGCM_sys_Put_Out {
1054    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1055    if ( $DEBUG_sys ) ; then
1056        echo "IGCM_sys_Put_Out :" $@
1057    fi
1058    if [ $DRYRUN = 0 ]; then
1059        if [ ! -f ${1} ] ; then
1060            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1061            IGCM_debug_PopStack "IGCM_sys_Put_Out"
1062            return 1
1063        fi
1064        #
1065        IGCM_sys_MkdirArchive $( dirname $2 )
1066        #
1067        typeset RET
1068
1069        #=====================================================
1070        #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1071        #=====================================================
1072
1073        #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1074        #if [ $? -eq 0 ] ; then
1075        #    typeset WORKPATH FILEPATH
1076        #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_OUT_SCR}|" )
1077        #    IGCM_sys_MkdirWork ${WORKPATH}
1078        #    FILEPATH=${WORKPATH}/$( basename $2 )
1079        #    #
1080        #    IGCM_sys_Cp ${1} ${FILEPATH}
1081        #fi
1082
1083        if [ X${JobType} = XRUN ] ; then
1084            if [ X${3} = X ] ; then
1085                IGCM_sys_Chmod 444 ${1}
1086            fi
1087        fi
1088        #
1089        # USUAL WAY
1090        \cp $1 $2 > out_rsync 2>&1
1091        RET=$?
1092
1093#       #RSYNC WITH NETWORK SSH CALL
1094#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
1095#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
1096
1097#       #RSYNC WITH NFS USE
1098#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1099#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1100
1101#       RET=$?
1102#       IGCM_sys_Rsync_out $RET
1103
1104#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1105#       (( RET=RET+$? ))
1106
1107        if [ ${RET} -gt 0 ] ; then
1108            echo "IGCM_sys_Put_Out : error."
1109            cat out_rsync
1110            IGCM_debug_Exit "IGCM_sys_Put_Out"
1111        else
1112            \rm out_rsync
1113        fi
1114    else
1115        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1116    fi
1117    IGCM_debug_PopStack "IGCM_sys_Put_Out"
1118    return 0
1119}
1120
1121#D-#==================================================
1122#D-function IGCM_sys_Get
1123#D-* Purpose: Get a file from ${ARCHIVE}
1124#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1125#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1126function IGCM_sys_Get {
1127    IGCM_debug_PushStack "IGCM_sys_Get" $@
1128
1129    typeset DEST RET dm_liste ifile target file_work
1130
1131    if ( $DEBUG_sys ) ; then
1132        echo "IGCM_sys_Get :" $@
1133    fi
1134    if [ $DRYRUN -le 2 ]; then
1135        if [ X${1} = X'/l' ] ; then
1136            # test if the first file is present in the old computation :
1137            eval set +A dm_liste \${${2}}
1138        else
1139            eval set +A dm_liste ${1}
1140        fi
1141        eval DEST=\${${#}}
1142
1143        #=====================================================
1144        #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1145        #=====================================================
1146
1147        # Is it an R_OUT file (not R_IN) ?
1148        #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1149        #if [ $? -eq 0 ] ; then
1150        #    # Yes  ? then we try to get it in SCRATCHDIR
1151        #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_OUT_SCR}|g" )
1152        #    if [ -f ${file_work[0]} ] ; then
1153        #       IGCM_sys_Cp ${file_work[*]} ${DEST}
1154        #       IGCM_debug_PopStack "IGCM_sys_Get"
1155        #       return
1156        #    fi
1157        #fi
1158
1159        # test if the (first) file is present in the old computation :
1160        IGCM_sys_TestFileArchive ${dm_liste[0]}
1161        RET=$?
1162        if [ ${RET} -gt 0 ] ; then
1163            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1164            IGCM_debug_Exit "IGCM_sys_Get"
1165            IGCM_debug_PopStack "IGCM_sys_Get"
1166            return
1167        fi
1168
1169#       dmget ${dm_liste[*]} > out_rsync 2>&1
1170#       RET=$?
1171#       if [ ${RET} -gt 0 ] ; then
1172#           echo "IGCM_sys_Get : demigration error."
1173#           cat out_rsync
1174#           IGCM_debug_Exit "IGCM_sys_Get"
1175#       fi
1176
1177        #USUAL WAY
1178        if [ X${1} = X'/l' ] ; then
1179            (( RET=0 ))
1180            for target in ${dm_liste[*]} ; do
1181                local_file=$( basename ${target} )
1182                \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1183                (( RET = RET + $? ))
1184            done
1185        else
1186            \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1187            RET=$?
1188        fi
1189
1190#       #RSYNC WITH NETWORK SSH CALL
1191#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1192#       ${RSYNC} ${RSYNC_opt} -e ssh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1193
1194#       #RSYNC WITH NFS USE
1195#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1196#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1197
1198#       RET=$?
1199#       IGCM_sys_Rsync_out $RET
1200
1201#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1202#       (( RET=RET+$? ))
1203
1204        if [ ${RET} -gt 0 ] ; then
1205            echo "IGCM_sys_Get : copy error."
1206            cat out_rsync
1207            IGCM_debug_Exit "IGCM_sys_Get"
1208        else
1209            \rm out_rsync
1210        fi
1211    else
1212        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1213    fi
1214    IGCM_debug_PopStack "IGCM_sys_Get"
1215}
1216
1217############################################################## A FINIR !!
1218
1219#D-#==================================================
1220#D-function IGCM_sys_GetDate_FichWork
1221#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1222#D-* Examples:
1223#D-
1224function IGCM_sys_GetDate_FichWork {
1225    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1226    if ( $DEBUG_sys ) ; then
1227        echo "IGCM_sys_GetDate_FichWork :" $@
1228    fi
1229    # donne la date filesys d'un fichier sur la machine work
1230    IGCM_debug_PopStack "IGCM_sys_FichWork"
1231}
1232
1233#D-#==================================================
1234#D-function IGCM_sys_GetDate_FichArchive
1235#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1236#D-* Examples:
1237#D-
1238function IGCM_sys_GetDate_FichArchive {
1239    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1240    if ( $DEBUG_sys ) ; then
1241        echo "IGCM_sys_GetDate_FichArchive :" $@
1242    fi
1243    IGCM_debug_PopStack "IGCM_sys_FichArchive"
1244}
1245
1246##############################################################
1247# REBUILD OPERATOR
1248
1249function IGCM_sys_rebuild {
1250    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1251    if ( $DEBUG_sys ) ; then
1252        echo "IGCM_sys_rebuild :" $@
1253    fi
1254    /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@
1255    if [ $? -gt 0 ] ; then
1256       echo "IGCM_sys_rebuild : erreur ${@}."
1257       IGCM_debug_Exit "rebuild"
1258    fi
1259
1260    IGCM_debug_PopStack "IGCM_sys_rebuild"
1261}
1262
1263############################################################
1264# Activate Running Environnment Variables
1265
1266function IGCM_sys_activ_variables {
1267    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1268    if ( $DEBUG_sys ) ; then
1269        echo "IGCM_sys_activ_variables"
1270    fi
1271#    ulimit -s 2097152
1272
1273    typeset max_omp
1274
1275    ulimit -s unlimited
1276
1277    (( max_omp = 0 ))
1278    for comp in ${config_ListOfComponents[*]} ; do
1279       
1280        eval ExeNameIn=\${config_Executable_${comp}[0]}
1281        eval ExeNameOut=\${config_Executable_${comp}[1]}
1282       
1283   
1284        # Only if we really have an executable for the component :
1285        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1286            eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1287
1288            if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
1289
1290                (( max_omp = comp_proc_omp_loc ))
1291            fi
1292        fi
1293    done
1294    if [ ${max_omp} -gt 1 ] ; then
1295        module load openmp/${max_omp}thds
1296    fi
1297
1298    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1299}
1300
1301############################################################
1302# Desactivate Running Environnment Variables
1303
1304function IGCM_sys_desactiv_variables {
1305    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1306    if ( $DEBUG_sys ) ; then
1307        echo "IGCM_sys_desactiv_variables"
1308    fi
1309    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1310}
1311
1312
1313# function IGCM_sys_build_run_file {
1314############################################################
1315# Build run file
1316
1317#     IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1318#     if ( $DEBUG_sys ) ; then
1319#       echo "IGCM_sys_build_run_file " $@
1320#     fi
1321
1322#     # set Number of processors for OCE here
1323#     NUM_PROC_OCE=5
1324
1325#     (( NUM_PROC_ATM = $BATCH_NUM_PROC_TOT - NUM_PROC_OCE - 1))
1326#     (( nb_tot_m1    = $BATCH_NUM_PROC_TOT - NUM_PROC_OCE ))
1327#     if [ $1 = MPI1 ]; then
1328#       cat <<EOF > run_file
1329# -np 1 ./oasis
1330# -np ${NUM_PROC_ATM} ./lmdz.x
1331# -np ${NUM_PROC_OCE} ./opa.xx
1332# EOF
1333#       config_UserChoices_JobRunOptions='"--app"'
1334#       IGCM_sys_Chmod u+x run_file
1335#     fi
1336#     IGCM_debug_PopStack "IGCM_sys_build_run_file"
1337 
1338# }
1339
1340############################################################
1341# Build MPI/OMP scripts
1342function IGCM_sys_build_execution_scripts
1343{
1344    IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1345    if ( $DEBUG_sys ) ; then
1346        echo "IGCM_sys_build_execution_scripts " $@
1347    fi
1348
1349    typeset nodes listnodes init_node node_num_current start_num init_exec comp ExeNameIn ExeNameOut
1350    typeset nombre_restant_node node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1351    typeset num_corempi nombre_restant_node nombre_restant_comp
1352
1353    # Verification with PBS parameter
1354    if [ X${BATCH_NUM_PROC_TOT} != X ] ; then
1355
1356        if ( ${OK_PARA_MPI} ) ; then
1357            EXECUTION=${HOST_MPIRUN_COMMAND}
1358        else
1359            if [ ${BATCH_NUM_PROC_TOT} -eq 1 ] ; then
1360                EXECUTION=${MPIRUN_COMMAND:="time "}
1361            fi
1362        fi
1363    else
1364        if ( ! ${OK_PARA_MPI} ) ; then
1365            EXECUTION=${MPIRUN_COMMAND:="time "}
1366        fi
1367    fi
1368
1369    if [ ${PROCESSUS_NUMBER} -gt 1 ] ; then
1370
1371    #  Hosts treatment
1372
1373        ${EXECUTION} hostname | sort | uniq > hosts.tmp
1374       
1375        i=0
1376        rm -f hosts
1377        IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
1378        for nodes in `cat hosts.tmp`
1379        do
1380            host[$i]=$nodes
1381            echo "${host[$i]} slots=8 max_slots=8" >> hosts
1382            IGCM_debug_Print 1 ${host[$i]}
1383            i=$((i+1))
1384        done
1385        rm -f hosts.tmp
1386
1387        listnodes=${host[*]}
1388   
1389        EXECUTION="${EXECUTION} -hostfile hosts" 
1390    fi
1391
1392# Initialisation
1393
1394    init_node=y
1395    node_num_current=0
1396    start_num=0
1397    init_exec=n
1398
1399
1400# Test : if oasis is there, we put it at the first position
1401               
1402    for comp in ${config_ListOfComponents[*]} ; do
1403       
1404        if [ "X${comp}" = "XCPL" ]  ; then
1405           
1406            eval ExeNameIn=\${config_Executable_${comp}[0]}
1407            eval ExeNameOut=\${config_Executable_${comp}[1]}
1408           
1409            echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1410            echo ""  >> script_${ExeNameOut}.ksh
1411            echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1412            echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1413            echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1414            echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1415            IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1416           
1417            init_node=n
1418           
1419            (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1420            node_num_current=0
1421            node_current=${host[${node_num_current}]}
1422           
1423            EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh" 
1424           
1425            init_exec=y
1426            start_num=1
1427           
1428        fi
1429       
1430    done
1431   
1432# Then loop on the components (except for oasis)
1433
1434    for comp in ${config_ListOfComponents[*]} ; do
1435       
1436        eval ExeNameIn=\${config_Executable_${comp}[0]}
1437        eval ExeNameOut=\${config_Executable_${comp}[1]}
1438       
1439   
1440        # Only if we really have an executable for the component :
1441        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1442
1443            eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1444            eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1445           
1446            if ( ${OK_PARA_MPI} ) ; then
1447               
1448                echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1449#               echo "set -vx" >> script_${ExeNameOut}.ksh
1450                echo ""  >> script_${ExeNameOut}.ksh
1451                echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1452                echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1453                echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1454                echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1455                echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1456                echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1457                IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1458               
1459                node_num=0
1460               
1461# We define the number of MPI process to be assigned for the component
1462
1463                nombre_restant_comp=${comp_proc_mpi_loc}
1464               
1465# Loop on the allocated nodes
1466
1467                for node in ${listnodes} ; do
1468
1469# We go to the current node
1470
1471                    if [ ${node_num} = ${node_num_current} ] ; then
1472
1473                        node_current=${host[${node_num_current}]}
1474
1475# If first time on the node : initialisation
1476
1477                        if [ ${init_node} = y ] ; then
1478                            nombre_restant_node=${NUM_COREPERNODE}
1479                        fi
1480       
1481# Test on the number of OMP threads
1482
1483                        if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1484                            (( node_num = node_num + 1 ))
1485                            node_num_current=${node_num}
1486                            init_node=y
1487                            continue
1488                        fi
1489
1490# Number of MPI process to assign
1491
1492                        (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1493 
1494                        if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1495                            num_corempi=${nombre_restant_comp}
1496                        fi
1497
1498                        (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1499                        (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1500                   
1501                        if [ ${init_exec} = y ] ; then
1502                            EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1503                        else   
1504                            EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1505                            init_exec=y
1506                        fi
1507
1508                        ((  start_num = num_corempi + start_num ))
1509       
1510                    else
1511                       
1512                        (( node_num = node_num + 1 )) 
1513                        continue
1514                    fi
1515               
1516# Test on the number of core/process remaining on the node/component
1517               
1518                    if [ ${nombre_restant_node} = 0 ] ; then
1519                        (( node_num = node_num + 1 ))
1520                        node_num_current=${node_num}
1521                        init_node=y
1522
1523                        if [ ${nombre_restant_comp} = 0 ] ; then
1524                            break 1
1525                        fi
1526                    else
1527
1528                        node_num_current=${node_num}
1529                        init_node=n
1530                       
1531                        if [ ${nombre_restant_comp} = 0 ] ; then
1532                            break 1
1533                        fi
1534                    fi
1535                done
1536            else
1537                EXECUTION="${EXECUTION} ./${ExeNameOut}"
1538            fi
1539        fi
1540    done
1541
1542    IGCM_debug_Print 1 "sys Titane : La commande d execution est "
1543    IGCM_debug_Print 1 $EXECUTION
1544
1545    IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1546}
1547
1548
1549
1550##############################################################
1551# NCO OPERATOR
1552
1553function IGCM_sys_ncatted {
1554    IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1555    if ( $DEBUG_sys ) ; then
1556        echo "IGCM_sys_ncatted :" $@
1557    fi
1558    ncatted "$@"
1559    if [ $? -gt 0 ] ; then
1560       echo "IGCM_sys_ncatted : erreur ${@}."
1561       IGCM_debug_Exit "ncatted"
1562    fi
1563
1564    IGCM_debug_PopStack "IGCM_sys_ncatted"
1565}
1566
1567function IGCM_sys_ncbo {
1568    IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1569    if ( $DEBUG_sys ) ; then
1570        echo "IGCM_sys_ncbo :" $@
1571    fi
1572    ncbo $@
1573    if [ $? -gt 0 ] ; then
1574       echo "IGCM_sys_ncbo : erreur ${@}."
1575       IGCM_debug_Exit "ncbo"
1576    fi
1577
1578    IGCM_debug_PopStack "IGCM_sys_ncbo"
1579}
1580
1581function IGCM_sys_ncdiff {
1582    IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1583    if ( $DEBUG_sys ) ; then
1584        echo "IGCM_sys_ncdiff :" $@
1585    fi
1586    ncdiff $@
1587    if [ $? -gt 0 ] ; then
1588       echo "IGCM_sys_ncdiff : erreur ${@}."
1589       IGCM_debug_Exit "ncdiff"
1590    fi
1591
1592    IGCM_debug_PopStack "IGCM_sys_ncdiff"
1593}
1594
1595function IGCM_sys_ncea {
1596    IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1597    if ( $DEBUG_sys ) ; then
1598        echo "IGCM_sys_ncea :" $@
1599    fi
1600    ncea $@
1601    if [ $? -gt 0 ] ; then
1602       echo "IGCM_sys_ncea : erreur ${@}."
1603       IGCM_debug_Exit "ncea"
1604    fi
1605
1606    IGCM_debug_PopStack "IGCM_sys_ncea"
1607}
1608
1609function IGCM_sys_ncecat {
1610    IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1611    if ( $DEBUG_sys ) ; then
1612        echo "IGCM_sys_ncecat :" $@
1613    fi
1614    ncecat $@
1615    if [ $? -gt 0 ] ; then
1616       echo "IGCM_sys_ncecat : erreur ${@}."
1617       IGCM_debug_Exit "ncecat"
1618    fi
1619
1620    IGCM_debug_PopStack "IGCM_sys_ncecat"
1621}
1622
1623function IGCM_sys_ncflint {
1624    IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1625    if ( $DEBUG_sys ) ; then
1626        echo "IGCM_sys_ncflint :" $@
1627    fi
1628    ncflint $@
1629    if [ $? -gt 0 ] ; then
1630       echo "IGCM_sys_ncflint : erreur ${@}."
1631       IGCM_debug_Exit "ncflint"
1632    fi
1633
1634    IGCM_debug_PopStack "IGCM_sys_ncflint"
1635}
1636
1637function IGCM_sys_ncks {
1638    IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1639    if ( $DEBUG_sys ) ; then
1640        echo "IGCM_sys_ncks :" $@
1641    fi
1642    ncks $@
1643    if [ $? -gt 0 ] ; then
1644       echo "IGCM_sys_ncks : erreur ${@}."
1645       IGCM_debug_Exit "ncks"
1646    fi
1647
1648    IGCM_debug_PopStack "IGCM_sys_ncks"
1649}
1650
1651function IGCM_sys_ncpdq {
1652    IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1653    if ( $DEBUG_sys ) ; then
1654        echo "IGCM_sys_ncpdq :" $@
1655    fi
1656    ncpdq $@
1657    if [ $? -gt 0 ] ; then
1658       echo "IGCM_sys_ncpdq : erreur ${@}."
1659       IGCM_debug_Exit "ncpdq"
1660    fi
1661
1662    IGCM_debug_PopStack "IGCM_sys_ncpdq"
1663}
1664
1665function IGCM_sys_ncra {
1666    IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1667    if ( $DEBUG_sys ) ; then
1668        echo "IGCM_sys_ncra :" $@
1669    fi
1670    ncra $@
1671    if [ $? -gt 0 ] ; then
1672       echo "IGCM_sys_ncra : erreur ${@}."
1673       IGCM_debug_Exit "ncra"
1674    fi
1675
1676    IGCM_debug_PopStack "IGCM_sys_ncra"
1677}
1678
1679function IGCM_sys_ncrcat {
1680    IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1681    if ( $DEBUG_sys ) ; then
1682        echo "IGCM_sys_ncrcat :" $@
1683    fi
1684    ncrcat $@
1685    if [ $? -gt 0 ] ; then
1686       echo "IGCM_sys_ncrcat : erreur ${@}."
1687#       IGCM_debug_Exit "ncrcat"
1688    fi
1689
1690    IGCM_debug_PopStack "IGCM_sys_ncrcat"
1691}
1692
1693function IGCM_sys_ncrename {
1694    IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1695    if ( $DEBUG_sys ) ; then
1696        echo "IGCM_sys_ncrename :" $@
1697    fi
1698    ncrename $@
1699    if [ $? -gt 0 ] ; then
1700       echo "IGCM_sys_ncrename : erreur ${@}."
1701       IGCM_debug_Exit "ncrename"
1702    fi
1703
1704    IGCM_debug_PopStack "IGCM_sys_ncrename"
1705}
1706
1707function IGCM_sys_ncwa {
1708    IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1709    if ( $DEBUG_sys ) ; then
1710        echo "IGCM_sys_ncwa :" $@
1711    fi
1712    ncwa $@
1713    if [ $? -gt 0 ] ; then
1714       echo "IGCM_sys_ncwa : erreur ${@}."
1715       IGCM_debug_Exit "ncwa"
1716    fi
1717
1718    IGCM_debug_PopStack "IGCM_sys_ncwa"
1719}
Note: See TracBrowser for help on using the repository browser.