source: tags/libIGCM_v2.0_rc3/libIGCM_sys/libIGCM_sys_iitm.ksh @ 1591

Last change on this file since 1591 was 801, checked in by sdipsl, 11 years ago
  • Some adaptation so as to find and prepare tared restart on Ada.
File size: 33.2 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sébastien Denvil
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
6# $Revision:: 423                                      $ Revision of last commit
7# $Author:: sdipsl                                     $ Author of last commit
8# $Date:: 2011-02-18 16:49:14 +0100 (ven. 18 févr. 20#$ 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 IITM IBM machine
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# $hostname of the MASTER job
70typeset -r MASTER=iitm01
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="-va"
81
82#====================================================
83# Host specific DIRECTORIES
84#====================================================
85
86#====================================================
87#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
88typeset -r R_EXE="${MODIPSL}/bin"
89
90#====================================================
91#- SUBMIT_DIR : submission dir
92typeset SUBMIT_DIR=${SUBMIT_DIR:=${LOADL_STEP_INITDIR}}
93
94#====================================================
95#- IN
96typeset -r R_IN=${R_IN:=/gpfs1/home/sabin}
97typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/gpfs1/home/sabin}
98
99#====================================================
100#- ARCHIVE
101typeset -r ARCHIVE=$( echo ${HOME} | sed -e "s/gpfs1/gpfs3/" )
102
103#====================================================
104#- Mirror libIGCM from iitm to a post-processing machine
105typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
106
107#====================================================
108#- libIGCM_POST
109typeset -r HOME_POST=${HOME}
110typeset -r libIGCM_POST=${libIGCM}
111
112#====================================================
113#- OUT
114typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
115
116#====================================================
117#- RUN_DIR_PATH : Temporary working directory (=> TMP)
118typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${ARCHIVE}/RUN/${LOADL_STEP_ID}}
119
120#====================================================
121#- BIG_DIR : BIG_DIR to store files waiting for rebuild
122typeset -r BIG_DIR=${BIG_DIR:=${ARCHIVE}/REBUILD}
123
124#====================================================
125#- HOST_MPIRUN_COMMAND
126typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time poe"}
127
128#====================================================
129#- Max number of arguments passed to nco operator or demigration command
130UNIX_MAX_LIMIT=360
131
132#D-#==================================================
133#D-function IGCM_sys_ChangeArchive
134#D-* Purpose: Just a dummy call on this machine
135#D-* Examples:
136#D-
137function IGCM_sys_ChangeArchive {
138
139  IGCM_debug_Print 1 " dummy function : IGCM_sys_ChangeArchive "
140
141}
142
143#D-#==================================================
144#D-function IGCM_sys_RshMaster
145#D-* Purpose: Just a fake command to wrapp
146#D-           IGCM_card call in post-treatment
147#D-           Ulam do not see brodie filesystem
148#D-           Cesium do not see all mercure filesystem
149#D-           That's why we need this hack.
150#D-* Examples:
151#D-
152function IGCM_sys_RshMaster {
153    IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
154    /bin/ksh <<-EOF
155    ${@}
156EOF
157    if [ $? -gt 0 ] ; then
158      echo "IGCM_sys_RshArchive : erreur."
159      IGCM_debug_Exit "IGCM_sys_RshArchive"
160    fi
161    IGCM_debug_PopStack "IGCM_sys_RshMaster"
162}
163
164#D-#==================================================
165#D-function IGCM_sys_RshArchive
166#D-* Purpose: Archive rsh command
167#D-* Examples:
168#D-
169function IGCM_sys_RshArchive {
170    IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
171    /bin/ksh <<-EOF
172    ${@}
173EOF
174    if [ $? -gt 0 ] ; then
175      echo "IGCM_sys_RshArchive : erreur."
176      IGCM_debug_Exit "IGCM_sys_RshArchive"
177    fi
178    IGCM_debug_PopStack "IGCM_sys_RshArchive"
179}
180
181#D-#==================================================
182#D-function IGCM_sys_RshPost
183#D-* Purpose: Post-process rsh command
184#D-* Examples:
185#D-
186function IGCM_sys_RshPost {
187    IGCM_debug_PushStack "IGCM_sys_RshPost" $@
188    if ( $DEBUG_sys ) ; then
189      echo "IGCM_sys_RshPost :" $@
190    fi
191    /bin/ksh ${@}
192    #rsh ulam exec /bin/ksh ${@}
193    if [ $? -gt 0 ] ; then
194      echo "IGCM_sys_RshPost : erreur."
195      IGCM_debug_Exit "IGCM_sys_RshPost"
196    fi
197    IGCM_debug_PopStack "IGCM_sys_RshPost"
198}
199
200#D-#==================================================
201#D-function IGCM_sys_SendMail
202#D-* Purpose: Send mail when simulation is over
203#D-* Examples:
204#D-
205function IGCM_sys_SendMail {
206    IGCM_debug_PushStack "IGCM_sys_SendMail" $@
207    if ( $DEBUG_sys ) ; then
208      echo "IGCM_sys_SendMail :" $@
209    fi
210
211    if ( ${ExitFlag} ) ; then
212      status=failed
213    else
214      status=completed
215    fi
216    cat  << END_MAIL > job_end.mail
217Dear ${LOGIN},
218
219  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
220  Job started : ${DateBegin}
221  Job ended   : ${DateEnd}
222  Ouput files are available in ${R_SAVE}
223  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
224END_MAIL
225
226    if [ ! -z ${config_UserChoices_MailName} ] ; then
227      mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
228    elif [ -f ~/.forward ] ; then
229      mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
230    else
231      mailx -s "${config_UserChoices_JobName} ${status}" ${USER} < job_end.mail
232    fi
233
234    if [ $? -gt 0 ] ; then
235      echo "IGCM_sys_SendMail : erreur."
236      IGCM_debug_Exit "IGCM_sys_SendMail"
237    fi
238    IGCM_debug_PopStack "IGCM_sys_SendMail"
239}
240
241#D-#==================================================
242#D-function IGCM_sys_Mkdir
243#D-* Purpose: Master locale mkdir command
244#D-* Examples:
245#D-
246function IGCM_sys_Mkdir {
247    IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
248    if ( $DEBUG_sys ) ; then
249      echo "IGCM_sys_Mkdir :" $@
250    fi
251    if [ ! -d ${1} ]; then
252      \mkdir -p $1
253      if [ $? -gt 0 ] ; then
254        echo "IGCM_sys_Mkdir : erreur."
255        IGCM_debug_Exit "IGCM_sys_Mkdir"
256      fi
257    fi
258    # vérification :
259    if [ ! -d ${1} ] ; then
260      echo "IGCM_sys_Mkdir : erreur."
261      IGCM_debug_Exit "IGCM_sys_Mkdir"
262    fi
263    IGCM_debug_PopStack "IGCM_sys_Mkdir"
264}
265
266#D-#==================================================
267#D-function IGCM_sys_MkdirArchive
268#D-* Purpose: Mkdir on Archive
269#D-* Examples:
270#D-
271function IGCM_sys_MkdirArchive {
272    IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
273    if ( $DEBUG_sys ) ; then
274      echo "IGCM_sys_MkdirArchive :" $@
275    fi
276    #- creation de repertoire sur le serveur fichier
277    mkdir -p $1
278
279    if [ $? -gt 0 ] ; then
280      echo "IGCM_sys_MkdirArchive : erreur."
281      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
282    fi
283    IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
284}
285
286#D-#==================================================
287#D-function IGCM_sys_MkdirWork
288#D-* Purpose: Mkdir on Work
289#D-* Examples:
290#D-
291function IGCM_sys_MkdirWork {
292    IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
293    if ( $DEBUG_sys ) ; then
294      echo "IGCM_sys_MkdirWork :" $@
295    fi
296    #- creation de repertoire sur le serveur fichier
297    if [ ! -d ${1} ]; then 
298      \mkdir -p $1
299      if [ $? -gt 0 ] ; then
300        echo "IGCM_sys_MkdirWork : erreur."
301        IGCM_debug_Exit "IGCM_sys_MkdirWork"
302      fi
303    fi
304    IGCM_debug_PopStack "IGCM_sys_MkdirWork"
305}
306
307#D-#==================================================
308#D-function IGCM_sys_Cd
309#D-* Purpose: master cd command
310#D-* Examples:
311#D-
312function IGCM_sys_Cd {
313    IGCM_debug_PushStack "IGCM_sys_Cd" $@
314    if ( $DEBUG_sys ) ; then
315      echo "IGCM_sys_Cd :" $@
316    fi
317    \cd $1
318    if [ $? -gt 0 ] ; then
319      echo "IGCM_sys_Cd : erreur."
320      IGCM_debug_Exit "IGCM_sys_Cd"
321    fi
322    IGCM_debug_PopStack "IGCM_sys_Cd"
323}
324
325#D-#==================================================
326#D-function IGCM_sys_Chmod
327#D-* Purpose: Chmod
328#D-* Examples:
329#D-
330function IGCM_sys_Chmod {
331    IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
332    if ( $DEBUG_sys ) ; then
333      echo "IGCM_sys_Chmod :" $@
334    fi
335    if [ $DRYRUN -le 1 ]; then
336      \chmod $@
337      if [ $? -gt 0 ] ; then
338        echo "IGCM_sys_Chmod : erreur."
339        IGCM_debug_Exit "IGCM_sys_Chmod"
340      fi
341    else
342      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
343    fi
344    IGCM_debug_PopStack "IGCM_sys_Chmod"
345}
346
347#D-#==================================================
348#D-function IGCM_sys_FileSize
349#D-* Purpose: Filesize
350#D-* Examples:
351#D-
352function IGCM_sys_FileSize {
353    IGCM_debug_PushStack "IGCM_sys_FileSize" $@
354
355    typeset sizeF
356    set +A sizeF -- $( ls -la ${1} )
357    if [ $? -gt 0 ] ; then
358      IGCM_debug_Exit "IGCM_sys_FileSize"
359    fi
360    eval ${2}=${sizeF[4]}
361
362    IGCM_debug_PopStack "IGCM_sys_FileSize"
363}
364
365#D-#==================================================
366#D-function IGCM_sys_TestDir
367#D-* Purpose: Test Directory that must exists
368#D-* Examples:
369#D-
370function IGCM_sys_TestDir {
371    IGCM_debug_PushStack "IGCM_sys_TestDir" $@
372    if ( $DEBUG_sys ) ; then
373      echo "IGCM_sys_TestDir :" $@
374    fi
375    typeset ExistFlag
376    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
377    IGCM_debug_PopStack "IGCM_sys_TestDir"
378
379    return ${ExistFlag}
380}
381
382#D-#==================================================
383#D-function IGCM_sys_TestDirArchive
384#D-* Purpose: Test Directory that must exists on Archive
385#D-* Examples:
386#D-
387function IGCM_sys_TestDirArchive {
388    IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
389    if ( $DEBUG_sys ) ; then
390      echo "IGCM_sys_TestDirArchive :" $@
391    fi
392    typeset ExistFlag
393    ExistFlag=$( IGCM_sys_RshArchive "[ -d $1 ] && echo 0 || echo 1" )
394    IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
395
396    return ${ExistFlag}
397}
398
399#D-#==================================================
400#D-function IGCM_sys_TestFileArchive
401#D-* Purpose: Test file that must NOT EXISTS on Archive
402#D-* Examples:
403#D-
404function IGCM_sys_TestFileArchive {
405    IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
406    typeset ExistFlag
407    ExistFlag=$( IGCM_sys_RshArchive "[ -f $1 ] && echo 0 || echo 1" )
408    IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
409
410    return ${ExistFlag}
411}
412
413#D-#==================================================
414#D-function IGCM_sys_CountFileArchive
415#D-* Purpose: Count files on Archive filesystem
416#D-* Examples:
417#D-
418function IGCM_sys_CountFileArchive {
419    IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
420    IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
421    if [ $? -gt 0 ] ; then
422      echo "IGCM_sys_CountFileArchive : erreur."
423    fi
424    IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
425}
426
427#D-#==================================================
428#D-function IGCM_sys_Tree
429#D-* Purpose: Tree directories with files on ${ARCHIVE}
430#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
431#D-
432function IGCM_sys_Tree {
433    IGCM_debug_PushStack "IGCM_sys_Tree" $@
434    if ( $DEBUG_sys ) ; then
435      echo "IGCM_sys_Tree :" $@
436    fi
437
438    \ls -r $@
439
440    IGCM_debug_PopStack "IGCM_sys_Tree"
441}
442
443#D-#==================================================
444#D-function IGCM_sys_Tar
445#D-* Purpose: master un-tar command
446#D-* Examples:
447#D-
448function IGCM_sys_Tar {
449    IGCM_debug_PushStack "IGCM_sys_Tar" $@
450    if ( $DEBUG_sys ) ; then
451      echo "IGCM_sys_Tar :" $@
452    fi
453    \tar cvf $@
454    if [ $? -gt 0 ] ; then
455      echo "IGCM_sys_Tar : erreur."
456      IGCM_debug_Exit "IGCM_sys_Tar"
457    fi
458    \tar tvf $1
459
460    IGCM_debug_PopStack "IGCM_sys_Tar"
461}
462
463#D-#==================================================
464#D-function IGCM_sys_UnTar
465#D-* Purpose: master un-tar command
466#D-* Examples:
467#D-
468function IGCM_sys_UnTar {
469    IGCM_debug_PushStack "IGCM_sys_UnTar" $@
470    if ( $DEBUG_sys ) ; then
471      echo "IGCM_sys_UnTar :" $@
472    fi
473    \tar xvf $1
474    if [ $? -gt 0 ] ; then
475      echo "IGCM_sys_UnTar : erreur."
476      IGCM_debug_Exit "IGCM_sys_UnTar"
477    fi
478    IGCM_debug_PopStack "IGCM_sys_UnTar"
479}
480
481#D-#==================================================
482#D-function IGCM_sys_Qsub
483#D-* Purpose: Qsub new job
484#D-* Examples:
485#D-
486function IGCM_sys_Qsub {
487    IGCM_debug_PushStack "IGCM_sys_Qsub" $@
488    if ( $DEBUG_sys ) ; then
489      echo "IGCM_sys_Qsub :" $@
490    fi
491    {
492      [ ${#@} = 1 ] &&  { cd $LOADL_STEP_INITDIR ; /usr/lpp/LoadL/full/bin/llsubmit $1 ; ERROR=$? ; cd - ; }
493      [ ${#@} = 2 ] &&  { cd $2 ; /usr/lpp/LoadL/full/bin/llsubmit $1 ; ERROR=$? ; cd - ; }
494    }
495    if [ ${ERROR} -gt 0 ] ; then
496      echo "IGCM_sys_Qsub : erreur $@."
497      IGCM_debug_Exit "IGCM_sys_Qsub"
498    fi
499    IGCM_debug_PopStack "IGCM_sys_Qsub"
500}
501
502#D-#==================================================
503#D-function IGCM_sys_QsubPost
504#D-* Purpose: Qsub new job on scalaire
505#D-* Examples:
506#D-
507function IGCM_sys_QsubPost {
508    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
509    if ( $DEBUG_sys ) ; then
510      echo "IGCM_sys_QsubPost :" $@
511    fi
512    cd ${POST_DIR}
513    /usr/lpp/LoadL/full/bin/llsubmit ${libIGCM_POST}/$1.job
514    cd -
515    if [ $? -gt 0 ] ; then
516      echo "IGCM_sys_QsubPost : erreur " $@
517      IGCM_debug_Exit "IGCM_sys_QsubPost"
518    fi
519    IGCM_debug_PopStack "IGCM_sys_QsubPost"
520}
521
522#D-*************************
523#D- File transfer functions
524#D-*************************
525#D-
526
527#D-#==================================================
528#D-function IGCM_sys_Rsync_out
529#D-* Purpose: treat return val of rsync
530#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
531#D-  Error values and explanations can depend on your system version.
532function IGCM_sys_Rsync_out {
533    RET=$1
534    if [ ! $RET ] ; then
535      echo "rsync error !"
536    fi
537
538    if [ $MYLANG = "fr" ]; then
539      case $RET in
540          0)  return ;;
541          1)  echo "Erreur de rsync ; RERR_SYNTAX : "
542            echo "Erreur de syntaxe ou d'utilisation."
543            return;;
544          2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
545            echo "Incompatibilité de protocole."
546            return;;
547          3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
548            echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
549            echo "répertoires"
550            return;;
551          4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
552            echo "Action demandée non supportée : une tentative de manipulation de"
553            echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
554            echo "été faite ; ou une option qui est supportée par le  client  mais"
555            echo "pas par le serveur a été spécifiée."
556            return;;
557          10) echo "Erreur de rsync ; RERR_SOCKETIO"
558            echo "Erreur dans le socket d'entrée sortie"
559            return;;
560          11) echo "Erreur de rsync ; RERR_FILEIO"
561            echo "Erreur d'entrée sortie fichier"
562            return;;
563          12) echo "Erreur de rsync ; RERR_STREAMIO"
564            echo "Erreur dans flux de donnée du protocole rsync"
565            return;;
566          13) echo "Erreur de rsync ; RERR_MESSAGEIO"
567            echo "Erreur avec les diagnostics du programme"
568            return;;
569          14) echo "Erreur de rsync ; RERR_IPC"
570            echo "Erreur dans le code IPC"
571            return;;
572          20) echo "Erreur de rsync ; RERR_SIGNAL"
573            echo "SIGUSR1 ou SIGINT reçu"
574            return;;
575          21) echo "Erreur de rsync ; RERR_WAITCHILD"
576            echo "Une erreur retournée par waitpid()"
577            return;;
578          22) echo "Erreur de rsync ; RERR_MALLOC"
579            echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
580            return;;
581          23) echo ""
582                echo "Erreur fichier inexistant"
583            return;;
584          30) echo "Erreur de rsync ; RERR_TIMEOUT"
585            echo "Temps d'attente écoulé dans l'envoi/réception de données"
586            return;;
587          *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
588            return;;
589      esac
590    elif [ $MYLANG = "en" ] ; then
591      case $RET in
592          0)  return;;       
593          1)  echo "rsync error : Syntax or usage error "
594            return;;
595          2)  echo "rsync error : Protocol incompatibility "
596            return;;
597          3)  echo "rsync error : Errors selecting input/output files, dirs"
598            return;;
599          4)  echo "rsync error : Requested action not supported: an attempt"
600            echo "was made to manipulate 64-bit files on a platform that cannot support"
601            echo "them; or an option was specified that is supported by the client and"
602            echo "not by the server."
603            return;;
604          5)  echo "rsync error : Error starting client-server protocol"
605            return;;
606          10) echo "rsync error : Error in socket I/O "
607            return;;
608          11) echo "rsync error : Error in file I/O "
609            return;;
610          12) echo "rsync error : Error in rsync protocol data stream "
611            return;;
612          13) echo "rsync error : Errors with program diagnostics "
613            return;;
614          14) echo "rsync error : Error in IPC code "
615            return;;
616          20) echo "rsync error : Received SIGUSR1 or SIGINT "
617            return;;
618          21) echo "rsync error : Some error returned by waitpid() "
619            return;;
620          22) echo "rsync error : Error allocating core memory buffers "
621            return;;
622          23) echo "rsync error : Partial transfer due to error"
623            return;;
624          24) echo "rsync error : Partial transfer due to vanished source files"
625            return;;
626          30) echo "rsync error : Timeout in data send/receive "
627            return;;
628          *)  echo "rsync error : return code of rsync unknown :" $RET
629            return;;
630      esac
631    else
632      echo "unknown language $MYLANG."
633      return
634    fi
635}
636
637#D-#==================================================
638#D-function IGCM_sys_Cp
639#D-* Purpose: generic cp
640#D-* Examples:
641#D-
642function IGCM_sys_Cp {
643    IGCM_debug_PushStack "IGCM_sys_Cp" $@
644    if ( $DEBUG_sys ) ; then
645      echo "IGCM_sys_Cp :" $@
646    fi
647
648    typeset RET
649
650    echo cp $@ > out_rsync 2>&1
651    \cp $@ >> out_rsync 2>&1
652    RET=$?
653
654    if [ ${RET} -gt 0 ] ; then
655      echo "IGCM_sys_Cp : error."
656      cat out_rsync
657      IGCM_debug_Exit "IGCM_sys_Cp"
658    fi
659    IGCM_debug_PopStack "IGCM_sys_Cp"
660}
661
662#D-#==================================================
663#D-function IGCM_sys_Rm
664#D-* Purpose: generic rm
665#D-* Examples:
666#D-
667function IGCM_sys_Rm {
668    IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
669    if ( $DEBUG_sys ) ; then
670      echo "IGCM_sys_Rm :" $@
671    fi
672
673    typeset RET
674
675    echo rm $@ > out_rsync 2>&1
676    \rm $@ >> out_rsync 2>&1
677    RET=$?
678
679    if [ ${RET} -gt 0 ] ; then
680      echo "IGCM_sys_Rm : error."
681      cat out_rsync
682      IGCM_debug_Exit "IGCM_sys_Rm"
683    fi
684    IGCM_debug_PopStack "IGCM_sys_Rm"
685}
686
687#D-#==================================================
688#D-function IGCM_sys_RmRunDir
689#D-* Purpose: rm tmpdir (dummy function most of the time batch
690#D-                      scheduler will do the job)
691#D-* Examples:
692#D-
693function IGCM_sys_RmRunDir {
694    IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
695    if ( $DEBUG_sys ) ; then
696      echo "IGCM_sys_RmRunDir :" $@
697    fi
698
699    typeset RET
700
701    echo rm $@ > out_rsync 2>&1
702    \rm $@ >> out_rsync 2>&1
703    RET=$?
704
705    if [ ${RET} -gt 0 ] ; then
706      echo "IGCM_sys_RmRunDir : error."
707      cat out_rsync
708      IGCM_debug_Exit "IGCM_sys_RmRunDir"
709    else
710      \rm out_rsync
711    fi
712
713    IGCM_debug_PopStack "IGCM_sys_RmRunDir"
714}
715
716#D-#==================================================
717#D-function IGCM_sys_Mv
718#D-* Purpose: generic move
719#D-* Examples:
720#D-
721function IGCM_sys_Mv {
722    IGCM_debug_PushStack "IGCM_sys_Mv" $@
723    if ( $DEBUG_sys ) ; then
724      echo "IGCM_sys_Mv :" $@
725    fi
726
727    if [ $DRYRUN = 0 ]; then
728
729        typeset RET
730
731        echo mv $@ > out_rsync 2>&1
732        \mv $@ >> out_rsync 2>&1
733        RET=$?
734
735        if [ ${RET} -gt 0 ] ; then
736            echo "IGCM_sys_Mv : error in mv."
737            cat out_rsync
738            IGCM_debug_Exit "IGCM_sys_Mv"
739        fi
740    else
741        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
742    fi
743
744    IGCM_debug_PopStack "IGCM_sys_Mv"
745}
746
747#D-#==================================================
748#D-function IGCM_sys_Put_Dir
749#D-* Purpose: Copy a complete directory on $(ARCHIVE)
750#D-* Examples:
751#D-
752function IGCM_sys_Put_Dir {
753    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
754    if ( $DEBUG_sys ) ; then
755      echo "IGCM_sys_Put_Dir :" $@
756    fi
757    if [ $DRYRUN = 0 ]; then
758      if [ ! -d ${1} ] ; then
759          echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
760          IGCM_debug_PopStack "IGCM_sys_Put_Dir"
761          return
762      fi
763
764      typeset RET
765
766      # Only if we use rsync
767      #IGCM_sys_TestDirArchive $( dirname $2 )
768      #
769      #USUAL WAY
770      \cp -r $1 $2 > out_rsync 2>&1
771      RET=$?
772
773      if [ ${RET} -gt 0 ] ; then
774          echo "IGCM_sys_Put_Dir : error."
775          cat out_rsync
776          IGCM_debug_Exit "IGCM_sys_Put_Dir"
777      fi
778    else
779      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
780    fi
781    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
782}
783
784#D-#==================================================
785#D-function IGCM_sys_Get_Dir
786#D-* Purpose: Copy a complete directory from $(ARCHIVE)
787#D-* Examples:
788#D-
789function IGCM_sys_Get_Dir {
790    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
791    if ( $DEBUG_sys ) ; then
792      echo "IGCM_sys_Get_Dir :" $@
793    fi
794    if [ $DRYRUN = 0 ]; then
795      if [ ! -d ${1} ] ; then
796          echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
797          IGCM_debug_PopStack "IGCM_sys_Get_Dir"
798          return
799      fi
800
801      typeset RET
802
803      #USUAL WAY
804      \cp -rp $1 $2 > out_rsync 2>&1
805      RET=$?
806
807      if [ ${RET} -gt 0 ] ; then
808          echo "IGCM_sys_Get_Dir : error."
809          cat out_rsync
810          IGCM_debug_Exit "IGCM_sys_Get_Dir"
811      fi
812    else
813      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
814    fi
815    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
816}
817
818#D-#==================================================
819#D-function IGCM_sys_Get_Master
820#D-* Purpose: Copy a complete directory from MASTER filesystem
821#D-* Examples:
822#D-
823function IGCM_sys_Get_Master {
824    IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
825    if ( $DEBUG_sys ) ; then
826      echo "IGCM_sys_Get_Master :" $@
827    fi
828    if [ $DRYRUN = 0 ]; then
829        if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
830            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
831            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
832            return
833        fi
834
835        typeset RET
836
837        #USUAL WAY
838        \cp -rp $1 $2 > out_rsync 2>&1
839        RET=$?
840
841        if [ ${RET} -gt 0 ] ; then
842            echo "IGCM_sys_Get_Dir : error."
843            cat out_rsync
844            IGCM_debug_Exit "IGCM_sys_Get_Dir"
845        fi
846    else
847      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
848    fi
849    IGCM_debug_PopStack "IGCM_sys_Get_Master"
850}
851
852#D-#==================================================
853#D-function IGCM_sys_Put_Rest
854#D-* Purpose: Put computied restarts on $(ARCHIVE).
855#D-           File and target directory must exist.
856#D-* Examples:
857#D-
858function IGCM_sys_Put_Rest {
859    IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
860    if ( $DEBUG_sys ) ; then
861      echo "IGCM_sys_Put_Rest :" $@
862    fi
863    if [ $DRYRUN = 0 ]; then
864      if [ ! -f ${1} ] ; then
865          echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
866          IGCM_debug_Exit "IGCM_sys_Put_Rest"
867      fi
868
869      typeset RET
870      #
871      if [ X${JobType} = XRUN ] ; then
872          IGCM_sys_Chmod 444 ${1}
873      fi
874      #
875      # Only if we use rsync
876      #IGCM_sys_MkdirArchive $( dirname $2 )
877      #
878      #USUAL WAY
879      \cp $1 $2 > out_rsync 2>&1
880      RET=$?
881
882      if [ ${RET} -gt 0 ] ; then
883          echo "IGCM_sys_Put_Rest : error."
884          cat out_rsync
885          IGCM_debug_Exit "IGCM_sys_Put_Rest"
886      fi
887    else
888      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
889    fi
890    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
891}
892
893#D-#==================================================
894#D-function IGCM_sys_PrepareTaredRestart
895#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
896#D-* Examples:
897#D-
898function IGCM_sys_PrepareTaredRestart {
899  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
900  echo $1
901  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
902}
903
904#D-#==================================================
905#D-function IGCM_sys_Put_Out
906#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
907#D-* Examples:
908#D-
909function IGCM_sys_Put_Out {
910    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
911    if ( $DEBUG_sys ) ; then
912      echo "IGCM_sys_Put_Out :" $@
913    fi
914    if [ $DRYRUN = 0 ]; then
915      if [ ! -f ${1} ] ; then
916          echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
917          IGCM_debug_PopStack "IGCM_sys_Put_Out"
918          return 1
919      fi
920      #
921      IGCM_sys_MkdirArchive $( dirname $2 )
922      #
923      typeset RET
924      #
925      if [ X${JobType} = XRUN ] ; then
926          if [ X${3} = X ] ; then
927            IGCM_sys_Chmod 444 ${1}
928          fi
929      fi
930      #
931      #USUAL WAY
932      \cp $1 $2 > out_rsync 2>&1
933      RET=$?
934
935      if [ ${RET} -gt 0 ] ; then
936          echo "IGCM_sys_Put_Out : error."
937          cat out_rsync
938          IGCM_debug_Exit "IGCM_sys_Put_Out"
939      fi
940    else
941      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
942    fi
943    IGCM_debug_PopStack "IGCM_sys_Put_Out"
944    return 0
945}
946
947#D-#==================================================
948#D-function IGCM_sys_Get
949#D-* Purpose: Get a file from ${ARCHIVE}
950#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
951#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
952function IGCM_sys_Get {
953    IGCM_debug_PushStack "IGCM_sys_Get" $@
954
955    typeset DEST RET dm_liste ifile target
956
957    if ( $DEBUG_sys ) ; then
958      echo "IGCM_sys_Get :" $@
959    fi
960    if [ $DRYRUN -le 2 ]; then
961      if [ X${1} = X'/l' ] ; then
962            # test if the first file is present in the old computation :
963          eval set +A dm_liste \${${2}}
964      else
965          dm_liste=${1}
966      fi
967      eval DEST=\${${#}}
968
969        # test if the (first) file is present in the old computation :
970      IGCM_sys_TestFileArchive ${dm_liste[0]}
971      RET=$?
972        if [ ${RET} -gt 0 ] ; then
973          echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
974          IGCM_debug_Exit "IGCM_sys_Get"
975          return
976        fi
977
978      # SD : dm_liste is not suited for computing job
979      #      because we change filename during transfert
980      #      dm_liste is better suited for post-treatment
981      #dm_liste=" "
982      #(( ifile=1 ))
983      #while [ $ifile -lt $# ] ; do
984      #    dm_liste=$( eval echo ${dm_liste} " "\${${ifile}} )
985      #    (( ifile = ifile + 1 ))
986      #done
987      #DEST=$( eval echo \${${#}} )
988
989      #USUAL WAY
990      \cp ${dm_liste[*]} ${DEST} > out_rsync 2>&1
991      RET=$?
992
993      if [ ${RET} -gt 0 ] ; then
994          echo "IGCM_sys_Get : copy error."
995          cat out_rsync
996          IGCM_debug_Exit "IGCM_sys_Get"
997      fi
998    else
999      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1000    fi
1001    IGCM_debug_PopStack "IGCM_sys_Get"
1002}
1003
1004############################################################## A FINIR !!
1005
1006#D-#==================================================
1007#D-function IGCM_sys_GetDate_FichWork
1008#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1009#D-* Examples:
1010#D-
1011function IGCM_sys_GetDate_FichWork {
1012    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1013    if ( $DEBUG_sys ) ; then
1014      echo "IGCM_sys_GetDate_FichWork :" $@
1015    fi
1016    # donne la date filesys d'un fichier sur la machine work
1017    IGCM_debug_PopStack "IGCM_sys_FichWork"
1018}
1019
1020#D-#==================================================
1021#D-function IGCM_sys_GetDate_FichArchive
1022#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1023#D-* Examples:
1024#D-
1025function IGCM_sys_GetDate_FichArchive {
1026    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1027    if ( $DEBUG_sys ) ; then
1028      echo "IGCM_sys_GetDate_FichArchive :" $@
1029    fi
1030    IGCM_debug_PopStack "IGCM_sys_FichArchive"
1031}
1032
1033##############################################################
1034# REBUILD OPERATOR
1035
1036function IGCM_sys_rebuild {
1037    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1038    if ( $DEBUG_sys ) ; then
1039      echo "IGCM_sys_rebuild :" $@
1040    fi
1041    /gpfs1/home/sebastien/REBUILD/rebuild -f -o $@
1042    if [ $? -gt 0 ] ; then
1043       echo "IGCM_sys_rebuild : erreur ${@}."
1044       IGCM_debug_Exit "rebuild"
1045    fi
1046
1047    IGCM_debug_PopStack "IGCM_sys_rebuild"
1048}
1049
1050############################################################
1051# Activate Running Environnment Variables
1052
1053function IGCM_sys_activ_variables {
1054    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1055    if ( $DEBUG_sys ) ; then
1056      echo "IGCM_sys_activ_variables "
1057    fi
1058
1059# --------------------------------------------------------------------
1060#D- MPI specifications
1061# --------------------------------------------------------------------
1062
1063# --------------------------------------------------------------------
1064#D- Other specifications
1065# --------------------------------------------------------------------
1066
1067    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1068
1069}
1070
1071############################################################
1072# Desactivate Running Environnment Variables
1073
1074function IGCM_sys_desactiv_variables {
1075    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1076    if ( $DEBUG_sys ) ; then
1077      echo "IGCM_sys_desactiv_variables "
1078    fi
1079# --------------------------------------------------------------------
1080#D- MPI specifications
1081# --------------------------------------------------------------------
1082
1083# --------------------------------------------------------------------
1084#D- Other specifications
1085# --------------------------------------------------------------------
1086
1087    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1088 
1089}
1090
1091############################################################
1092# Build run file
1093
1094function IGCM_sys_build_run_file {
1095    IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1096set -x
1097    if ( $DEBUG_sys ) ; then
1098      echo "IGCM_sys_build_run_file " $@
1099    fi
1100
1101    NUM_PROC_OASIS=1
1102
1103    # Set the number of processors for OCE here
1104    NUM_PROC_OCE=5
1105
1106    (( NUM_PROC_ATM = BATCH_NUM_PROC_TOT - NUM_PROC_OASIS - NUM_PROC_OCE ))
1107
1108    if [ $1 = MPI2 ]; then
1109       echo "IGCM_sys_build_run_file : error - MPI2 not available on iitm. "
1110       IGCM_debug_Exit "IGCM_sys_build_run_file"
1111    elif [ $1 = MPI1 ]; then
1112      cat <<EOF > run_file
1113./oasis
1114EOF
1115
1116      typeset i
1117      (( i = 0 ))
1118      while [ ${i} -lt ${NUM_PROC_ATM} ] ; do
1119        (( i = i + 1 ))
1120        cat <<EOF >> run_file
1121./lmdz.x
1122EOF
1123      done
1124
1125        (( i = 0 ))
1126        while [ ${i} -lt ${NUM_PROC_OCE} ] ; do
1127          (( i = i + 1 ))
1128          cat <<EOF >> run_file
1129./opa.xx
1130EOF
1131        done
1132
1133      wc -l run_file
1134    fi
1135set +x
1136    IGCM_debug_PopStack "IGCM_sys_build_run_file"
1137}
1138
1139############################################################
1140# Check of space available on temporary filesytems
1141function IGCM_sys_check_quota {
1142    IGCM_debug_PushStack "IGCM_sys_check_quota"
1143    if ( $DEBUG_sys ) ; then
1144      echo "IGCM_sys_check_quota"
1145    fi
1146    IGCM_debug_PopStack "IGCM_sys_check_quota"
1147}
Note: See TracBrowser for help on using the repository browser.