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

Last change on this file since 809 was 809, checked in by sdipsl, 11 years ago

Activate IGCM_sys_Chmod from DRYRUN=3 and add BoundaryFiles? list in FileToBeDeleted list at each Period.
Whitespace cleanup (from emacs macro) on libIGCM_sys_iitm.ksh
see #105

File size: 32.9 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 |            |         |                           |
46# |          |  Chmod 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    \chmod $@
332    if [ $? -gt 0 ] ; then
333      echo "IGCM_sys_Chmod : erreur."
334      IGCM_debug_Exit "IGCM_sys_Chmod"
335    fi
336    IGCM_debug_PopStack "IGCM_sys_Chmod"
337}
338
339#D-#==================================================
340#D-function IGCM_sys_FileSize
341#D-* Purpose: Filesize
342#D-* Examples:
343#D-
344function IGCM_sys_FileSize {
345    IGCM_debug_PushStack "IGCM_sys_FileSize" $@
346
347    typeset sizeF
348    set +A sizeF -- $( ls -la ${1} )
349    if [ $? -gt 0 ] ; then
350      IGCM_debug_Exit "IGCM_sys_FileSize"
351    fi
352    eval ${2}=${sizeF[4]}
353
354    IGCM_debug_PopStack "IGCM_sys_FileSize"
355}
356
357#D-#==================================================
358#D-function IGCM_sys_TestDir
359#D-* Purpose: Test Directory that must exists
360#D-* Examples:
361#D-
362function IGCM_sys_TestDir {
363    IGCM_debug_PushStack "IGCM_sys_TestDir" $@
364    if ( $DEBUG_sys ) ; then
365      echo "IGCM_sys_TestDir :" $@
366    fi
367    typeset ExistFlag
368    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
369    IGCM_debug_PopStack "IGCM_sys_TestDir"
370
371    return ${ExistFlag}
372}
373
374#D-#==================================================
375#D-function IGCM_sys_TestDirArchive
376#D-* Purpose: Test Directory that must exists on Archive
377#D-* Examples:
378#D-
379function IGCM_sys_TestDirArchive {
380    IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
381    if ( $DEBUG_sys ) ; then
382      echo "IGCM_sys_TestDirArchive :" $@
383    fi
384    typeset ExistFlag
385    ExistFlag=$( IGCM_sys_RshArchive "[ -d $1 ] && echo 0 || echo 1" )
386    IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
387
388    return ${ExistFlag}
389}
390
391#D-#==================================================
392#D-function IGCM_sys_TestFileArchive
393#D-* Purpose: Test file that must NOT EXISTS on Archive
394#D-* Examples:
395#D-
396function IGCM_sys_TestFileArchive {
397    IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
398    typeset ExistFlag
399    ExistFlag=$( IGCM_sys_RshArchive "[ -f $1 ] && echo 0 || echo 1" )
400    IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
401
402    return ${ExistFlag}
403}
404
405#D-#==================================================
406#D-function IGCM_sys_CountFileArchive
407#D-* Purpose: Count files on Archive filesystem
408#D-* Examples:
409#D-
410function IGCM_sys_CountFileArchive {
411    IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
412    IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
413    if [ $? -gt 0 ] ; then
414      echo "IGCM_sys_CountFileArchive : erreur."
415    fi
416    IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
417}
418
419#D-#==================================================
420#D-function IGCM_sys_Tree
421#D-* Purpose: Tree directories with files on ${ARCHIVE}
422#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
423#D-
424function IGCM_sys_Tree {
425    IGCM_debug_PushStack "IGCM_sys_Tree" $@
426    if ( $DEBUG_sys ) ; then
427      echo "IGCM_sys_Tree :" $@
428    fi
429
430    \ls -r $@
431
432    IGCM_debug_PopStack "IGCM_sys_Tree"
433}
434
435#D-#==================================================
436#D-function IGCM_sys_Tar
437#D-* Purpose: master un-tar command
438#D-* Examples:
439#D-
440function IGCM_sys_Tar {
441    IGCM_debug_PushStack "IGCM_sys_Tar" $@
442    if ( $DEBUG_sys ) ; then
443      echo "IGCM_sys_Tar :" $@
444    fi
445    \tar cvf $@
446    if [ $? -gt 0 ] ; then
447      echo "IGCM_sys_Tar : erreur."
448      IGCM_debug_Exit "IGCM_sys_Tar"
449    fi
450    \tar tvf $1
451
452    IGCM_debug_PopStack "IGCM_sys_Tar"
453}
454
455#D-#==================================================
456#D-function IGCM_sys_UnTar
457#D-* Purpose: master un-tar command
458#D-* Examples:
459#D-
460function IGCM_sys_UnTar {
461    IGCM_debug_PushStack "IGCM_sys_UnTar" $@
462    if ( $DEBUG_sys ) ; then
463      echo "IGCM_sys_UnTar :" $@
464    fi
465    \tar xvf $1
466    if [ $? -gt 0 ] ; then
467      echo "IGCM_sys_UnTar : erreur."
468      IGCM_debug_Exit "IGCM_sys_UnTar"
469    fi
470    IGCM_debug_PopStack "IGCM_sys_UnTar"
471}
472
473#D-#==================================================
474#D-function IGCM_sys_Qsub
475#D-* Purpose: Qsub new job
476#D-* Examples:
477#D-
478function IGCM_sys_Qsub {
479    IGCM_debug_PushStack "IGCM_sys_Qsub" $@
480    if ( $DEBUG_sys ) ; then
481      echo "IGCM_sys_Qsub :" $@
482    fi
483    {
484      [ ${#@} = 1 ] &&  { cd $LOADL_STEP_INITDIR ; /usr/lpp/LoadL/full/bin/llsubmit $1 ; ERROR=$? ; cd - ; }
485      [ ${#@} = 2 ] &&  { cd $2 ; /usr/lpp/LoadL/full/bin/llsubmit $1 ; ERROR=$? ; cd - ; }
486    }
487    if [ ${ERROR} -gt 0 ] ; then
488      echo "IGCM_sys_Qsub : erreur $@."
489      IGCM_debug_Exit "IGCM_sys_Qsub"
490    fi
491    IGCM_debug_PopStack "IGCM_sys_Qsub"
492}
493
494#D-#==================================================
495#D-function IGCM_sys_QsubPost
496#D-* Purpose: Qsub new job on scalaire
497#D-* Examples:
498#D-
499function IGCM_sys_QsubPost {
500    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
501    if ( $DEBUG_sys ) ; then
502      echo "IGCM_sys_QsubPost :" $@
503    fi
504    cd ${POST_DIR}
505    /usr/lpp/LoadL/full/bin/llsubmit ${libIGCM_POST}/$1.job
506    cd -
507    if [ $? -gt 0 ] ; then
508      echo "IGCM_sys_QsubPost : erreur " $@
509      IGCM_debug_Exit "IGCM_sys_QsubPost"
510    fi
511    IGCM_debug_PopStack "IGCM_sys_QsubPost"
512}
513
514#D-*************************
515#D- File transfer functions
516#D-*************************
517#D-
518
519#D-#==================================================
520#D-function IGCM_sys_Rsync_out
521#D-* Purpose: treat return val of rsync
522#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
523#D-  Error values and explanations can depend on your system version.
524function IGCM_sys_Rsync_out {
525    RET=$1
526    if [ ! $RET ] ; then
527      echo "rsync error !"
528    fi
529
530    if [ $MYLANG = "fr" ]; then
531      case $RET in
532          0)  return ;;
533          1)  echo "Erreur de rsync ; RERR_SYNTAX : "
534            echo "Erreur de syntaxe ou d'utilisation."
535            return;;
536          2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
537            echo "Incompatibilité de protocole."
538            return;;
539          3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
540            echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
541            echo "répertoires"
542            return;;
543          4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
544            echo "Action demandée non supportée : une tentative de manipulation de"
545            echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
546            echo "été faite ; ou une option qui est supportée par le  client  mais"
547            echo "pas par le serveur a été spécifiée."
548            return;;
549          10) echo "Erreur de rsync ; RERR_SOCKETIO"
550            echo "Erreur dans le socket d'entrée sortie"
551            return;;
552          11) echo "Erreur de rsync ; RERR_FILEIO"
553            echo "Erreur d'entrée sortie fichier"
554            return;;
555          12) echo "Erreur de rsync ; RERR_STREAMIO"
556            echo "Erreur dans flux de donnée du protocole rsync"
557            return;;
558          13) echo "Erreur de rsync ; RERR_MESSAGEIO"
559            echo "Erreur avec les diagnostics du programme"
560            return;;
561          14) echo "Erreur de rsync ; RERR_IPC"
562            echo "Erreur dans le code IPC"
563            return;;
564          20) echo "Erreur de rsync ; RERR_SIGNAL"
565            echo "SIGUSR1 ou SIGINT reçu"
566            return;;
567          21) echo "Erreur de rsync ; RERR_WAITCHILD"
568            echo "Une erreur retournée par waitpid()"
569            return;;
570          22) echo "Erreur de rsync ; RERR_MALLOC"
571            echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
572            return;;
573          23) echo ""
574                echo "Erreur fichier inexistant"
575            return;;
576          30) echo "Erreur de rsync ; RERR_TIMEOUT"
577            echo "Temps d'attente écoulé dans l'envoi/réception de données"
578            return;;
579          *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
580            return;;
581      esac
582    elif [ $MYLANG = "en" ] ; then
583      case $RET in
584          0)  return;;
585          1)  echo "rsync error : Syntax or usage error "
586            return;;
587          2)  echo "rsync error : Protocol incompatibility "
588            return;;
589          3)  echo "rsync error : Errors selecting input/output files, dirs"
590            return;;
591          4)  echo "rsync error : Requested action not supported: an attempt"
592            echo "was made to manipulate 64-bit files on a platform that cannot support"
593            echo "them; or an option was specified that is supported by the client and"
594            echo "not by the server."
595            return;;
596          5)  echo "rsync error : Error starting client-server protocol"
597            return;;
598          10) echo "rsync error : Error in socket I/O "
599            return;;
600          11) echo "rsync error : Error in file I/O "
601            return;;
602          12) echo "rsync error : Error in rsync protocol data stream "
603            return;;
604          13) echo "rsync error : Errors with program diagnostics "
605            return;;
606          14) echo "rsync error : Error in IPC code "
607            return;;
608          20) echo "rsync error : Received SIGUSR1 or SIGINT "
609            return;;
610          21) echo "rsync error : Some error returned by waitpid() "
611            return;;
612          22) echo "rsync error : Error allocating core memory buffers "
613            return;;
614          23) echo "rsync error : Partial transfer due to error"
615            return;;
616          24) echo "rsync error : Partial transfer due to vanished source files"
617            return;;
618          30) echo "rsync error : Timeout in data send/receive "
619            return;;
620          *)  echo "rsync error : return code of rsync unknown :" $RET
621            return;;
622      esac
623    else
624      echo "unknown language $MYLANG."
625      return
626    fi
627}
628
629#D-#==================================================
630#D-function IGCM_sys_Cp
631#D-* Purpose: generic cp
632#D-* Examples:
633#D-
634function IGCM_sys_Cp {
635    IGCM_debug_PushStack "IGCM_sys_Cp" $@
636    if ( $DEBUG_sys ) ; then
637      echo "IGCM_sys_Cp :" $@
638    fi
639
640    typeset RET
641
642    echo cp $@ > out_rsync 2>&1
643    \cp $@ >> out_rsync 2>&1
644    RET=$?
645
646    if [ ${RET} -gt 0 ] ; then
647      echo "IGCM_sys_Cp : error."
648      cat out_rsync
649      IGCM_debug_Exit "IGCM_sys_Cp"
650    fi
651    IGCM_debug_PopStack "IGCM_sys_Cp"
652}
653
654#D-#==================================================
655#D-function IGCM_sys_Rm
656#D-* Purpose: generic rm
657#D-* Examples:
658#D-
659function IGCM_sys_Rm {
660    IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
661    if ( $DEBUG_sys ) ; then
662      echo "IGCM_sys_Rm :" $@
663    fi
664
665    typeset RET
666
667    echo rm $@ > out_rsync 2>&1
668    \rm $@ >> out_rsync 2>&1
669    RET=$?
670
671    if [ ${RET} -gt 0 ] ; then
672      echo "IGCM_sys_Rm : error."
673      cat out_rsync
674      IGCM_debug_Exit "IGCM_sys_Rm"
675    fi
676    IGCM_debug_PopStack "IGCM_sys_Rm"
677}
678
679#D-#==================================================
680#D-function IGCM_sys_RmRunDir
681#D-* Purpose: rm tmpdir (dummy function most of the time batch
682#D-                      scheduler will do the job)
683#D-* Examples:
684#D-
685function IGCM_sys_RmRunDir {
686    IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
687    if ( $DEBUG_sys ) ; then
688      echo "IGCM_sys_RmRunDir :" $@
689    fi
690
691    typeset RET
692
693    echo rm $@ > out_rsync 2>&1
694    \rm $@ >> out_rsync 2>&1
695    RET=$?
696
697    if [ ${RET} -gt 0 ] ; then
698      echo "IGCM_sys_RmRunDir : error."
699      cat out_rsync
700      IGCM_debug_Exit "IGCM_sys_RmRunDir"
701    else
702      \rm out_rsync
703    fi
704
705    IGCM_debug_PopStack "IGCM_sys_RmRunDir"
706}
707
708#D-#==================================================
709#D-function IGCM_sys_Mv
710#D-* Purpose: generic move
711#D-* Examples:
712#D-
713function IGCM_sys_Mv {
714    IGCM_debug_PushStack "IGCM_sys_Mv" $@
715    if ( $DEBUG_sys ) ; then
716      echo "IGCM_sys_Mv :" $@
717    fi
718
719    if [ $DRYRUN = 0 ]; then
720
721        typeset RET
722
723        echo mv $@ > out_rsync 2>&1
724        \mv $@ >> out_rsync 2>&1
725        RET=$?
726
727        if [ ${RET} -gt 0 ] ; then
728            echo "IGCM_sys_Mv : error in mv."
729            cat out_rsync
730            IGCM_debug_Exit "IGCM_sys_Mv"
731        fi
732    else
733        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
734    fi
735
736    IGCM_debug_PopStack "IGCM_sys_Mv"
737}
738
739#D-#==================================================
740#D-function IGCM_sys_Put_Dir
741#D-* Purpose: Copy a complete directory on $(ARCHIVE)
742#D-* Examples:
743#D-
744function IGCM_sys_Put_Dir {
745    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
746    if ( $DEBUG_sys ) ; then
747      echo "IGCM_sys_Put_Dir :" $@
748    fi
749    if [ $DRYRUN = 0 ]; then
750      if [ ! -d ${1} ] ; then
751          echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
752          IGCM_debug_PopStack "IGCM_sys_Put_Dir"
753          return
754      fi
755
756      typeset RET
757
758      # Only if we use rsync
759      #IGCM_sys_TestDirArchive $( dirname $2 )
760      #
761      #USUAL WAY
762      \cp -r $1 $2 > out_rsync 2>&1
763      RET=$?
764
765      if [ ${RET} -gt 0 ] ; then
766          echo "IGCM_sys_Put_Dir : error."
767          cat out_rsync
768          IGCM_debug_Exit "IGCM_sys_Put_Dir"
769      fi
770    else
771      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
772    fi
773    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
774}
775
776#D-#==================================================
777#D-function IGCM_sys_Get_Dir
778#D-* Purpose: Copy a complete directory from $(ARCHIVE)
779#D-* Examples:
780#D-
781function IGCM_sys_Get_Dir {
782    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
783    if ( $DEBUG_sys ) ; then
784      echo "IGCM_sys_Get_Dir :" $@
785    fi
786    if [ $DRYRUN = 0 ]; then
787      if [ ! -d ${1} ] ; then
788          echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
789          IGCM_debug_PopStack "IGCM_sys_Get_Dir"
790          return
791      fi
792
793      typeset RET
794
795      #USUAL WAY
796      \cp -rp $1 $2 > out_rsync 2>&1
797      RET=$?
798
799      if [ ${RET} -gt 0 ] ; then
800          echo "IGCM_sys_Get_Dir : error."
801          cat out_rsync
802          IGCM_debug_Exit "IGCM_sys_Get_Dir"
803      fi
804    else
805      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
806    fi
807    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
808}
809
810#D-#==================================================
811#D-function IGCM_sys_Get_Master
812#D-* Purpose: Copy a complete directory from MASTER filesystem
813#D-* Examples:
814#D-
815function IGCM_sys_Get_Master {
816    IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
817    if ( $DEBUG_sys ) ; then
818      echo "IGCM_sys_Get_Master :" $@
819    fi
820    if [ $DRYRUN = 0 ]; then
821        if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
822            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
823            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
824            return
825        fi
826
827        typeset RET
828
829        #USUAL WAY
830        \cp -rp $1 $2 > out_rsync 2>&1
831        RET=$?
832
833        if [ ${RET} -gt 0 ] ; then
834            echo "IGCM_sys_Get_Dir : error."
835            cat out_rsync
836            IGCM_debug_Exit "IGCM_sys_Get_Dir"
837        fi
838    else
839      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
840    fi
841    IGCM_debug_PopStack "IGCM_sys_Get_Master"
842}
843
844#D-#==================================================
845#D-function IGCM_sys_Put_Rest
846#D-* Purpose: Put computied restarts on $(ARCHIVE).
847#D-           File and target directory must exist.
848#D-* Examples:
849#D-
850function IGCM_sys_Put_Rest {
851    IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
852    if ( $DEBUG_sys ) ; then
853      echo "IGCM_sys_Put_Rest :" $@
854    fi
855    if [ $DRYRUN = 0 ]; then
856      if [ ! -f ${1} ] ; then
857          echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
858          IGCM_debug_Exit "IGCM_sys_Put_Rest"
859      fi
860
861      typeset RET
862      #
863      if [ X${JobType} = XRUN ] ; then
864          IGCM_sys_Chmod 444 ${1}
865      fi
866      #
867      # Only if we use rsync
868      #IGCM_sys_MkdirArchive $( dirname $2 )
869      #
870      #USUAL WAY
871      \cp $1 $2 > out_rsync 2>&1
872      RET=$?
873
874      if [ ${RET} -gt 0 ] ; then
875          echo "IGCM_sys_Put_Rest : error."
876          cat out_rsync
877          IGCM_debug_Exit "IGCM_sys_Put_Rest"
878      fi
879    else
880      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
881    fi
882    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
883}
884
885#D-#==================================================
886#D-function IGCM_sys_PrepareTaredRestart
887#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
888#D-* Examples:
889#D-
890function IGCM_sys_PrepareTaredRestart {
891  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
892  echo $1
893  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
894}
895
896#D-#==================================================
897#D-function IGCM_sys_Put_Out
898#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
899#D-* Examples:
900#D-
901function IGCM_sys_Put_Out {
902    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
903    if ( $DEBUG_sys ) ; then
904      echo "IGCM_sys_Put_Out :" $@
905    fi
906    if [ $DRYRUN = 0 ]; then
907      if [ ! -f ${1} ] ; then
908          echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
909          IGCM_debug_PopStack "IGCM_sys_Put_Out"
910          return 1
911      fi
912      #
913      IGCM_sys_MkdirArchive $( dirname $2 )
914      #
915      typeset RET
916      #
917      if [ X${JobType} = XRUN ] ; then
918          if [ X${3} = X ] ; then
919            IGCM_sys_Chmod 444 ${1}
920          fi
921      fi
922      #
923      #USUAL WAY
924      \cp $1 $2 > out_rsync 2>&1
925      RET=$?
926
927      if [ ${RET} -gt 0 ] ; then
928          echo "IGCM_sys_Put_Out : error."
929          cat out_rsync
930          IGCM_debug_Exit "IGCM_sys_Put_Out"
931      fi
932    else
933      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
934    fi
935    IGCM_debug_PopStack "IGCM_sys_Put_Out"
936    return 0
937}
938
939#D-#==================================================
940#D-function IGCM_sys_Get
941#D-* Purpose: Get a file from ${ARCHIVE}
942#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
943#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
944function IGCM_sys_Get {
945    IGCM_debug_PushStack "IGCM_sys_Get" $@
946
947    typeset DEST RET dm_liste ifile target
948
949    if ( $DEBUG_sys ) ; then
950      echo "IGCM_sys_Get :" $@
951    fi
952    if [ $DRYRUN -le 2 ]; then
953      if [ X${1} = X'/l' ] ; then
954            # test if the first file is present in the old computation :
955          eval set +A dm_liste \${${2}}
956      else
957          dm_liste=${1}
958      fi
959      eval DEST=\${${#}}
960
961        # test if the (first) file is present in the old computation :
962      IGCM_sys_TestFileArchive ${dm_liste[0]}
963      RET=$?
964        if [ ${RET} -gt 0 ] ; then
965          echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
966          IGCM_debug_Exit "IGCM_sys_Get"
967          return
968        fi
969
970      # SD : dm_liste is not suited for computing job
971      #      because we change filename during transfert
972      #      dm_liste is better suited for post-treatment
973      #dm_liste=" "
974      #(( ifile=1 ))
975      #while [ $ifile -lt $# ] ; do
976      #    dm_liste=$( eval echo ${dm_liste} " "\${${ifile}} )
977      #    (( ifile = ifile + 1 ))
978      #done
979      #DEST=$( eval echo \${${#}} )
980
981      #USUAL WAY
982      \cp ${dm_liste[*]} ${DEST} > out_rsync 2>&1
983      RET=$?
984
985      if [ ${RET} -gt 0 ] ; then
986          echo "IGCM_sys_Get : copy error."
987          cat out_rsync
988          IGCM_debug_Exit "IGCM_sys_Get"
989      fi
990    else
991      ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
992    fi
993    IGCM_debug_PopStack "IGCM_sys_Get"
994}
995
996############################################################## A FINIR !!
997
998#D-#==================================================
999#D-function IGCM_sys_GetDate_FichWork
1000#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1001#D-* Examples:
1002#D-
1003function IGCM_sys_GetDate_FichWork {
1004    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1005    if ( $DEBUG_sys ) ; then
1006      echo "IGCM_sys_GetDate_FichWork :" $@
1007    fi
1008    # donne la date filesys d'un fichier sur la machine work
1009    IGCM_debug_PopStack "IGCM_sys_FichWork"
1010}
1011
1012#D-#==================================================
1013#D-function IGCM_sys_GetDate_FichArchive
1014#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1015#D-* Examples:
1016#D-
1017function IGCM_sys_GetDate_FichArchive {
1018    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1019    if ( $DEBUG_sys ) ; then
1020      echo "IGCM_sys_GetDate_FichArchive :" $@
1021    fi
1022    IGCM_debug_PopStack "IGCM_sys_FichArchive"
1023}
1024
1025##############################################################
1026# REBUILD OPERATOR
1027
1028function IGCM_sys_rebuild {
1029    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1030    if ( $DEBUG_sys ) ; then
1031      echo "IGCM_sys_rebuild :" $@
1032    fi
1033    /gpfs1/home/sebastien/REBUILD/rebuild -f -o $@
1034    if [ $? -gt 0 ] ; then
1035       echo "IGCM_sys_rebuild : erreur ${@}."
1036       IGCM_debug_Exit "rebuild"
1037    fi
1038
1039    IGCM_debug_PopStack "IGCM_sys_rebuild"
1040}
1041
1042############################################################
1043# Activate Running Environnment Variables
1044
1045function IGCM_sys_activ_variables {
1046    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1047    if ( $DEBUG_sys ) ; then
1048      echo "IGCM_sys_activ_variables "
1049    fi
1050
1051# --------------------------------------------------------------------
1052#D- MPI specifications
1053# --------------------------------------------------------------------
1054
1055# --------------------------------------------------------------------
1056#D- Other specifications
1057# --------------------------------------------------------------------
1058
1059    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1060
1061}
1062
1063############################################################
1064# Desactivate Running Environnment Variables
1065
1066function IGCM_sys_desactiv_variables {
1067    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1068    if ( $DEBUG_sys ) ; then
1069      echo "IGCM_sys_desactiv_variables "
1070    fi
1071# --------------------------------------------------------------------
1072#D- MPI specifications
1073# --------------------------------------------------------------------
1074
1075# --------------------------------------------------------------------
1076#D- Other specifications
1077# --------------------------------------------------------------------
1078
1079    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1080
1081}
1082
1083############################################################
1084# Build run file
1085
1086function IGCM_sys_build_run_file {
1087    IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1088set -x
1089    if ( $DEBUG_sys ) ; then
1090      echo "IGCM_sys_build_run_file " $@
1091    fi
1092
1093    NUM_PROC_OASIS=1
1094
1095    # Set the number of processors for OCE here
1096    NUM_PROC_OCE=5
1097
1098    (( NUM_PROC_ATM = BATCH_NUM_PROC_TOT - NUM_PROC_OASIS - NUM_PROC_OCE ))
1099
1100    if [ $1 = MPI2 ]; then
1101       echo "IGCM_sys_build_run_file : error - MPI2 not available on iitm. "
1102       IGCM_debug_Exit "IGCM_sys_build_run_file"
1103    elif [ $1 = MPI1 ]; then
1104      cat <<EOF > run_file
1105./oasis
1106EOF
1107
1108      typeset i
1109      (( i = 0 ))
1110      while [ ${i} -lt ${NUM_PROC_ATM} ] ; do
1111        (( i = i + 1 ))
1112        cat <<EOF >> run_file
1113./lmdz.x
1114EOF
1115      done
1116
1117        (( i = 0 ))
1118        while [ ${i} -lt ${NUM_PROC_OCE} ] ; do
1119          (( i = i + 1 ))
1120          cat <<EOF >> run_file
1121./opa.xx
1122EOF
1123        done
1124
1125      wc -l run_file
1126    fi
1127set +x
1128    IGCM_debug_PopStack "IGCM_sys_build_run_file"
1129}
1130
1131############################################################
1132# Check of space available on temporary filesytems
1133function IGCM_sys_check_quota {
1134    IGCM_debug_PushStack "IGCM_sys_check_quota"
1135    if ( $DEBUG_sys ) ; then
1136      echo "IGCM_sys_check_quota"
1137    fi
1138    IGCM_debug_PopStack "IGCM_sys_check_quota"
1139}
Note: See TracBrowser for help on using the repository browser.