source: tags/libIGCM_v1_5/libIGCM_sys/libIGCM_sys_ulam.ksh @ 487

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

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

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