source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_iitm.ksh @ 804

Last change on this file since 804 was 804, checked in by sdipsl, 11 years ago
  • Files waiting for rebuild are stored within the relevant simulation tree. see #87

--> /IGCM_OUT/TagName/SpaceName/ExperiementName/JobName/REBUILD

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