source: tags/libIGCM_v1_11/libIGCM_sys/libIGCM_sys_ulam.ksh @ 488

Last change on this file since 488 was 464, checked in by mafoipsl, 13 years ago

mfget is working again on ulam. Workaround deleted.

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