source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_calculo.ksh @ 217

Last change on this file since 217 was 217, checked in by sdipsl, 14 years ago

Avoid side effect with user environment. Do not define read-only varible potentially defined by system environment.

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Date Author Revision
File size: 32.4 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Martial.Mancip_ipsl.jussieu.fr
6# $Date$
7# $Author$
8# $Revision$
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11# History:
12# Modification:
13#
14#**************************************************************
15
16#=========================================================
17# The documentation of this file can be automatically generated
18# if you use the prefix #D- for comments to be extracted.
19# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
20#=========================================================
21 
22#D-#==================================================
23#D-LibIGCM_sys for IPSL calculo
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
82#====================================================
83# Source Ferret
84. /usr/local/ferret/ferret_paths_ksh
85. /home/brocksce/.atlas_env_calcul_ksh
86
87export FER_DATA="$FER_DATA /home/mc2ipsl/temp_local/grids"
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#- SCRATCHDIR (=> ${R_DONNEES})
99typeset -r SCRATCHDIR=/home/${LOGIN}/TEMP_LOCAL
100
101#====================================================
102#- SUBMIT_DIR : submission dir
103typeset SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
104
105#====================================================
106#- ARCHIVE
107typeset -r ARCHIVE=/home
108
109#====================================================
110#- IN
111typeset -r R_IN=${R_IN:=${ARCHIVE}/${LOGIN}/TEMP_LOCAL/SCRIPTS}
112
113#====================================================
114#- OUT
115typeset -r R_OUT=${ARCHIVE}/${LOGIN}/TEMP_LOCAL/SCRIPTS/IGCM_OUT
116
117#====================================================
118#- OUT_POST
119typeset -r R_OUT_POST=${SCRATCHDIR}
120
121#====================================================
122#- RUN_DIR_PATH : Temporary working directory (=> TMP)
123typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/tmp$$}
124
125#=========================================================
126#- Add "time" before mpirun command
127MPIRUN_COMMAND="time "${MPIRUN_COMMAND}
128echo ${MPIRUN_COMMAND}
129
130#====================================================
131#- Max number of arguments passed to nco operator or demigration command
132UNIX_MAX_LIMIT=360
133
134#D-#==================================================
135#D-function IGCM_sys_RshMaster
136#D-* Purpose: Master rsh command
137#D-* Examples:
138#D-
139function IGCM_sys_RshMaster {
140    IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
141    ssh ${HOST} /bin/ksh  <<-EOF
142    export libIGCM=${libIGCM}
143    export DEBUG_debug=${DEBUG_debug}
144    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
145    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
146    ${@}
147EOF
148    if [ $? -gt 0 ] ; then
149        echo "IGCM_sys_RshMaster : erreur."
150        IGCM_debug_Exit "IGCM_sys_RshMaster"
151    fi
152    IGCM_debug_PopStack "IGCM_sys_RshMaster"
153}
154
155#D-#==================================================
156#D-function IGCM_sys_RshArchive
157#D-* Purpose: Archive rsh command
158#D-* Examples:
159#D-
160function IGCM_sys_RshArchive {
161    IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
162    /bin/ksh  <<-EOF
163    ${@}
164EOF
165    if [ $? -gt 0 ] ; then
166        echo "IGCM_sys_RshArchive : erreur."
167        IGCM_debug_Exit "IGCM_sys_RshArchive"
168    fi
169    IGCM_debug_PopStack "IGCM_sys_RshArchive"
170}
171
172#D-#==================================================
173#D-function IGCM_sys_RshPost
174#D-* Purpose: Master rsh command
175#D-* Examples:
176#D-
177(( RshPNum = 0 ))
178function IGCM_sys_RshPost {
179    IGCM_debug_PushStack "IGCM_sys_RshPost" $@
180    if ( $DEBUG_sys ) ; then
181        echo "IGCM_sys_RshPost :" $@
182    fi
183    #ssh ${HOST} exec /bin/ksh -vx $@ > out_RshPost.${RshPNum}
184    ssh ${HOST} exec /bin/ksh $@ > out_RshPost.${RshPNum}
185    if [ $? -gt 0 ] ; then
186        echo "IGCM_sys_RshPost : erreur."
187        IGCM_debug_Exit "IGCM_sys_RshPost"
188    fi
189    (( RshPNum = RshPNum + 1 ))
190    IGCM_debug_PopStack "IGCM_sys_RshPost"
191}
192
193#D-#==================================================
194#D-function IGCM_sys_Mkdir
195#D-* Purpose: Master locale mkdir command
196#D-* Examples:
197#D-
198function IGCM_sys_Mkdir {
199    IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
200    if ( $DEBUG_sys ) ; then
201        echo "IGCM_sys_Mkdir :" $@
202    fi
203    if [ ! -d ${1} ]; then
204        \mkdir -p $1
205        if [ $? -gt 0 ] ; then
206            echo "IGCM_sys_Mkdir : erreur."
207            IGCM_debug_Exit "IGCM_sys_Mkdir"
208        fi
209    fi
210    # vérification :
211    if [ ! -d ${1} ] ; then
212        echo "IGCM_sys_Mkdir : erreur."
213        IGCM_debug_Exit "IGCM_sys_Mkdir"
214    fi
215    IGCM_debug_PopStack "IGCM_sys_Mkdir"
216}
217
218#D-#==================================================
219#D-function IGCM_sys_MkdirArchive
220#D-* Purpose: Mkdir on Archive
221#D-* Examples:
222#D-
223function IGCM_sys_MkdirArchive {
224    IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
225    if ( $DEBUG_sys ) ; then
226        echo "IGCM_sys_MkdirArchive :" $@
227    fi
228    #- creation de repertoire sur le serveur fichier
229    if [ ! -d ${1} ]; then 
230        \mkdir -p $1
231        if [ $? -gt 0 ] ; then
232            echo "IGCM_sys_MkdirArchive : erreur."
233            IGCM_debug_Exit "IGCM_sys_MkdirArchive"
234        fi
235    fi
236    IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
237}
238
239#D-#==================================================
240#D-function IGCM_sys_MkdirWork
241#D-* Purpose: Mkdir on Work
242#D-* Examples:
243#D-
244function IGCM_sys_MkdirWork {
245    IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
246    if ( $DEBUG_sys ) ; then
247        echo "IGCM_sys_MkdirWork :" $@
248    fi
249    #- creation de repertoire sur le serveur fichier
250    if [ ! -d ${1} ]; then 
251        \mkdir -p $1
252        if [ $? -gt 0 ] ; then
253            echo "IGCM_sys_MkdirWork : erreur."
254            IGCM_debug_Exit "IGCM_sys_MkdirWork"
255        fi
256    fi
257    IGCM_debug_PopStack "IGCM_sys_MkdirWork"
258}
259
260#D-#==================================================
261#D-function IGCM_sys_Cd
262#D-* Purpose: master cd command
263#D-* Examples:
264#D-
265function IGCM_sys_Cd {
266    IGCM_debug_PushStack "IGCM_sys_Cd" $@
267    if ( $DEBUG_sys ) ; then
268        echo "IGCM_sys_Cd :" $@
269    fi
270    \cd $1
271    if [ $? -gt 0 ] ; then
272        echo "IGCM_sys_Cd : erreur."
273        IGCM_debug_Exit "IGCM_sys_Cd"
274    fi
275    IGCM_debug_PopStack "IGCM_sys_Cd"
276}
277
278#D-#==================================================
279#D-function IGCM_sys_Chmod
280#D-* Purpose: Chmod
281#D-* Examples:
282#D-
283function IGCM_sys_Chmod {
284    IGCM_debug_PushStack "IGCM_sys_Chmod" $@
285    if ( $DEBUG_sys ) ; then
286        echo "IGCM_sys_Chmod :" $@
287    fi
288    if [ $DRYRUN -le 1 ]; then
289        \chmod $@
290        if [ $? -gt 0 ] ; then
291            echo "IGCM_sys_Chmod : erreur."
292            IGCM_debug_Exit "IGCM_sys_Chmod"
293        fi
294    else
295        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
296    fi
297    IGCM_debug_PopStack "IGCM_sys_Chmod"
298}
299
300#D-#==================================================
301#D-function IGCM_sys_FileSize
302#D-* Purpose: Filesize
303#D-* Examples:
304#D-
305function IGCM_sys_FileSize {
306    IGCM_debug_PushStack "IGCM_sys_FileSize" $@
307
308    typeset sizeF
309    set +A sizeF -- $( ls -la ${1} )
310    if [ $? -gt 0 ] ; then
311        IGCM_debug_Exit "IGCM_sys_FileSize"
312    fi
313    eval ${2}=${sizeF[4]}
314
315    IGCM_debug_PopStack "IGCM_sys_FileSize"
316}
317
318#D-#==================================================
319#D-function IGCM_sys_TestDir
320#D-* Purpose: Test Directory that must exists
321#D-* Examples:
322#D-
323function IGCM_sys_TestDir {
324    IGCM_debug_PushStack "IGCM_sys_TestDir" $@
325    if ( $DEBUG_sys ) ; then
326        echo "IGCM_sys_TestDir :" $@
327    fi
328    typeset ExistFlag
329    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
330    IGCM_debug_PopStack "IGCM_sys_TestDir"
331
332    return ${ExistFlag}
333}
334
335#D-#==================================================
336#D-function IGCM_sys_TestDirArchive
337#D-* Purpose: Test Directory that must exists on Archive
338#D-* Examples:
339#D-
340function IGCM_sys_TestDirArchive {
341    IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
342    if ( $DEBUG_sys ) ; then
343        echo "IGCM_sys_TestDirArchive :" $@
344    fi
345    typeset ExistFlag
346    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
347    IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
348
349    return ${ExistFlag}
350}
351
352#D-#==================================================
353#D-function IGCM_sys_TestFileArchive
354#D-* Purpose: Test file that must NOT EXISTS on Archive
355#D-* Examples:
356#D-
357function IGCM_sys_TestFileArchive {
358    IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
359    if ( $DEBUG_sys ) ; then
360        echo "IGCM_sys_TestFileArchive :" $@
361    fi
362    typeset ExistFlag
363    ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
364    IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
365
366    return ${ExistFlag}
367}
368
369#D-#==================================================
370#D-function IGCM_sys_CountFileArchive
371#D-* Purpose: Count files on Archive filesystem
372#D-* Examples:
373#D-
374function IGCM_sys_CountFileArchive {
375    IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
376    ls ${@} 2>/dev/null | wc -l
377    if [ $? -gt 0 ] ; then
378        echo "IGCM_sys_CountFileArchive : erreur."
379    fi
380    IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
381}
382
383#D-#==================================================
384#D-function IGCM_sys_Tree
385#D-* Purpose: Tree directories with files on ${ARCHIVE}
386#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
387#D-
388function IGCM_sys_Tree {
389    IGCM_debug_PushStack "IGCM_sys_Tree" $@
390    if ( $DEBUG_sys ) ; then
391        echo "IGCM_sys_Tree :" $@
392    fi
393
394    /home/mmaipsl/BIN/tree -f $@
395
396    IGCM_debug_PopStack "IGCM_sys_Tree"
397}
398
399#D-#==================================================
400#D-function IGCM_sys_Tar
401#D-* Purpose: master un-tar command
402#D-* Examples:
403#D-
404function IGCM_sys_Tar {
405    IGCM_debug_PushStack "IGCM_sys_Tar" $@
406    if ( $DEBUG_sys ) ; then
407        echo "IGCM_sys_Tar :" $@
408    fi
409    \tar cvf $@
410    if [ $? -gt 0 ] ; then
411        echo "IGCM_sys_Tar : erreur."
412        IGCM_debug_Exit "IGCM_sys_Tar"
413    fi
414    \tar tvf $1
415
416    IGCM_debug_PopStack "IGCM_sys_Tar"
417}
418
419#D-#==================================================
420#D-function IGCM_sys_UnTar
421#D-* Purpose: master un-tar command
422#D-* Examples:
423#D-
424function IGCM_sys_UnTar {
425    IGCM_debug_PushStack "IGCM_sys_UnTar" $@
426    if ( $DEBUG_sys ) ; then
427        echo "IGCM_sys_UnTar :" $@
428    fi
429    \tar xvf $1
430    if [ $? -gt 0 ] ; then
431        echo "IGCM_sys_UnTar : erreur."
432        IGCM_debug_Exit "IGCM_sys_UnTar"
433    fi
434    IGCM_debug_PopStack "IGCM_sys_UnTar"
435}
436
437#D-#==================================================
438#D-function IGCM_sys_Qsub
439#D-* Purpose: Qsub new job
440#D-* Examples:
441#D-
442function IGCM_sys_Qsub {
443    IGCM_debug_PushStack "IGCM_sys_Qsub" $@
444    if ( $DEBUG_sys ) ; then
445        echo "IGCM_sys_Qsub :" $@
446    fi
447    echo "ssh -l ${LOGIN} ${HOST} ""cd ${SUBMIT_DIR} ; ${@}"" > ${Script_Output} 2>&1 &"
448    ssh -l ${LOGIN} ${HOST} "cd ${SUBMIT_DIR} ; ${@}" > ${Script_Output} 2>&1 &
449    if [ $? -gt 0 ] ; then
450        echo "IGCM_sys_Qsub : erreur."
451        IGCM_debug_Exit "IGCM_sys_Qsub"
452    fi
453    IGCM_debug_PopStack "IGCM_sys_Qsub"
454}
455
456#D-#==================================================
457#D-function IGCM_sys_QsubPost
458#D-* Purpose: Qsub new job on scalaire
459#D-* Examples:
460#D-
461function IGCM_sys_QsubPost {
462    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
463    if ( $DEBUG_sys ) ; then
464        echo "IGCM_sys_QsubPost :" $@
465    fi
466    #echo "ssh -x -l ${LOGIN} ${HOST} ${3} > ${2} 2>&1 &"
467    #    ssh -x -l ${LOGIN} ${HOST}
468    echo "${3} > ${2} 2>&1 &"
469    ${3} > ${2} 2>&1 &
470    if [ $? -gt 0 ] ; then
471        echo "IGCM_sys_QsubPost : erreur."
472        IGCM_debug_Exit "IGCM_sys_QsubPost"
473    fi
474    IGCM_debug_PopStack "IGCM_sys_QsubPost"
475}
476
477#D-*************************
478#D- File transfer functions
479#D-*************************
480#D-
481
482#D-#==================================================
483#D-function IGCM_sys_Rsync_out
484#D-* Purpose: treat return val of rsync
485#D-* Examples:  IGCM_sys_Rsync_out out_RET_rsync
486#D-  Error values and explanations can depend on your system version.
487function IGCM_sys_Rsync_out {
488    RET=$1
489    if [ ! $RET ] ; then
490        echo "rsync error !"
491    fi
492
493    if [ $MYLANG = "fr" ]; then
494        case $RET in
495            0)  return ;;
496            1)  echo "Erreur de rsync ; RERR_SYNTAX : "
497                echo "Erreur de syntaxe ou d'utilisation."
498                return;;
499            2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
500                echo "Incompatibilité de protocole."
501                return;;
502            3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
503                echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
504                echo "répertoires"
505                return;;
506            4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
507                echo "Action demandée non supportée : une tentative de manipulation de"
508                echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
509                echo "été faite ; ou une option qui est supportée par le  client  mais"
510                echo "pas par le serveur a été spécifiée."
511                return;;
512            10) echo "Erreur de rsync ; RERR_SOCKETIO"
513                echo "Erreur dans le socket d'entrée sortie"
514                return;;
515            11) echo "Erreur de rsync ; RERR_FILEIO"
516                echo "Erreur d'entrée sortie fichier"
517                return;;
518            12) echo "Erreur de rsync ; RERR_STREAMIO"
519                echo "Erreur dans flux de donnée du protocole rsync"
520                return;;
521            13) echo "Erreur de rsync ; RERR_MESSAGEIO"
522                echo "Erreur avec les diagnostics du programme"
523                return;;
524            14) echo "Erreur de rsync ; RERR_IPC"
525                echo "Erreur dans le code IPC"
526                return;;
527            20) echo "Erreur de rsync ; RERR_SIGNAL"
528                echo "SIGUSR1 ou SIGINT reçu"
529                return;;
530            21) echo "Erreur de rsync ; RERR_WAITCHILD"
531                echo "Une erreur retournée par waitpid()"
532                return;;
533            22) echo "Erreur de rsync ; RERR_MALLOC"
534                echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
535                return;;
536            23) echo ""
537                echo "Erreur fichier inexistant"
538                return;;
539            30) echo "Erreur de rsync ; RERR_TIMEOUT"
540                echo "Temps d'attente écoulé dans l'envoi/réception de données"
541                return;;
542            *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
543                return;;
544        esac
545    elif [ $MYLANG = "en" ] ; then
546        case $RET in
547            0)  return;;               
548            1)  echo "rsync error : Syntax or usage error "
549                return;;
550            2)  echo "rsync error : Protocol incompatibility "
551                return;;
552            3)  echo "rsync error : Errors selecting input/output files, dirs"
553                return;;
554            4)  echo "rsync error : Requested action not supported: an attempt"
555                echo "was made to manipulate 64-bit files on a platform that cannot support"
556                echo "them; or an option was specified that is supported by the client and"
557                echo "not by the server."
558                return;;
559            5)  echo "rsync error : Error starting client-server protocol"
560                return;;
561            10) echo "rsync error : Error in socket I/O "
562                return;;
563            11) echo "rsync error : Error in file I/O "
564                return;;
565            12) echo "rsync error : Error in rsync protocol data stream "
566                return;;
567            13) echo "rsync error : Errors with program diagnostics "
568                return;;
569            14) echo "rsync error : Error in IPC code "
570                return;;
571            20) echo "rsync error : Received SIGUSR1 or SIGINT "
572                return;;
573            21) echo "rsync error : Some error returned by waitpid() "
574                return;;
575            22) echo "rsync error : Error allocating core memory buffers "
576                return;;
577            23) echo "rsync error : Partial transfer due to error"
578                return;;
579            24) echo "rsync error : Partial transfer due to vanished source files"
580                return;;
581            30) echo "rsync error : Timeout in data send/receive "
582                return;;
583            *)  echo "rsync error : return code of rsync unknown :" $RET
584                return;;
585        esac
586    else
587        echo "unknown language $MYLANG."
588        return
589    fi
590}
591   
592#D-#==================================================
593#D-function IGCM_sys_Cp
594#D-* Purpose: generic cp
595#D-* Examples:
596#D-
597function IGCM_sys_Cp {
598    IGCM_debug_PushStack "IGCM_sys_Cp" $@
599    if ( $DEBUG_sys ) ; then
600        echo "IGCM_sys_Cp :" $@
601    fi
602
603    typeset RET
604
605    echo cp --preserve=timestamps $@ > out_rsync 2>&1
606    \cp --preserve=timestamps $@ >> out_rsync 2>&1
607    RET=$?
608   
609    if [ ${RET} -gt 0 ] ; then
610        echo "IGCM_sys_Cp : error."
611        cat out_rsync
612        IGCM_debug_Exit "IGCM_sys_Cp"
613    fi
614    IGCM_debug_PopStack "IGCM_sys_Cp"
615}
616
617#D-#==================================================
618#D-function IGCM_sys_Rm
619#D-* Purpose: generic rm
620#D-* Examples:
621#D-
622function IGCM_sys_Rm {
623    IGCM_debug_PushStack "IGCM_sys_Rm" $@
624    if ( $DEBUG_sys ) ; then
625        echo "IGCM_sys_Rm :" $@
626    fi
627
628    typeset RET
629
630    echo rm $@ > out_rsync 2>&1
631    \rm $@ >> out_rsync 2>&1
632    RET=$?
633   
634    if [ ${RET} -gt 0 ] ; then
635        echo "IGCM_sys_Rm : error."
636        cat out_rsync
637        IGCM_debug_Exit "IGCM_sys_Rm"
638    fi
639    IGCM_debug_PopStack "IGCM_sys_Rm"
640}
641
642#D-#==================================================
643#D-function IGCM_sys_Mv
644#D-* Purpose: generic move
645#D-* Examples:
646#D-
647function IGCM_sys_Mv {
648    IGCM_debug_PushStack "IGCM_sys_Mv" $@
649    if ( $DEBUG_sys ) ; then
650        echo "IGCM_sys_Mv :" $@
651    fi
652
653    if [ $DRYRUN = 0 ]; then
654
655        typeset RET
656           
657        echo mv $@ > out_rsync 2>&1
658        \mv $@ >> out_rsync 2>&1
659        RET=$?
660   
661        if [ ${RET} -gt 0 ] ; then
662            echo "IGCM_sys_Mv : error in mv."
663            cat out_rsync
664            IGCM_debug_Exit "IGCM_sys_Mv"
665        fi
666    else
667        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
668    fi
669
670    IGCM_debug_PopStack "IGCM_sys_Mv"
671}
672
673#D-#==================================================
674#D-function IGCM_sys_Put_Dir
675#D-* Purpose: Copy a complete directory on $(ARCHIVE)
676#D-* Examples:
677#D-
678function IGCM_sys_Put_Dir {
679    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
680    if ( $DEBUG_sys ) ; then
681        echo "IGCM_sys_Put_Dir :" $@
682    fi
683    if [ $DRYRUN = 0 ]; then
684        if [ ! -d ${1} ] ; then
685            echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
686            IGCM_debug_PopStack "IGCM_sys_Put_Dir"
687            return
688        fi
689
690        typeset RET
691
692        #
693        #USUAL WAY
694        \cp -R $1 $2 > out_rsync 2>&1
695        RET=$?
696
697        if [ ${RET} -gt 0 ] ; then
698            echo "IGCM_sys_Put_Dir : error."
699            cat out_rsync
700            IGCM_debug_Exit "IGCM_sys_Put_Dir"
701        fi
702    else
703        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
704    fi
705    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
706}
707
708#D-#==================================================
709#D-function IGCM_sys_Get_Dir
710#D-* Purpose: Copy a complete directory from $(ARCHIVE)
711#D-* Examples:
712#D-
713function IGCM_sys_Get_Dir {
714    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
715    if ( $DEBUG_sys ) ; then
716        echo "IGCM_sys_Get_Dir :" $@
717    fi
718    if [ $DRYRUN = 0 ]; then
719        if [ ! -d ${1} ] ; then
720            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
721            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
722            return
723        fi
724
725        typeset RET
726
727        # Only if we use rsync
728        #IGCM_sys_TestDirArchive $( dirname $2 )
729        #
730        #USUAL WAY
731        \cp -R $1 $2 > out_rsync 2>&1
732        RET=$?
733
734        if [ ${RET} -gt 0 ] ; then
735            echo "IGCM_sys_Get_Dir : error."
736            cat out_rsync
737            IGCM_debug_Exit "IGCM_sys_Get_Dir"
738        fi
739    else
740        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
741    fi
742    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
743}
744
745#D-#==================================================
746#D-function IGCM_sys_Get_Master
747#D-* Purpose: Copy a complete directory from MASTER filesystem
748#D-* Examples:
749#D-
750function IGCM_sys_Get_Master {
751    IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
752    if ( $DEBUG_sys ) ; then
753        echo "IGCM_sys_Get_Master :" $@
754    fi
755    if [ $DRYRUN = 0 ]; then
756        if [ ! -d ${1} ] ; then
757            echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
758            IGCM_debug_PopStack "IGCM_sys_Get_Master"
759            return
760        fi
761
762        typeset RET
763        sleep 60
764
765        #USUAL WAY
766        \cp -R $1 $2 > out_rsync 2>&1
767        RET=$?
768
769        if [ ${RET} -gt 0 ] ; then
770            echo "IGCM_sys_Get_Master : error."
771            cat out_rsync
772            IGCM_debug_Exit "IGCM_sys_Get_Master"
773        fi
774    else
775        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
776    fi
777    IGCM_debug_PopStack "IGCM_sys_Get_Master"
778}
779
780#D-#==================================================
781#D-function IGCM_sys_Put_Rest
782#D-* Purpose: commande de transfert des restarts $(ARCHIVE).
783#D-           Quitte si le fichier ou si le répertoire d'arriver n'existe pas.
784#D-* Examples:
785#D-
786function IGCM_sys_Put_Rest {
787    IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
788    if ( $DEBUG_sys ) ; then
789        echo "IGCM_sys_Put_Rest :" $@
790    fi
791    if [ $DRYRUN = 0 ]; then
792
793        IGCM_sys_TestDirArchive $( dirname $2 )
794
795        if [ ! -f ${1} ] ; then
796            echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
797            IGCM_debug_Exit "IGCM_sys_Put_Rest"
798        fi
799        if [ X${JobType} = XRUN ] ; then
800            IGCM_sys_Chmod 444 ${1}
801        fi
802        typeset RET
803
804        echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
805        ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
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_Rest : error."
814            cat out_rsync
815            IGCM_debug_Exit "IGCM_sys_Put_Rest"
816        fi
817    else
818        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
819    fi
820    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
821}
822
823#D-#==================================================
824#D-function IGCM_sys_Put_Out
825#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
826#D-* Examples:
827#D-
828function IGCM_sys_Put_Out {
829    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
830    if ( $DEBUG_sys ) ; then
831        echo "IGCM_sys_Put_Out :" $@
832    fi
833    if [ $DRYRUN = 0 ]; then
834        if [ -f ${1} ] ; then
835            if [ ! -d $( dirname $2 ) ] ; then
836                IGCM_sys_MkdirArchive $( dirname $2 )
837            fi
838        else
839            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
840            IGCM_debug_PopStack "IGCM_sys_Put_Out"
841            return 1
842        fi
843
844        typeset RET
845        #
846        if [ X${JobType} = XRUN ] ; then
847            IGCM_sys_Chmod 444 ${1}
848        fi
849        #
850
851        echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
852        ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
853        RET=$?
854        IGCM_sys_Rsync_out $RET
855
856        ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
857        (( RET=RET+$? ))
858
859        if [ ${RET} -gt 0 ] ; then
860            echo "IGCM_sys_Put_Out : error."
861            cat out_rsync
862            IGCM_debug_Exit "IGCM_sys_Put_Out"
863        fi
864    else
865        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
866    fi
867    IGCM_debug_PopStack "IGCM_sys_Put_Out"
868    return 0
869}
870
871#D-#==================================================
872#D-function IGCM_sys_Get
873#D-* Purpose: Get a file from ${ARCHIVE}
874#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
875#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
876function IGCM_sys_Get {
877    IGCM_debug_PushStack "IGCM_sys_Get" $@
878
879    typeset DEST RET dm_liste ifile target
880
881    if ( $DEBUG_sys ) ; then
882        echo "IGCM_sys_Get :" $@
883    fi
884    if [ $DRYRUN -le 2 ]; then
885        if [ X${1} = X'/l' ] ; then
886            # test if the first file is present in the old computation :
887            eval set +A dm_liste \${${2}}
888        else
889            dm_liste=${1}
890        fi
891        eval DEST=\${${#}}
892
893        # test if the (first) file is present in the old computation :
894        IGCM_sys_TestFileArchive ${dm_liste[0]}
895        RET=$?
896        if [ ${RET} -gt 0 ] ; then
897            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
898            IGCM_debug_Exit "IGCM_sys_Get"
899            #return
900        fi
901
902        (( RET=0 ))
903        for target in ${dm_liste[*]} ; do
904          ln -s ${target} ${DEST} >> out_rsync 2>&1
905          (( RET=RET+$? ))
906        done
907
908#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
909#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
910#       RET=$?
911#       IGCM_sys_Rsync_out $RET
912
913#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
914#       (( RET=RET+$? ))
915
916        if [ ${RET} -gt 0 ] ; then
917            echo "IGCM_sys_Get : copy error."
918            cat out_rsync
919            IGCM_debug_Exit "IGCM_sys_Get"
920        fi
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: DO NOTHING ! 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        if [ ! -f ${1} ] ; then
939            echo "WARNING : IGCM_sys_Put_Dods ${1} DOES NOT EXIST ."
940            IGCM_debug_PopStack "IGCM_sys_Put_Dods"
941            return
942        fi
943        #DO NOTHING
944    else
945        IGCM_err "DRYRUN mode = " $DRYRUN
946    fi
947    IGCM_debug_PopStack "IGCM_sys_Put_Dods"
948}
949
950############################################################## A FINIR !!
951
952#D-#==================================================
953#D-function IGCM_sys_GetDate_FichWork
954#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
955#D-* Examples:
956#D-
957function IGCM_sys_GetDate_FichWork {
958    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
959    if ( $DEBUG_sys ) ; then
960        echo "IGCM_sys_GetDate_FichWork :" $@
961    fi
962    # donne la date filesys d'un fichier sur la machine work
963    IGCM_debug_PopStack "IGCM_sys_FichWork"
964}
965
966#D-#==================================================
967#D-function IGCM_sys_GetDate_FichArchive
968#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
969#D-* Examples:
970#D-
971function IGCM_sys_GetDate_FichArchive {
972    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
973    if ( $DEBUG_sys ) ; then
974        echo "IGCM_sys_GetDate_FichArchive :" $@
975    fi
976    IGCM_debug_PopStack "IGCM_sys_FichArchive"
977}
978
979
980##############################################################
981# REBUILD OPERATOR
982
983function IGCM_sys_rebuild {
984    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
985    if ( $DEBUG_sys ) ; then
986        echo "IGCM_sys_rebuild :" $@
987    fi
988    /home/mmaipsl/TEMP_LOCAL/PARALLEL/modipsl/bin/rebuild -f -o $@
989    if [ $? -gt 0 ] ; then
990       echo "IGCM_sys_rebuild : erreur ${@}."
991       IGCM_debug_Exit "rebuild"
992    fi
993
994    IGCM_debug_PopStack "IGCM_sys_rebuild"
995}
996
997##############################################################
998# NCO OPERATOR
999
1000function IGCM_sys_ncap {
1001    IGCM_debug_PushStack "IGCM_sys_ncap" -- $@
1002    if ( $DEBUG_sys ) ; then
1003        echo "IGCM_sys_ncap :" $@
1004    fi
1005    /usr/local/bin/ncap $@
1006    if [ $? -gt 0 ] ; then
1007       echo "IGCM_sys_ncap : erreur ${@}."
1008#       IGCM_debug_Exit "ncap"
1009    fi
1010
1011    IGCM_debug_PopStack "IGCM_sys_ncap"
1012}
1013
1014ncatted=/usr/local/bin/ncatted
1015# Problem with ksh and string passed in this function to ncatted !
1016# function IGCM_sys_ncatted {
1017#     IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1018#     if ( $DEBUG_sys ) ; then
1019#       echo "IGCM_sys_ncatted :" $@
1020#     fi
1021#     /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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    /usr/local/bin/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# Activate Running Environnment Variables
1186
1187function IGCM_sys_activ_variables {
1188    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1189    if ( $DEBUG_sys ) ; then
1190        echo "IGCM_sys_activ_variables"
1191    fi
1192    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1193}
1194
1195############################################################
1196# Desactivate Running Environnment Variables
1197
1198function IGCM_sys_desactiv_variables {
1199    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1200    if ( $DEBUG_sys ) ; then
1201        echo "IGCM_sys_desactiv_variables "
1202    fi
1203    IGCM_debug_PopStack "IGCM_sys_desactiv_variables "
1204}
1205
1206############################################################
1207# Build run file
1208
1209function IGCM_sys_build_run_file {
1210    IGCM_debug_PushStack "IGCM_sys_build_run_file"
1211    if ( $DEBUG_sys ) ; then
1212        echo "IGCM_sys_build_run_file "
1213    fi
1214    IGCM_debug_PopStack "IGCM_sys_build_run_file "
1215}
Note: See TracBrowser for help on using the repository browser.