source: branches/SmoothFiles/libIGCM_sys/libIGCM_sys_calculo.ksh @ 8

Last change on this file since 8 was 8, checked in by mmaipsl, 16 years ago

MM: Add SmoothFiles? with last commit (r6) corrections.

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