source: tags/libIGCM_v1_9/libIGCM_sys/libIGCM_sys_ulam.ksh @ 1170

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