source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_cesium.ksh @ 192

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