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

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

MM: import first trunk version of libIGCM.

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