source: tags/libIGCM_v1_8-old/libIGCM_sys/libIGCM_sys_calculo.ksh

Last change on this file 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 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.5 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# Set environment tools (ferret, nco, cdo)
84#====================================================
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            if [ X${3} = X ] ; then
848                IGCM_sys_Chmod 444 ${1}
849            fi
850        fi
851        #
852
853        echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
854        ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
855        RET=$?
856        IGCM_sys_Rsync_out $RET
857
858        ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
859        (( RET=RET+$? ))
860
861        if [ ${RET} -gt 0 ] ; then
862            echo "IGCM_sys_Put_Out : error."
863            cat out_rsync
864            IGCM_debug_Exit "IGCM_sys_Put_Out"
865        fi
866    else
867        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
868    fi
869    IGCM_debug_PopStack "IGCM_sys_Put_Out"
870    return 0
871}
872
873#D-#==================================================
874#D-function IGCM_sys_Get
875#D-* Purpose: Get a file from ${ARCHIVE}
876#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
877#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
878function IGCM_sys_Get {
879    IGCM_debug_PushStack "IGCM_sys_Get" $@
880
881    typeset DEST RET dm_liste ifile target
882
883    if ( $DEBUG_sys ) ; then
884        echo "IGCM_sys_Get :" $@
885    fi
886    if [ $DRYRUN -le 2 ]; then
887        if [ X${1} = X'/l' ] ; then
888            # test if the first file is present in the old computation :
889            eval set +A dm_liste \${${2}}
890        else
891            dm_liste=${1}
892        fi
893        eval DEST=\${${#}}
894
895        # test if the (first) file is present in the old computation :
896        IGCM_sys_TestFileArchive ${dm_liste[0]}
897        RET=$?
898        if [ ${RET} -gt 0 ] ; then
899            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
900            IGCM_debug_Exit "IGCM_sys_Get"
901            #return
902        fi
903
904        (( RET=0 ))
905        for target in ${dm_liste[*]} ; do
906          ln -s ${target} ${DEST} >> out_rsync 2>&1
907          (( RET=RET+$? ))
908        done
909
910#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
911#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
912#       RET=$?
913#       IGCM_sys_Rsync_out $RET
914
915#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
916#       (( RET=RET+$? ))
917
918        if [ ${RET} -gt 0 ] ; then
919            echo "IGCM_sys_Get : copy error."
920            cat out_rsync
921            IGCM_debug_Exit "IGCM_sys_Get"
922        fi
923    else
924        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
925    fi
926    IGCM_debug_PopStack "IGCM_sys_Get"
927}
928
929#D-#==================================================
930#D-function IGCM_sys_Put_Dods
931#D-* Purpose: DO NOTHING ! Put $(ARCHIVE) files on DODS internet protocole.
932#D-* Examples:
933#D-
934function IGCM_sys_Put_Dods {
935    IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
936    if ( $DEBUG_sys ) ; then
937        echo "IGCM_sys_Put_Dods :" $@
938    fi
939    if [ $DRYRUN = 0 ]; then
940        if [ ! -f ${1} ] ; then
941            echo "WARNING : IGCM_sys_Put_Dods ${1} DOES NOT EXIST ."
942            IGCM_debug_PopStack "IGCM_sys_Put_Dods"
943            return
944        fi
945        #DO NOTHING
946    else
947        IGCM_err "DRYRUN mode = " $DRYRUN
948    fi
949    IGCM_debug_PopStack "IGCM_sys_Put_Dods"
950}
951
952############################################################## A FINIR !!
953
954#D-#==================================================
955#D-function IGCM_sys_GetDate_FichWork
956#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
957#D-* Examples:
958#D-
959function IGCM_sys_GetDate_FichWork {
960    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
961    if ( $DEBUG_sys ) ; then
962        echo "IGCM_sys_GetDate_FichWork :" $@
963    fi
964    # donne la date filesys d'un fichier sur la machine work
965    IGCM_debug_PopStack "IGCM_sys_FichWork"
966}
967
968#D-#==================================================
969#D-function IGCM_sys_GetDate_FichArchive
970#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
971#D-* Examples:
972#D-
973function IGCM_sys_GetDate_FichArchive {
974    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
975    if ( $DEBUG_sys ) ; then
976        echo "IGCM_sys_GetDate_FichArchive :" $@
977    fi
978    IGCM_debug_PopStack "IGCM_sys_FichArchive"
979}
980
981
982##############################################################
983# REBUILD OPERATOR
984
985function IGCM_sys_rebuild {
986    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
987    if ( $DEBUG_sys ) ; then
988        echo "IGCM_sys_rebuild :" $@
989    fi
990    /home/mmaipsl/TEMP_LOCAL/PARALLEL/modipsl/bin/rebuild -f -o $@
991    if [ $? -gt 0 ] ; then
992       echo "IGCM_sys_rebuild : erreur ${@}."
993       IGCM_debug_Exit "rebuild"
994    fi
995
996    IGCM_debug_PopStack "IGCM_sys_rebuild"
997}
998
999##############################################################
1000# NCO OPERATOR
1001
1002function IGCM_sys_ncap {
1003    IGCM_debug_PushStack "IGCM_sys_ncap" -- $@
1004    if ( $DEBUG_sys ) ; then
1005        echo "IGCM_sys_ncap :" $@
1006    fi
1007    /usr/local/bin/ncap $@
1008    if [ $? -gt 0 ] ; then
1009       echo "IGCM_sys_ncap : erreur ${@}."
1010#       IGCM_debug_Exit "ncap"
1011    fi
1012
1013    IGCM_debug_PopStack "IGCM_sys_ncap"
1014}
1015
1016ncatted=/usr/local/bin/ncatted
1017# Problem with ksh and string passed in this function to ncatted !
1018# function IGCM_sys_ncatted {
1019#     IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1020#     if ( $DEBUG_sys ) ; then
1021#       echo "IGCM_sys_ncatted :" $@
1022#     fi
1023#     /usr/local/bin/ncatted $@
1024#     if [ $? -gt 0 ] ; then
1025#        echo "IGCM_sys_ncatted : erreur ${@}."
1026#        IGCM_debug_Exit "ncatted"
1027#     fi
1028
1029#     IGCM_debug_PopStack "IGCM_sys_ncatted"
1030# }
1031
1032function IGCM_sys_ncbo {
1033    IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1034    if ( $DEBUG_sys ) ; then
1035        echo "IGCM_sys_ncbo :" $@
1036    fi
1037    /usr/local/bin/ncbo $@
1038    if [ $? -gt 0 ] ; then
1039       echo "IGCM_sys_ncbo : erreur ${@}."
1040#       IGCM_debug_Exit "ncbo"
1041    fi
1042
1043    IGCM_debug_PopStack "IGCM_sys_ncbo"
1044}
1045
1046function IGCM_sys_ncdiff {
1047    IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1048    if ( $DEBUG_sys ) ; then
1049        echo "IGCM_sys_ncdiff :" $@
1050    fi
1051    /usr/local/bin/ncdiff $@
1052    if [ $? -gt 0 ] ; then
1053       echo "IGCM_sys_ncdiff : erreur ${@}."
1054#       IGCM_debug_Exit "ncdiff"
1055    fi
1056
1057    IGCM_debug_PopStack "IGCM_sys_ncdiff"
1058}
1059
1060function IGCM_sys_ncea {
1061    IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1062    if ( $DEBUG_sys ) ; then
1063        echo "IGCM_sys_ncea :" $@
1064    fi
1065    /usr/local/bin/ncea $@
1066    if [ $? -gt 0 ] ; then
1067       echo "IGCM_sys_ncea : erreur ${@}."
1068#       IGCM_debug_Exit "ncea"
1069    fi
1070
1071    IGCM_debug_PopStack "IGCM_sys_ncea"
1072}
1073
1074function IGCM_sys_ncecat {
1075    IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1076    if ( $DEBUG_sys ) ; then
1077        echo "IGCM_sys_ncecat :" $@
1078    fi
1079    /usr/local/bin/ncecat $@
1080    if [ $? -gt 0 ] ; then
1081       echo "IGCM_sys_ncecat : erreur ${@}."
1082#       IGCM_debug_Exit "ncecat"
1083    fi
1084
1085    IGCM_debug_PopStack "IGCM_sys_ncecat"
1086}
1087
1088function IGCM_sys_ncflint {
1089    IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1090    if ( $DEBUG_sys ) ; then
1091        echo "IGCM_sys_ncflint :" $@
1092    fi
1093    /usr/local/bin/ncflint $@
1094    if [ $? -gt 0 ] ; then
1095       echo "IGCM_sys_ncflint : erreur ${@}."
1096#       IGCM_debug_Exit "ncflint"
1097    fi
1098
1099    IGCM_debug_PopStack "IGCM_sys_ncflint"
1100}
1101
1102function IGCM_sys_ncks {
1103    IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1104    if ( $DEBUG_sys ) ; then
1105        echo "IGCM_sys_ncks :" $@
1106    fi
1107    /usr/local/bin/ncks $@
1108    if [ $? -gt 0 ] ; then
1109       echo "IGCM_sys_ncks : erreur ${@}."
1110#       IGCM_debug_Exit "ncks"
1111    fi
1112
1113    IGCM_debug_PopStack "IGCM_sys_ncks"
1114}
1115
1116function IGCM_sys_ncpdq {
1117    IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1118    if ( $DEBUG_sys ) ; then
1119        echo "IGCM_sys_ncpdq :" $@
1120    fi
1121    /usr/local/bin/ncpdq $@
1122    if [ $? -gt 0 ] ; then
1123       echo "IGCM_sys_ncpdq : erreur ${@}."
1124#       IGCM_debug_Exit "ncpdq"
1125    fi
1126
1127    IGCM_debug_PopStack "IGCM_sys_ncpdq"
1128}
1129
1130function IGCM_sys_ncra {
1131    IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1132    if ( $DEBUG_sys ) ; then
1133        echo "IGCM_sys_ncra :" $@
1134    fi
1135    /usr/local/bin/ncra $@
1136    if [ $? -gt 0 ] ; then
1137       echo "IGCM_sys_ncra : erreur ${@}."
1138#       IGCM_debug_Exit "ncra"
1139    fi
1140
1141    IGCM_debug_PopStack "IGCM_sys_ncra"
1142}
1143
1144function IGCM_sys_ncrcat {
1145    IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1146    if ( $DEBUG_sys ) ; then
1147        echo "IGCM_sys_ncrcat :" $@
1148    fi
1149    /usr/local/bin/ncrcat $@
1150    if [ $? -gt 0 ] ; then
1151       echo "IGCM_sys_ncrcat : erreur ${@}."
1152#       IGCM_debug_Exit "ncrcat"
1153    fi
1154
1155    IGCM_debug_PopStack "IGCM_sys_ncrcat"
1156}
1157
1158function IGCM_sys_ncrename {
1159    IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1160    if ( $DEBUG_sys ) ; then
1161        echo "IGCM_sys_ncrename :" $@
1162    fi
1163    /usr/local/bin/ncrename $@
1164    if [ $? -gt 0 ] ; then
1165       echo "IGCM_sys_ncrename : erreur ${@}."
1166#       IGCM_debug_Exit "ncrename"
1167    fi
1168
1169    IGCM_debug_PopStack "IGCM_sys_ncrename"
1170}
1171
1172function IGCM_sys_ncwa {
1173    IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1174    if ( $DEBUG_sys ) ; then
1175        echo "IGCM_sys_ncwa :" $@
1176    fi
1177    /usr/local/bin/ncwa $@
1178    if [ $? -gt 0 ] ; then
1179       echo "IGCM_sys_ncwa : erreur ${@}."
1180#       IGCM_debug_Exit "ncwa"
1181    fi
1182
1183    IGCM_debug_PopStack "IGCM_sys_ncwa"
1184}
1185
1186############################################################
1187# Activate Running Environnment Variables
1188
1189function IGCM_sys_activ_variables {
1190    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1191    if ( $DEBUG_sys ) ; then
1192        echo "IGCM_sys_activ_variables"
1193    fi
1194    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1195}
1196
1197############################################################
1198# Desactivate Running Environnment Variables
1199
1200function IGCM_sys_desactiv_variables {
1201    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1202    if ( $DEBUG_sys ) ; then
1203        echo "IGCM_sys_desactiv_variables "
1204    fi
1205    IGCM_debug_PopStack "IGCM_sys_desactiv_variables "
1206}
1207
1208############################################################
1209# Build run file
1210
1211function IGCM_sys_build_run_file {
1212    IGCM_debug_PushStack "IGCM_sys_build_run_file"
1213    if ( $DEBUG_sys ) ; then
1214        echo "IGCM_sys_build_run_file "
1215    fi
1216    IGCM_debug_PopStack "IGCM_sys_build_run_file "
1217}
Note: See TracBrowser for help on using the repository browser.