source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_ulam.ksh @ 377

Last change on this file since 377 was 377, checked in by brocksce, 13 years ago

IGCM_sys_ncap replaced by IGCM_sys_ncap2 because ncap2 can do more than ncap
Added correction of climatological axis in create_se
Added all different calendars
Added defdim("tbnds",2)
Added test to handle time_counter and time UNLIMITED dimension (for CPL component)

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